# HG changeset patch # User unc0rr # Date 1165339647 0 # Node ID 929c44745fd9e362985deeda95d9d1884df54e81 # Parent b0eef98928f82b42761e5333e33361583d380223 Ammo schemes and ammo stores support in engine diff -r b0eef98928f8 -r 929c44745fd9 hedgewars/CCHandlers.inc --- a/hedgewars/CCHandlers.inc Thu Nov 30 22:36:07 2006 +0000 +++ b/hedgewars/CCHandlers.inc Tue Dec 05 17:27:27 2006 +0000 @@ -117,11 +117,17 @@ Gear:= AddGear(0, 0, gtHedgehog, 0); Gear.Hedgehog:= @CurrentTeam.Hedgehogs[b]; PHedgehog(Gear.Hedgehog).Team:= CurrentTeam; + CurrentTeam.Hedgehogs[b].AmmoStore:= 0; CurrentTeam.Hedgehogs[b].Gear:= Gear end else OutError(errmsgUnknownVariable + ' "' + id + '"', true) end; +procedure chAddAmmoStore(var descr: shortstring); +begin +AddAmmoStore(descr) +end; + procedure chBind(var id: shortstring); var s: shortstring; b: integer; diff -r b0eef98928f8 -r 929c44745fd9 hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Thu Nov 30 22:36:07 2006 +0000 +++ b/hedgewars/CMakeLists.txt Tue Dec 05 17:27:27 2006 +0000 @@ -13,6 +13,7 @@ uAIAmmoTests.pas uAIMisc.pas uAIThinkStack.pas + uAmmos.pas uCollisions.pas uConsole.pas uConsts.pas diff -r b0eef98928f8 -r 929c44745fd9 hedgewars/hwengine.dpr --- a/hedgewars/hwengine.dpr Thu Nov 30 22:36:07 2006 +0000 +++ b/hedgewars/hwengine.dpr Tue Dec 05 17:27:27 2006 +0000 @@ -41,7 +41,8 @@ uLandTemplates in 'uLandTemplates.pas', uLandObjects in 'uLandObjects.pas', uLandGraphics in 'uLandGraphics.pas', - uLocale in 'uLocale.pas'; + uLocale in 'uLocale.pas', + uAmmos in 'uAmmos.pas'; {$INCLUDE options.inc} @@ -218,6 +219,8 @@ SendIPCRaw(@s[0], Length(s) + 1); // send proto version InitTeams; +ParseCommand('ammstore 1111111111111119'); +AssignStores; if isSoundEnabled then InitSound; InitWorld; diff -r b0eef98928f8 -r 929c44745fd9 hedgewars/uAmmos.pas --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/uAmmos.pas Tue Dec 05 17:27:27 2006 +0000 @@ -0,0 +1,65 @@ +unit uAmmos; +interface +uses uConsts; +{$INCLUDE options.inc} +type PHHAmmo = ^THHAmmo; + THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo; + +procedure AddAmmoStore(s: shortstring); +procedure AssignStores; + +implementation +uses uMisc, uTeams; +var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo; + StoreCnt: Longword = 0; + +procedure AddAmmoStore(s: shortstring); +var mi: array[0..cMaxSlotIndex] of byte; + a: TAmmoType; + cnt: Longword; + tmp: PHHAmmo; +begin +TryDo(byte(s[0]) = byte(ord(High(TAmmoType)) + 1), 'Invalid ammo scheme (incompatible frontend)', true); + +inc(StoreCnt); +TryDo(StoreCnt <= cMaxHHs, 'Ammo stores overflow', true); + +new(StoresList[Pred(StoreCnt)]); +tmp:= StoresList[Pred(StoreCnt)]; + +FillChar(mi, sizeof(mi), 0); +for a:= Low(TAmmoType) to High(TAmmoType) do + begin + cnt:= byte(s[ord(a) + 1]) - byte('0'); + if cnt > 0 then + begin + if cnt >= 9 then cnt:= AMMO_INFINITE; + TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); + tmp[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; + tmp[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnt; + inc(mi[Ammoz[a].Slot]) + end + end; +end; + +function GetAmmoByNum(num: Longword): PHHAmmo; +begin +TryDo(num < StoreCnt, 'Invalid store number', true); +Result:= StoresList[num] +end; + +procedure AssignStores; +var tteam: PTeam; + i: Longword; +begin +tteam:= TeamsList; +while tteam <> nil do + begin + for i:= 0 to cMaxHHIndex do + if tteam.Hedgehogs[i].Gear <> nil then + tteam.Hedgehogs[i].Ammo:= GetAmmoByNum(tteam.Hedgehogs[i].AmmoStore); + tteam:= tteam.Next + end +end; + +end. diff -r b0eef98928f8 -r 929c44745fd9 hedgewars/uConsole.pas --- a/hedgewars/uConsole.pas Thu Nov 30 22:36:07 2006 +0000 +++ b/hedgewars/uConsole.pas Tue Dec 05 17:27:27 2006 +0000 @@ -33,7 +33,8 @@ implementation {$J+} -uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, uRandom; +uses uMisc, uStore, Types, uConsts, uGears, uTeams, uIO, uKeys, uWorld, uLand, + uRandom, uAmmos; const cLineWidth: integer = 0; cLinesCount = 256; @@ -276,6 +277,7 @@ RegisterVariable('grave' , vtCommand, @chGrave , false); RegisterVariable('bind' , vtCommand, @chBind , true ); RegisterVariable('add' , vtCommand, @chAdd , false); +RegisterVariable('ammstore', vtCommand, @chAddAmmoStore , false); RegisterVariable('skip' , vtCommand, @chSkip , false); RegisterVariable('say' , vtCommand, @chSay , true ); RegisterVariable('ammomenu', vtCommand, @chAmmoMenu , false); diff -r b0eef98928f8 -r 929c44745fd9 hedgewars/uTeams.pas --- a/hedgewars/uTeams.pas Thu Nov 30 22:36:07 2006 +0000 +++ b/hedgewars/uTeams.pas Tue Dec 05 17:27:27 2006 +0000 @@ -18,16 +18,16 @@ unit uTeams; interface -uses SDLh, uConsts, uKeys, uGears, uRandom; +uses SDLh, uConsts, uKeys, uGears, uRandom, uAmmos; {$INCLUDE options.inc} type PHedgehog = ^THedgehog; PTeam = ^TTeam; - PHHAmmo = ^THHAmmo; THedgehog = record Name: string[MAXNAMELEN]; Gear: PGear; NameTag, HealthTag: PSDL_Surface; Ammo: PHHAmmo; + AmmoStore: Longword; CurSlot, CurAmmo: LongWord; AltSlot, AltAmmo: LongWord; Team: PTeam; @@ -35,7 +35,6 @@ visStepPos: LongWord; BotLevel : LongWord; // 0 - Human player end; - THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo; TTeam = record Next: PTeam; Color, AdjColor: Longword; @@ -181,19 +180,6 @@ end; end; -procedure FillAmmoGroup(Ammo: PHHAmmo); -var mi: array[0..cMaxSlotIndex] of byte; - a: TAmmoType; -begin -FillChar(mi, sizeof(mi), 0); -for a:= Low(TAmmoType) to High(TAmmoType) do - begin - TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true); - Ammo^[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo; - inc(mi[Ammoz[a].Slot]) - end; -end; - procedure RecountAllTeamsHealth; var p: PTeam; begin @@ -214,14 +200,11 @@ while p <> nil do begin th:= 0; - FillAmmoGroup(@p.Ammos[0]); for i:= 0 to cMaxHHIndex do if p.Hedgehogs[i].Gear <> nil then begin p.Hedgehogs[i].Gear.Health:= 100; inc(th, 100); - p.Hedgehogs[i].Ammo:= @p.Ammos[0] // 0 means all hedgehogs - // will have common set of ammo end; if th > MaxTeamHealth then MaxTeamHealth:= th; p:= p.Next @@ -239,7 +222,8 @@ if Ammo[CurSlot, CurAmmo].Count = 0 then begin CurAmmo:= 0; - while (CurAmmo <= cMaxSlotAmmoIndex) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurAmmo) + CurSlot:= 0; + while (CurSlot <= cMaxSlotIndex) and (Ammo[CurSlot, CurAmmo].Count = 0) do inc(CurSlot) end; with Ammo[CurSlot, CurAmmo] do