- Implement ammo cases
authorunc0rr
Sun, 10 Dec 2006 15:55:53 +0000
changeset 295 8834f3cb620e
parent 294 92a7ccd67bb9
child 296 607912ccc5af
- Implement ammo cases - Small fixes
hedgewars/HHHandlers.inc
hedgewars/hwengine.dpr
hedgewars/uAI.pas
hedgewars/uAmmos.pas
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/hedgewars/HHHandlers.inc	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/HHHandlers.inc	Sun Dec 10 15:55:53 2006 +0000
@@ -104,11 +104,22 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure PickUp(HH, Gear: PGear);
+var s: shortstring;
+    a: TAmmoType;
 begin
 Gear.Message:= gm_Destroy;
 case Gear.Pos of
+       posCaseAmmo: begin
+                    a:= TAmmoType(Gear.State);
+                    AddAmmo(PHedgehog(HH.Hedgehog), a);
+                    s:= trammo[Ammoz[a].NameId];
+                    AddCaption(s, PHedgehog(HH.Hedgehog).Team.Color, capgrpAmmoinfo);
+                    end;
      posCaseHealth: begin
                     inc(HH.Health, Gear.Health);
+                    str(Gear.Health, s);
+                    s:= '+' + s;
+                    AddCaption(s, PHedgehog(HH.Hedgehog).Team.Color, capgrpAmmoinfo);
                     RenderHealth(PHedgehog(HH.Hedgehog)^);
                     RecountTeamHealth(PHedgehog(HH.Hedgehog)^.Team)
                     end;
--- a/hedgewars/hwengine.dpr	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/hwengine.dpr	Sun Dec 10 15:55:53 2006 +0000
@@ -220,7 +220,7 @@
 SendIPCRaw(@s[0], Length(s) + 1); // send proto version
 
 InitTeams;
-ParseCommand('ammstore 1111111111111119');
+ParseCommand('ammstore 9191111111111110');
 AssignStores;
 
 if isSoundEnabled then InitSound;
--- a/hedgewars/uAI.pas	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/uAI.pas	Sun Dec 10 15:55:53 2006 +0000
@@ -24,7 +24,7 @@
 
 implementation
 uses uTeams, uConsts, SDLh, uAIMisc, uGears, uAIAmmoTests, uAIActions, uMisc,
-     uAIThinkStack;
+     uAIThinkStack, uAmmos;
 
 var BestActions: TActions;
     CanUseAmmo: array [TAmmoType] of boolean;
--- a/hedgewars/uAmmos.pas	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/uAmmos.pas	Sun Dec 10 15:55:53 2006 +0000
@@ -7,17 +7,37 @@
 
 procedure AddAmmoStore(s: shortstring);
 procedure AssignStores;
+procedure AddAmmo(Hedgehog: pointer; ammo: TAmmoType);
+function  HHHasAmmo(Hedgehog: pointer; Ammo: TAmmoType): boolean;
+procedure PackAmmo(Ammo: PHHAmmo; Slot: integer);
+procedure OnUsedAmmo(Ammo: PHHAmmo);
 
 implementation
-uses uMisc, uTeams;
+uses uMisc, uTeams, uGears;
+type TAmmoCounts = array[TAmmoType] of Longword;
 var StoresList: array[0..Pred(cMaxHHs)] of PHHAmmo;
     StoreCnt: Longword = 0;
 
-procedure AddAmmoStore(s: shortstring);
+procedure FillAmmoStore(Ammo: PHHAmmo; var cnts: TAmmoCounts);
 var mi: array[0..cMaxSlotIndex] of byte;
     a: TAmmoType;
-    cnt: Longword;
-    tmp: PHHAmmo;
+begin
+FillChar(mi, sizeof(mi), 0);
+FillChar(Ammo^, sizeof(Ammo^), 0);
+for a:= Low(TAmmoType) to High(TAmmoType) do
+    if cnts[a] > 0 then
+       begin
+       TryDo(mi[Ammoz[a].Slot] <= cMaxSlotAmmoIndex, 'Ammo slot overflow', true);
+       Ammo[Ammoz[a].Slot, mi[Ammoz[a].Slot]]:= Ammoz[a].Ammo;
+       Ammo[Ammoz[a].Slot, mi[Ammoz[a].Slot]].Count:= cnts[a];
+       inc(mi[Ammoz[a].Slot])
+       end
+end;
+
+procedure AddAmmoStore(s: shortstring);
+var cnt: Longword;
+    a: TAmmoType;
+    ammos: TAmmoCounts;
 begin
 TryDo(byte(s[0]) = byte(ord(High(TAmmoType)) + 1), 'Invalid ammo scheme (incompatible frontend)', true);
 
@@ -25,21 +45,15 @@
 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
+    if cnt = 9 then cnt:= AMMO_INFINITE;
+    ammos[a]:= cnt
     end;
+
+FillAmmoStore(StoresList[Pred(StoreCnt)], ammos)
 end;
 
 function GetAmmoByNum(num: Longword): PHHAmmo;
@@ -62,4 +76,70 @@
       end
 end;
 
+procedure AddAmmo(Hedgehog: pointer; ammo: TAmmoType);
+var ammos: TAmmoCounts;
+    slot, ami: integer;
+    hhammo: PHHAmmo;
+begin
+FillChar(ammos, sizeof(ammos), 0);
+hhammo:= PHedgehog(Hedgehog).Ammo;
+
+for slot:= 0 to cMaxSlotIndex do
+    for ami:= 0 to cMaxSlotAmmoIndex do
+        if hhammo[slot, ami].Count > 0 then
+           ammos[hhammo[slot, ami].AmmoType]:= hhammo[slot, ami].Count;
+
+if ammos[ammo] <> AMMO_INFINITE then inc(ammos[ammo]);
+FillAmmoStore(hhammo, ammos)
+end;
+
+procedure PackAmmo(Ammo: PHHAmmo; Slot: integer);
+var ami: integer;
+    b: boolean;
+begin
+    repeat
+      b:= false;
+      ami:= 0;
+      while (not b) and (ami < cMaxSlotAmmoIndex) do
+          if (Ammo[Slot, ami].Count = 0)
+             and (Ammo[Slot, ami + 1].Count > 0) then b:= true
+                                                 else inc(ami);
+      if b then // there's a free item in ammo stack
+         begin
+         Ammo[Slot, ami]:= Ammo[Slot, ami + 1];
+         Ammo[Slot, ami + 1].Count:= 0
+         end;
+    until not b;
+end;
+
+procedure OnUsedAmmo(Ammo: PHHAmmo);
+var s, a: Longword;
+begin
+with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
+     begin
+     if CurAmmoGear = nil then begin s:= CurSlot; a:= CurAmmo end
+                          else begin s:= AltSlot; a:= AltAmmo end;
+     with Ammo[s, a] do
+          if Count <> AMMO_INFINITE then
+             begin
+             dec(Count);
+             if Count = 0 then PackAmmo(Ammo, CurSlot)
+             end
+     end
+end;
+
+function  HHHasAmmo(Hedgehog: pointer; Ammo: TAmmoType): boolean;
+var slot, ami: integer;
+begin
+Slot:= Ammoz[Ammo].Slot;
+ami:= 0;
+Result:= false;
+while (not Result) and (ami <= cMaxSlotAmmoIndex) do
+      begin
+      with PHedgehog(Hedgehog).Ammo[Slot, ami] do
+            if (AmmoType = Ammo) and (Count > 0) then Result:= true;
+      inc(ami)
+      end
+end;
+
 end.
--- a/hedgewars/uGears.pas	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/uGears.pas	Sun Dec 10 15:55:53 2006 +0000
@@ -67,7 +67,7 @@
 
 implementation
 uses uWorld, uMisc, uStore, uConsole, uSound, uTeams, uRandom, uCollisions,
-     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI;
+     uLand, uIO, uLandGraphics, uAIMisc, uLocale, uAI, uAmmos;
 var RopePoints: record
                 Count: Longword;
                 HookAngle: integer;
@@ -779,10 +779,18 @@
 
 procedure SpawnBoxOfSmth;
 begin
-if (CountGears(gtCase) > 2) or (getrandom(3) <> 0) then exit;
+if (CountGears(gtCase) >= 5) or (getrandom(cCaseFactor) <> 0) then exit;
 FollowGear:= AddGear(0, 0, gtCase, 0);
-FollowGear.Health:= 25;
-FollowGear.Pos:= posCaseHealth;
+case getrandom(2) of
+     0: begin
+        FollowGear.Health:= 25;
+        FollowGear.Pos:= posCaseHealth
+        end;
+     1: begin
+        FollowGear.Pos:= posCaseAmmo;
+        FollowGear.State:= Longword(amMineStrike)
+        end;
+     end;
 FindPlace(FollowGear, true, 0, 2048)
 end;
 
--- a/hedgewars/uMisc.pas	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/uMisc.pas	Sun Dec 10 15:55:53 2006 +0000
@@ -65,6 +65,7 @@
     cGravity      : Double = 0.0005;
 
     cShowFPS      : boolean = true;
+    cCaseFactor   : Longword = 3;  {1..10}
     cFullScreen   : boolean = true;
     cLocaleFName  : shortstring = 'en.txt';
     cSeed         : shortstring = '';
--- a/hedgewars/uTeams.pas	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/uTeams.pas	Sun Dec 10 15:55:53 2006 +0000
@@ -42,7 +42,6 @@
              ExtDriven: boolean;
              Binds: TBinds;
              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
-             Ammos: array[0..cMaxHHIndex] of THHAmmo;
              CurrHedgehog: integer;
              NameTag: PSDL_Surface;
              CrosshairSurf: PSDL_Surface;
@@ -62,8 +61,6 @@
 procedure ApplyAmmoChanges(var Hedgehog: THedgehog);
 procedure SwitchHedgehog;
 procedure InitTeams;
-procedure OnUsedAmmo(Ammo: PHHAmmo);
-function  HHHasAmmo(Hedgehog: PHedgehog; Ammo: TAmmoType): boolean;
 function  TeamSize(p: PTeam): Longword;
 procedure RecountTeamHealth(team: PTeam);
 procedure RestoreTeamsFromSave;
@@ -254,55 +251,6 @@
      end
 end;
 
-procedure PackAmmo(Ammo: PHHAmmo; Slot: integer);
-var ami: integer;
-    b: boolean;
-begin
-    repeat
-      b:= false;
-      ami:= 0;
-      while (not b) and (ami < cMaxSlotAmmoIndex) do
-          if (Ammo[Slot, ami].Count = 0)
-             and (Ammo[Slot, ami + 1].Count > 0) then b:= true
-                                                 else inc(ami);
-      if b then // there's a free item in ammo stack
-         begin
-         Ammo[Slot, ami]:= Ammo[Slot, ami + 1];
-         Ammo[Slot, ami + 1].Count:= 0
-         end;
-    until not b;
-end;
-
-procedure OnUsedAmmo(Ammo: PHHAmmo);
-var s, a: Longword;
-begin
-with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do
-     begin
-     if CurAmmoGear = nil then begin s:= CurSlot; a:= CurAmmo end
-                          else begin s:= AltSlot; a:= AltAmmo end;
-     with Ammo[s, a] do
-          if Count <> AMMO_INFINITE then
-             begin
-             dec(Count);
-             if Count = 0 then PackAmmo(Ammo, CurSlot)
-             end
-     end
-end;
-
-function  HHHasAmmo(Hedgehog: PHedgehog; Ammo: TAmmoType): boolean;
-var slot, ami: integer;
-begin
-Slot:= Ammoz[Ammo].Slot;
-ami:= 0;
-Result:= false;
-while (not Result) and (ami <= cMaxSlotAmmoIndex) do
-      begin
-      with  Hedgehog.Ammo[Slot, ami] do
-            if (AmmoType = Ammo) and (Count > 0) then Result:= true;
-      inc(ami)
-      end
-end;
-
 function  TeamSize(p: PTeam): Longword;
 var i: Longword;
 begin
--- a/hedgewars/uWorld.pas	Sun Dec 10 12:09:32 2006 +0000
+++ b/hedgewars/uWorld.pas	Sun Dec 10 15:55:53 2006 +0000
@@ -259,7 +259,7 @@
 i:= 8;
 for grp:= Low(TCapGroup) to High(TCapGroup) do
     with Captions[grp] do
-         if EndTime > 0 then
+         if Surf <> nil then
             begin
             DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Surf, Surface);
             inc(i, Surf.h + 2);
@@ -365,7 +365,7 @@
 if Captions[Group].Surf <> nil then SDL_FreeSurface(Captions[Group].Surf);
 
 Captions[Group].Surf:= RenderString(s, Color, fntBig);
-Captions[Group].EndTime:= RealTicks + 1200
+Captions[Group].EndTime:= RealTicks + 1500
 end;
 
 procedure MoveCamera;