# HG changeset patch # User unc0rr # Date 1154811456 0 # Node ID 1ef5e2c41115c65a3c4756912906a10d8480d8e1 # Parent c6eec0bdb630336b4828c2608fac40ab10665f8a - Fixed compilation - Rewritten attack code - Many small changes diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/CCHandlers.inc Sat Aug 05 20:57:36 2006 +0000 @@ -219,8 +219,6 @@ if ((State and gstHHDriven)<>0)and((State and (gstAttacked or gstHHChooseTarget or gstMoving)) = 0) then begin FollowGear:= CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear; - if (State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then - State:= State or gstAttacking; if not CurrentTeam.ExtDriven then SendIPC('A'); Message:= Message or gm_Attack end @@ -230,11 +228,11 @@ procedure chAttack_m(var s: shortstring); begin if CheckNoTeamOrHH then exit; -with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^, - CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do +with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do begin - Message:= Message and not gm_Attack; - if not CurrentTeam.ExtDriven then SendIPC('a') + if not CurrentTeam.ExtDriven and + ((Message and gm_Attack) <> 0) then SendIPC('a'); + Message:= Message and not gm_Attack end end; @@ -279,7 +277,7 @@ var slot: LongWord; caSlot, caAmmo: PLongword; begin -if (s[0] <> #1) or (CurrentTeam = nil) then exit; +if (s[0] <> #1) or CheckNoTeamOrHH then exit; slot:= byte(s[1]) - 49; if slot > cMaxSlotIndex then exit; if not CurrentTeam.ExtDriven then SendIPC(char(byte(s[1]) + 79)); @@ -321,12 +319,12 @@ dec(TargetPoint.Y, WorldDy); s[0]:= #9; s[1]:= 'p'; - PInteger(@s[2])^:= TargetPoint.X; - PInteger(@s[6])^:= TargetPoint.Y; + PSmallInt(@s[2])^:= TargetPoint.X; + PSmallInt(@s[4])^:= TargetPoint.Y; SendIPC(s) end; State:= State and not gstHHChooseTarget; - end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', true) + end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', false) end; procedure chCapture(var s: shortstring); diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/CMakeLists.txt Sat Aug 05 20:57:36 2006 +0000 @@ -18,7 +18,7 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+" dcc32version "${dcc32_output}") if (dcc32version) set(pascal_compiler ${dcc32_executable}) - set(pascal_compiler_flags "-B -W"${hwengine_project}) + set(pascal_compiler_flags "-B -W "${hwengine_project}) else (dcc32version) string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" ppc386_version "${ppc386_output}") if (ppc386_version) @@ -30,7 +30,7 @@ message("Minimum required version of FreePascal is 1.9.2") else (ppc386_ver LESS "010902") set(pascal_compiler ${ppc386_executable}) - set(pascal_compiler_flags "-B -Sd -Xs -OG -O3 -Cs2000000"${hwengine_project}) + set(pascal_compiler_flags "-B -Sd -Xs -OG -O3 -Cs2000000 "${hwengine_project}) endif (ppc386_ver LESS "010902") endif (ppc386_version) endif (dcc32version) @@ -39,6 +39,6 @@ message(FATAL_ERROR "No Pascal compiler found!") endif (NOT pascal_compiler) -add_custom_command(COMMAND ${pascal_compiler} TARGET hwengine OUTPUTS hwengine ARGS ${pascal_compiler_flags}) +add_custom_target(hwengine ALL COMMAND "${pascal_compiler}" ${pascal_compiler_flags}) install(PROGRAMS "hwengine${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION bin) diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/GSHandlers.inc Sat Aug 05 20:57:36 2006 +0000 @@ -179,7 +179,7 @@ end; //////////////////////////////////////////////////////////////////////////////// -procedure doStepHealthTag(Gear: PGear); +procedure doStepHealthTagWork(Gear: PGear); begin AllInactive:= false; dec(Gear.Timer); @@ -191,6 +191,15 @@ end end; +procedure doStepHealthTag(Gear: PGear); +var s: shortstring; +begin +AllInactive:= false; +str(Gear.State, s); +Gear.Surf:= RenderString(s, PHedgehog(Gear.Hedgehog).Team.Color, fnt16); +Gear.doStep:= doStepHealthTagWork +end; + //////////////////////////////////////////////////////////////////////////////// procedure doStepGrave(Gear: PGear); begin @@ -264,7 +273,7 @@ if Gear.Timer > 0 then begin dec(Gear.Timer); - if Gear.Timer = 1 then PlaySound(sndShotgunFire); + if Gear.Timer = 0 then PlaySound(sndShotgunFire); exit end; i:= 200; @@ -283,7 +292,10 @@ dec(i) until i = 0; if (Gear.X < 0) or (Gear.Y < 0) or (Gear.X > 2048) or (Gear.Y > 1024) then - DeleteGear(Gear) + begin + DeleteGear(Gear); + AfterAttack + end end; //////////////////////////////////////////////////////////////////////////////// diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/HHHandlers.inc --- a/hedgewars/HHHandlers.inc Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/HHHandlers.inc Sat Aug 05 20:57:36 2006 +0000 @@ -36,15 +36,28 @@ var xx, yy: real; begin with Gear^, - CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do + PHedgehog(Gear.Hedgehog)^ do begin - {$IFDEF DEBUGFILE}AddFileLog('Attack: Gear.State = '+inttostr(State));{$ENDIF} - - if (((State and (gstHHDriven or gstAttacking)) = (gstHHDriven or gstAttacking))and + if ((State and gstHHDriven) <> 0)and + // (((State and gstAttacking) <> 0) or ((Message and gm_Attack) <> 0))and ((State and (gstAttacked or gstMoving or gstHHChooseTarget)) = 0)and (((State and gstFalling ) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInFall) <> 0))and - (((State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0))) then + (((State and gstHHJumping) = 0)or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_AttackInJump) <> 0))and + ((TargetPoint.X <> NoPointX) or((Ammo[CurSlot, CurAmmo].Propz and ammoprop_NeedTarget) = 0)) then begin + State:= State or gstAttacking; + if Power = cMaxPower then Message:= Message and not gm_Attack + else if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then Message:= Message and not gm_Attack + else begin + if Power = 0 then + begin + AttackBar:= CurrentTeam.AttackBar; + PlaySound(sndThrowPowerUp) + end; + inc(Power) + end; + if ((Message and gm_Attack) <> 0) then exit; + if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0 then begin StopTPUSound; @@ -76,10 +89,11 @@ Message:= Message or gm_Attack; CurAmmoGear.Message:= Message end else begin - if not CurrentTeam.ExtDriven then SendIPC('a'); + if not CurrentTeam.ExtDriven and + ((Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) <> 0) then SendIPC('a'); AfterAttack end - end + end else Message:= Message and not gm_Attack end end; @@ -96,7 +110,7 @@ State:= State or gstAttacked; OnUsedAmmo(Ammo) end; - AttackBar:= 0 + AttackBar:= 0; end end; @@ -151,31 +165,8 @@ exit end; -if (Gear.Message and gm_Attack)<>0 then - if (Gear.State and (gstAttacked or gstHHChooseTarget) = 0) then - with PHedgehog(Gear.Hedgehog)^ do - begin - Gear.State:= Gear.State or gstAttacking; - if Gear.Power = cMaxPower then Gear.Message:= Gear.Message and not gm_Attack - else - if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Power) = 0 then - Gear.Message:= Gear.Message and not gm_Attack - else begin - if Gear.Power = 0 then - begin - AttackBar:= CurrentTeam.AttackBar; - PlaySound(sndThrowPowerUp) - end; - inc(Gear.Power) - end - end - else Gear.Message:= Gear.Message and not gm_Attack; - -if ((Gear.State and gstAttacking) <> 0) and ((Gear.Message and gm_Attack) = 0) then - begin - Attack(Gear); - StepTicks:= cHHStepTicks - end; +if ((Gear.Message and gm_Attack) <> 0) or + ((Gear.State and gstAttacking) <> 0)then Attack(Gear); if (Gear.State and gstFalling) <> 0 then begin diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/SDLh.pas --- a/hedgewars/SDLh.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/SDLh.pas Sat Aug 05 20:57:36 2006 +0000 @@ -197,6 +197,7 @@ TByteArray = array[0..32767] of Byte; PSDL_Thread = Pointer; + PSDL_mutex = Pointer; function SDL_Init(flags: Longword): Integer; cdecl; external SDLLibName; procedure SDL_Quit; cdecl; external SDLLibName; @@ -243,6 +244,10 @@ function SDL_CreateThread(fn: pointer; data: pointer): PSDL_Thread; cdecl; external SDLLibName; procedure SDL_WaitThread(thread: PSDL_Thread; status: PInteger); cdecl; external SDLLibName; +function SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName; +procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName; +function SDL_LockMutex(mutex: PSDL_mutex): integer; cdecl; external SDLLibName name 'SDL_mutexP'; +function SDL_UnlockMutex(mutex: PSDL_mutex): integer; cdecl; external SDLLibName name 'SDL_mutexV'; (* TTF *) diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uAI.pas --- a/hedgewars/uAI.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uAI.pas Sat Aug 05 20:57:36 2006 +0000 @@ -284,7 +284,7 @@ with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do if (Gear <> nil) and ((Gear.State and gstHHDriven) <> 0) - and (TurnTimeLeft < 29990) + and (TurnTimeLeft < cHedgehogTurnTime - 5) and ((Gear.State and gstHHThinking) = 0) then if (BestActions.Pos >= BestActions.Count) then StartThink(Gear) else ProcessAction(BestActions, Gear) diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uAIMisc.pas --- a/hedgewars/uAIMisc.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uAIMisc.pas Sat Aug 05 20:57:36 2006 +0000 @@ -124,6 +124,7 @@ begin bonuses.Count:= 0; MyColor:= PHedgehog(ThinkingHH.Hedgehog).Team.Color; +SDL_LockMutex(GearsListMutex); Gear:= GearsList; while Gear <> nil do begin @@ -141,6 +142,7 @@ end; Gear:= Gear.NextGear end; +SDL_UnlockMutex(GearsListMutex); if isAfterAttack and (KnownExplosion.Radius > 0) then with KnownExplosion do AddBonus(X, Y, Radius + 10, -Radius); diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uConsts.pas Sat Aug 05 20:57:36 2006 +0000 @@ -119,8 +119,6 @@ cKeyMaxIndex = 322; - cMaxCaptions = 4; - cInactDelay = 1500; gfForts = $00000001; @@ -307,7 +305,7 @@ Slot: 0; TimeAfterTurn: 3000), (NameId: sidShotgun; - Ammo: (Propz: 0; + Ammo: (Propz: ammoprop_ForwMsgs; Count: AMMO_INFINITE; NumPerTurn: 1; Timer: 0; diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uGears.pas --- a/hedgewars/uGears.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uGears.pas Sat Aug 05 20:57:36 2006 +0000 @@ -61,6 +61,7 @@ Health, Damage: integer; CollIndex: Longword; Tag: integer; + Surf: PSDL_Surface; end; function AddGear(X, Y: integer; Kind: TGearType; State: Cardinal; const dX: real=0.0; dY: real=0.0; Timer: LongWord=0): PGear; @@ -74,6 +75,7 @@ var CurAmmoGear: PGear = nil; GearsList: PGear = nil; + GearsListMutex: PSDL_mutex; implementation uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions, @@ -235,18 +237,21 @@ Result.Tag:= Y end; end; +SDL_LockMutex(GearsListMutex); if GearsList = nil then GearsList:= Result else begin GearsList.PrevGear:= Result; Result.NextGear:= GearsList; GearsList:= Result - end + end; +SDL_UnlockMutex(GearsListMutex) end; procedure DeleteGear(Gear: PGear); var team: PTeam; begin if Gear.CollIndex < High(Longword) then DeleteCI(Gear); +if Gear.Surf <> nil then SDL_FreeSurface(Gear.Surf); if Gear.Kind = gtHedgehog then if CurAmmoGear <> nil then begin @@ -260,15 +265,17 @@ PHedgehog(Gear.Hedgehog).Gear:= nil; RecountTeamHealth(team); end; +{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} +SDL_LockMutex(GearsListMutex); if CurAmmoGear = Gear then CurAmmoGear:= nil; if FollowGear = Gear then FollowGear:= nil; -{$IFDEF DEBUGFILE}AddFileLog('DeleteGear: handle = '+inttostr(integer(Gear)));{$ENDIF} if Gear.NextGear <> nil then Gear.NextGear.PrevGear:= Gear.PrevGear; if Gear.PrevGear <> nil then Gear.PrevGear.NextGear:= Gear.NextGear else begin GearsList:= Gear^.NextGear; if GearsList <> nil then GearsList.PrevGear:= nil end; +SDL_UnlockMutex(GearsListMutex); Dispose(Gear) end; @@ -488,7 +495,7 @@ 0, PHedgehog(Gear.Hedgehog).visStepPos div 2, Surface); gtAmmo_Grenade: DrawSprite(sprGrenade , Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, DxDy2Angle32(Gear.dY, Gear.dX), Surface); - gtHealthTag: DrawCaption(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, PHedgehog(Gear.Hedgehog).HealthTagRect, Surface, true); + gtHealthTag: if Gear.Surf <> nil then DrawCentered(Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.Surf, Surface); gtGrave: DrawSpriteFromRect(PHedgehog(Gear.Hedgehog).Team.GraveRect, Round(Gear.X) + WorldDx - 16, Round(Gear.Y) + WorldDy - 16, 32, (GameTicks shr 7) and 7, Surface); gtUFO: DrawSprite(sprUFO, Round(Gear.X) - 16 + WorldDx, Round(Gear.Y) - 16 + WorldDy, (GameTicks shr 7) mod 4, Surface); gtSmokeTrace: if Gear.State < 8 then DrawSprite(sprSmokeTrace, Round(Gear.X) + WorldDx, Round(Gear.Y) + WorldDy, Gear.State, Surface); @@ -550,7 +557,7 @@ begin for i:= 0 to cCloudsNumber do AddGear( - cScreenWidth + i * ((cScreenWidth * 2 + 2304) div cCloudsNumber), -140, gtCloud, random(4), - (0.5-random)*0.02, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); + (0.5-random)*0.1, ((i mod 2) * 2 - 1) * (0.005 + 0.015*random)); AddGear(0, 0, gtATStartGame, 0, 0, 0, 2000); if (GameFlags and gfForts) = 0 then for i:= 0 to 3 do @@ -786,8 +793,10 @@ end; initialization +GearsListMutex:= SDL_CreateMutex; finalization -FreeGearsList +FreeGearsList; +SDL_DestroyMutex(GearsListMutex); end. diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uIO.pas Sat Aug 05 20:57:36 2006 +0000 @@ -56,7 +56,7 @@ case byte of 1: (len: byte; cmd: Char; - X, Y: integer;); + X, Y: SmallInt); 2: (str: shortstring); end; cmdcurpos: integer = 0; diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uMisc.pas --- a/hedgewars/uMisc.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uMisc.pas Sat Aug 05 20:57:36 2006 +0000 @@ -46,7 +46,7 @@ GameType : TGameType = gmtLocal; GameFlags : Longword = 0; TurnTimeLeft : Longword = 0; - cHedgehogTurnTime: Longword = 30000; + cHedgehogTurnTime: Longword = 45000; cCloudsNumber : integer = 9; cConsoleHeight : integer = 320; diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uStore.pas --- a/hedgewars/uStore.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uStore.pas Sat Aug 05 20:57:36 2006 +0000 @@ -45,11 +45,12 @@ procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: integer; Surface: PSDL_Surface); procedure DrawLand (X, Y: integer; Surface: PSDL_Surface); procedure DXOutText(X, Y: Integer; Font: THWFont; s: string; Surface: PSDL_Surface); -procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false); +procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); +procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); procedure DrawFromStoreRect(X, Y: integer; Rect: PSDL_Rect; Surface: PSDL_Surface); procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); +function RenderString(var s: shortstring; Color: integer; font: THWFont): PSDL_Surface; procedure RenderHealth(var Hedgehog: THedgehog); -function RenderString(var s: shortstring; Color, Pos: integer): PSDL_Surface; procedure AddProgress; function LoadImage(filename: string; hasAlpha: boolean; const critical: boolean = true): PSDL_Surface; @@ -60,7 +61,6 @@ uses uMisc, uIO, uConsole, uLand, uCollisions; var StoreSurface, - TempSurface, HHSurface: PSDL_Surface; procedure StoreInit; @@ -69,11 +69,7 @@ TryDo( StoreSurface <> nil, errmsgCreateSurface + ': store' , true); SDL_FillRect(StoreSurface, nil, 0); -TempSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 724, 900, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); -TryDo( TempSurface <> nil, errmsgCreateSurface + ': temp' , true); - TryDo(SDL_SetColorKey( StoreSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); -TryDo(SDL_SetColorKey( TempSurface, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true); end; procedure LoadToSurface(Filename: String; Surface: PSDL_Surface; X, Y: integer); @@ -155,10 +151,9 @@ while Team<>nil do begin r.w:= 104; - r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.TeamName); - Team.NameRect:= r; - inc(r.y, r.h); + Team.NameTag:= RenderString(Team.TeamName, Team.Color, Font); r.w:= cTeamHealthWidth + 5; + r.h:= Team.NameTag.h; DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface); Team.HealthRect:= r; rr:= r; @@ -168,12 +163,9 @@ dec(drY, r.h + 2); Team.DrawHealthY:= drY; for i:= 0 to 7 do - if Team.Hedgehogs[i].Gear<>nil then - begin - r:= WriteInRoundRect(StoreSurface, r.x, r.y, Team.Color, Font, Team.Hedgehogs[i].Name); - Team.Hedgehogs[i].NameRect:= r; - inc(r.y, r.h) - end; + with Team.Hedgehogs[i] do + if Gear <> nil then + NameTag:= RenderString(Name, Team.Color, fnt16); Team:= Team.Next end; end; @@ -209,19 +201,14 @@ procedure InitHealth; var p: PTeam; - i, t: integer; + i: integer; begin p:= TeamsList; - t:= 0; while p <> nil do begin for i:= 0 to cMaxHHIndex do if p.Hedgehogs[i].Gear <> nil then - begin - p.Hedgehogs[i].HealthRect.y:= t; RenderHealth(p.Hedgehogs[i]); - inc(t, p.Hedgehogs[i].HealthRect.h) - end; p:= p.Next end end; @@ -347,7 +334,6 @@ {$IFDEF DUMP} SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); -SDL_SaveBMP_RW(TempSurface, SDL_RWFromFile('TempSurface.bmp', 'wb'), 1); {$ENDIF} end; @@ -421,10 +407,19 @@ DrawFromRect(X, Y, Rect, StoreSurface, Surface) end; -procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface; const fromTempSurf: boolean = false); +procedure DrawCaption(X, Y: integer; Rect: TSDL_Rect; Surface: PSDL_Surface); begin -if fromTempSurf then DrawFromRect(X - (Rect.w) div 2, Y, @Rect, TempSurface, Surface) - else DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) +DrawFromRect(X - (Rect.w) div 2, Y, @Rect, StoreSurface, Surface) +end; + +procedure DrawCentered(X, Top: integer; Source, Surface: PSDL_Surface); +var r: TSDL_Rect; +begin +r.x:= X - Source.w div 2; +r.y:= Top; +r.w:= Source.w; +r.h:= Source.h; +SDL_UpperBlit(Source, nil, Surface, @r) end; procedure DrawHedgehog(X, Y: integer; Dir: integer; Pos, Step: LongWord; Surface: PSDL_Surface); @@ -444,30 +439,25 @@ for ii:= Low(TSprite) to High(TSprite) do SDL_FreeSurface(SpritesData[ii].Surface); SDL_FreeSurface( HHSurface ); -SDL_FreeSurface(TempSurface ); SDL_FreeSurface(LandSurface ); SDL_FreeSurface(StoreSurface ) end; +function RenderString(var s: shortstring; Color: integer; font: THWFont): PSDL_Surface; +var w, h: integer; +begin +TTF_SizeUTF8(Fontz[font].Handle, PChar(String(s)), w, h); +Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); +WriteInRoundRect(Result, 0, 0, Color, font, s); +TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) +end; + procedure RenderHealth(var Hedgehog: THedgehog); -var s: string[15]; +var s: shortstring; begin str(Hedgehog.Gear.Health, s); -Hedgehog.HealthRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s); -if Hedgehog.Gear.Damage > 0 then - begin - str(Hedgehog.Gear.Damage, s); - Hedgehog.HealthTagRect:= WriteInRoundRect(TempSurface, Hedgehog.HealthRect.x + Hedgehog.HealthRect.w, Hedgehog.HealthRect.y, Hedgehog.Team.Color, fnt16, s) - end; -end; - -function RenderString(var s: shortstring; Color, Pos: integer): PSDL_Surface; -var w, h: integer; -begin -TTF_SizeUTF8(Fontz[fntBig].Handle, PChar(String(s)), w, h); -Result:= SDL_CreateRGBSurface(SDL_HWSURFACE, w + 6, h + 2, cBits, PixelFormat.RMask, PixelFormat.GMask, PixelFormat.BMask, 0); -WriteInRoundRect(Result, 0, 0, Color, fntBig, s); -TryDo(SDL_SetColorKey(Result, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true) +if Hedgehog.HealthTag <> nil then SDL_FreeSurface(Hedgehog.HealthTag); +Hedgehog.HealthTag:= RenderString(s, Hedgehog.Team^.Color, fnt16) end; procedure AddProgress; diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uTeams.pas Sat Aug 05 20:57:36 2006 +0000 @@ -41,7 +41,7 @@ THedgehog = record Name: string[MAXNAMELEN]; Gear: PGear; - NameRect, HealthRect, HealthTagRect: TSDL_Rect; + NameTag, HealthTag: PSDL_Surface; Ammo: PHHAmmo; CurSlot, CurAmmo: LongWord; AltSlot, AltAmmo: LongWord; @@ -60,7 +60,8 @@ Hedgehogs: array[0..cMaxHHIndex] of THedgehog; Ammos: array[0..cMaxHHIndex] of THHAmmo; CurrHedgehog: integer; - NameRect, CrossHairRect, + NameTag: PSDL_Surface; + CrossHairRect, GraveRect, HealthRect: TSDL_Rect; GraveName: string; FortName: string; diff -r c6eec0bdb630 -r 1ef5e2c41115 hedgewars/uWorld.pas --- a/hedgewars/uWorld.pas Mon Jul 31 11:31:31 2006 +0000 +++ b/hedgewars/uWorld.pas Sat Aug 05 20:57:36 2006 +0000 @@ -60,12 +60,11 @@ type TCaptionStr = record Surf: PSDL_Surface; StorePos: Longword; - Group: TCapGroup; EndTime: LongWord; end; var cWaterSprCount: integer; - Captions: array[0..Pred(cMaxCaptions)] of TCaptionStr; + Captions: array[TCapGroup] of TCaptionStr; procedure InitWorld; begin @@ -132,23 +131,23 @@ DrawGears(Surface); -team:= TeamsList; -while team<>nil do +if CurrentTeam <> nil then + begin + team:= TeamsList; + while team<>nil do begin for i:= 0 to 7 do with team.Hedgehogs[i] do if Gear<>nil then if Gear.State = 0 then begin - DrawCaption( round(Gear.X) + WorldDx, - round(Gear.Y) - cHHRadius - 30 + WorldDy, - HealthRect, Surface, true); - DrawCaption( round(Gear.X) + WorldDx, - round(Gear.Y) - cHHRadius - 54 + WorldDy, - NameRect, Surface); -// DrawCaption( round(Gear.X) + WorldDx, -// round(Gear.Y) - Gear.Radius - 60 + WorldDy, -// Team.NameRect, Surface); + t:= round(Gear.Y) - cHHRadius - 10 + WorldDy; + dec(t, HealthTag.h + 2); + DrawCentered(round(Gear.X) + WorldDx, t, HealthTag, Surface); + dec(t, NameTag.h + 2); + DrawCentered(round(Gear.X) + WorldDx, t, NameTag, Surface); + dec(t, Team.NameTag.h + 2); + DrawCentered(round(Gear.X) + WorldDx, t, Team.NameTag, Surface) end else // Current hedgehog begin if (Gear.State and (gstMoving or gstDrowning or gstFalling)) = 0 then @@ -162,6 +161,8 @@ end; team:= team.Next end; + end; + // Waves {$WARNINGS OFF} @@ -217,18 +218,13 @@ begin with Captions[i] do if EndTime > 0 then - begin - r.x:= (cScreenWidth - Surf.w) div 2; - r.y:= 8 + i * (Surf.h + 2) + cConsoleYAdd; - r.w:= Surf.w; - r.h:= Surf.h; - SDL_UpperBlit(Surf, nil, Surface, @r) - end; + DrawCentered(cScreenWidth div 2, 8 + i * (Surf.h + 2) + cConsoleYAdd, Surf, Surface); inc(i) end; while (Captions[0].EndTime > 0) and (Captions[0].EndTime <= RealTicks) do begin SDL_FreeSurface(Captions[0].Surf); + Captions[0].Surf:= nil; for i:= 1 to Pred(cMaxCaptions) do Captions[Pred(i)]:= Captions[i]; Captions[Pred(cMaxCaptions)].EndTime:= 0 @@ -238,9 +234,11 @@ team:= TeamsList; while team <> nil do begin - DrawFromStoreRect(cScreenWidth div 2 - team.NameRect.w - 3, - Team.DrawHealthY, - @team.NameRect, Surface); + r.x:= cScreenWidth div 2 - team.NameTag.w - 3; + r.y:= team.DrawHealthY; + r.w:= team.NameTag.w; + r.h:= team.NameTag.h; + SDL_UpperBlit(team.NameTag, nil, Surface, @r); r:= team.HealthRect; r.w:= 2 + team.TeamHealth; DrawFromStoreRect(cScreenWidth div 2, @@ -312,6 +310,7 @@ while (i < cMaxCaptions) and (Captions[i].Group <> Group) do inc(i); if i < cMaxCaptions then begin + SDL_FreeSurface(Captions[i].Surf); while (i < Pred(cMaxCaptions)) do begin Captions[i]:= Captions[Succ(i)]; @@ -322,6 +321,7 @@ if Captions[Pred(cMaxCaptions)].EndTime > 0 then begin + SDL_FreeSurface(Captions[0].Surf); m:= Pred(cMaxCaptions); for i:= 1 to m do Captions[Pred(i)]:= Captions[i]; @@ -337,7 +337,7 @@ for t:= 0 to Pred(cMaxCaptions) do if (Captions[t].EndTime > 0) and (Captions[t].StorePos = k) then inc(k); -Captions[m].Surf:= RenderString(s, Color, k); +Captions[m].Surf:= RenderString(s, Color, fntBig); Captions[m].StorePos:= k; Captions[m].Group:= Group; Captions[m].EndTime:= RealTicks + 1200 @@ -367,8 +367,8 @@ begin s[0]:= #9; s[1]:= 'P'; - PInteger(@s[2])^:= CursorPoint.X - WorldDx; - PInteger(@s[6])^:= CursorPoint.Y - WorldDy; + PSmallInt(@s[2])^:= CursorPoint.X - WorldDx; + PSmallInt(@s[4])^:= CursorPoint.Y - WorldDy; SendIPC(s); PrevSentPointTime:= GameTicks end;