Add CurrentHedgehog variable which simplifies code
authorunc0rr
Fri, 21 Sep 2007 18:55:44 +0000
changeset 602 f7628ebfccde
parent 601 78a68cc4d846
child 603 d7877468653b
Add CurrentHedgehog variable which simplifies code
QTfrontend/game.cpp
hedgewars.kdevelop
hedgewars/CCHandlers.inc
hedgewars/GSHandlers.inc
hedgewars/HHHandlers.inc
hedgewars/uAI.pas
hedgewars/uGame.pas
hedgewars/uGears.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/QTfrontend/game.cpp	Thu Sep 20 20:00:10 2007 +0000
+++ b/QTfrontend/game.cpp	Fri Sep 21 18:55:44 2007 +0000
@@ -252,7 +252,7 @@
 	arguments << cfgdir->absolutePath();
 	arguments << QString::number(resolution.width());
 	arguments << QString::number(resolution.height());
-	arguments << "16"; // bpp
+	arguments << "32"; // bpp
 	arguments << QString("%1").arg(ipc_port);
 	arguments << (config->vid_Fullscreen() ? "1" : "0");
 	arguments << (config->isSoundEnabled() ? "1" : "0");
--- a/hedgewars.kdevelop	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars.kdevelop	Fri Sep 21 18:55:44 2007 +0000
@@ -18,20 +18,20 @@
     <projectname>hedgewars</projectname>
     <projectdirectory>.</projectdirectory>
     <absoluteprojectpath>false</absoluteprojectpath>
-    <description></description>
+    <description/>
     <versioncontrol>kdevsubversion</versioncontrol>
-    <defaultencoding></defaultencoding>
+    <defaultencoding/>
   </general>
   <kdevcustomproject>
     <run>
       <directoryradio>executable</directoryradio>
       <customdirectory>/</customdirectory>
       <mainprogram>/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GNA/bin/hedgewars</mainprogram>
-      <programargs></programargs>
+      <programargs/>
       <terminal>false</terminal>
       <autocompile>true</autocompile>
       <envvars/>
-      <globaldebugarguments></globaldebugarguments>
+      <globaldebugarguments/>
       <globalcwd>/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GNA</globalcwd>
       <useglobalprogram>false</useglobalprogram>
       <autoinstall>false</autoinstall>
@@ -164,16 +164,16 @@
     </general>
     <build>
       <buildtool>make</buildtool>
-      <builddir></builddir>
+      <builddir/>
     </build>
     <make>
       <abortonerror>false</abortonerror>
       <numberofjobs>1</numberofjobs>
       <prio>0</prio>
       <dontact>false</dontact>
-      <makebin></makebin>
-      <defaulttarget></defaulttarget>
-      <makeoptions></makeoptions>
+      <makebin/>
+      <defaulttarget/>
+      <makeoptions/>
       <selectedenvironment>default</selectedenvironment>
       <environments>
         <default/>
@@ -181,9 +181,9 @@
     </make>
     <other>
       <prio>0</prio>
-      <otherbin></otherbin>
-      <defaulttarget></defaulttarget>
-      <otheroptions></otheroptions>
+      <otherbin/>
+      <defaulttarget/>
+      <otheroptions/>
       <selectedenvironment>default</selectedenvironment>
       <environments>
         <default/>
@@ -192,12 +192,12 @@
   </kdevcustomproject>
   <kdevdebugger>
     <general>
-      <dbgshell></dbgshell>
+      <dbgshell/>
       <programargs/>
-      <gdbpath></gdbpath>
-      <configGdbScript></configGdbScript>
-      <runShellScript></runShellScript>
-      <runGdbScript></runGdbScript>
+      <gdbpath/>
+      <configGdbScript/>
+      <runShellScript/>
+      <runGdbScript/>
       <breakonloadinglibs>true</breakonloadinglibs>
       <separatetty>false</separatetty>
       <floatingtoolbar>false</floatingtoolbar>
@@ -302,7 +302,7 @@
       <includeTypedefs>false</includeTypedefs>
     </codecompletion>
     <creategettersetter>
-      <prefixGet></prefixGet>
+      <prefixGet/>
       <prefixSet>set</prefixSet>
       <prefixVariable>m_,_</prefixVariable>
       <parameterName>theValue</parameterName>
@@ -334,13 +334,13 @@
   </cppsupportpart>
   <kdevdocumentation>
     <projectdoc>
-      <docsystem></docsystem>
-      <docurl></docurl>
-      <usermanualurl></usermanualurl>
+      <docsystem/>
+      <docurl/>
+      <usermanualurl/>
     </projectdoc>
   </kdevdocumentation>
   <ctagspart>
-    <customArguments></customArguments>
+    <customArguments/>
     <customTagfilePath>/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GNA/tags</customTagfilePath>
     <activeTagsFiles/>
   </ctagspart>
--- a/hedgewars/CCHandlers.inc	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/CCHandlers.inc	Fri Sep 21 18:55:44 2007 +0000
@@ -19,7 +19,7 @@
 function CheckNoTeamOrHH: boolean;
 var Result: boolean;
 begin
-Result:= (CurrentTeam = nil) or (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear = nil);
+Result:= (CurrentTeam = nil) or (CurrentHedgehog^.Gear = nil);
 {$IFDEF DEBUGFILE}
 if Result then
    if CurrentTeam = nil then AddFileLog('CONSOLE: CurTeam = nil')
@@ -106,9 +106,9 @@
 with CurrentTeam^ do
      begin
      SplitBySpace(id, s);
-     val(id, Hedgehogs[HedgehogsNumber].BotLevel);
+     CurrentHedgehog:= @Hedgehogs[HedgehogsNumber];
+     val(id, CurrentHedgehog^.BotLevel);
      Gear:= AddGear(0, 0, gtHedgehog, 0, _0, _0, 0);
-     Gear^.Hedgehog:= @Hedgehogs[HedgehogsNumber];
      val(s, Gear^.Health);
      TryDo(Gear^.Health > 0, 'Invalid hedgehog health', true);
      PHedgehog(Gear^.Hedgehog)^.Team:= CurrentTeam;
@@ -141,7 +141,7 @@
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven then SendIPC('L');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
     Message:= Message or gm_Left
 end;
 
@@ -149,7 +149,7 @@
 begin
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('l');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      Message:= Message and not gm_Left
 end;
 
@@ -158,7 +158,7 @@
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven then SendIPC('R');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
     Message:= Message or gm_Right
 end;
 
@@ -166,7 +166,7 @@
 begin
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('r');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      Message:= Message and not gm_Right
 end;
 
@@ -175,7 +175,7 @@
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven then SendIPC('U');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
     Message:= Message or gm_Up
 end;
 
@@ -183,7 +183,7 @@
 begin
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('u');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      Message:= Message and not gm_Up
 end;
 
@@ -192,7 +192,7 @@
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven then SendIPC('D');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
     Message:= Message or gm_Down
 end;
 
@@ -200,7 +200,7 @@
 begin
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('d');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      Message:= Message and not gm_Down
 end;
 
@@ -209,7 +209,7 @@
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven then SendIPC('j');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
     Message:= Message or gm_LJump
 end;
 
@@ -218,7 +218,7 @@
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
 if not CurrentTeam^.ExtDriven then SendIPC('J');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
     Message:= Message or gm_HJump
 end;
 
@@ -226,13 +226,13 @@
 begin
 if CheckNoTeamOrHH then exit;
 bShowFinger:= false;
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      begin
      {$IFDEF DEBUGFILE}AddFileLog('/+attack: Gear^.State = '+inttostr(State));{$ENDIF}
      if ((State and gstHHDriven) <> 0) and
         ((State and (gstAttacked or gstHHChooseTarget)) = 0) then
         begin
-        FollowGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear;
+        FollowGear:= CurrentHedgehog^.Gear;
         if not CurrentTeam^.ExtDriven then SendIPC('A');
         Message:= Message or gm_Attack
         end
@@ -242,7 +242,7 @@
 procedure chAttack_m(var s: shortstring);
 begin
 if CheckNoTeamOrHH then exit;
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      begin
      if not CurrentTeam^.ExtDriven and
         ((Message and gm_Attack) <> 0) then SendIPC('a');
@@ -254,7 +254,7 @@
 begin
 if CheckNoTeamOrHH then exit;
 if not CurrentTeam^.ExtDriven then SendIPC('S');
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^ do
+with CurrentHedgehog^.Gear^ do
      Message:= Message or gm_Switch
 end;
 
@@ -279,7 +279,7 @@
 begin
 if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit;
 bShowFinger:= false;
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+with CurrentHedgehog^ do
      if (Ammo^[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then
         begin
         Ammo^[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48);
@@ -331,8 +331,8 @@
    exit
    end;
 
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^,
-     CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+with CurrentHedgehog^.Gear^,
+     CurrentHedgehog^ do
      if (State and gstHHChooseTarget) <> 0 then
         begin
         isCursorVisible:= false;
@@ -450,7 +450,7 @@
 begin
 if CheckNoTeamOrHH then exit;
 bShowFinger:= true;
-FollowGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear
+FollowGear:= CurrentHedgehog^.Gear
 end;
 
 procedure chPause(var s: shortstring);
--- a/hedgewars/GSHandlers.inc	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/GSHandlers.inc	Fri Sep 21 18:55:44 2007 +0000
@@ -820,7 +820,7 @@
    begin
    DeleteGear(Gear);
    FreeActionsList;
-   with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+   with CurrentHedgehog^ do
      if Gear <> nil then Gear^.Message:= Gear^.Message and not (gm_LJump or gm_HJump);
    exit
    end;
@@ -1204,7 +1204,7 @@
    OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
    ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
 
-   HHGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear;
+   HHGear:= CurrentHedgehog^.Gear;
    ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^);
    HHGear^.Message:= Msg;
    exit
@@ -1212,7 +1212,7 @@
 
 if (Gear^.Message and gm_Switch) <> 0 then
    begin
-   HHGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear;
+   HHGear:= CurrentHedgehog^.Gear;
    HHGear^.Message:= HHGear^.Message and not gm_Switch;
    State:= HHGear^.State;
    HHGear^.State:= 0;
@@ -1223,9 +1223,9 @@
 
    repeat
      CurrentTeam^.CurrHedgehog:= Succ(CurrentTeam^.CurrHedgehog) mod (CurrentTeam^.HedgehogsNumber);
-   until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil);
+   until (CurrentHedgehog^.Gear <> nil);
 
-   HHGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear;
+   HHGear:= CurrentHedgehog^.Gear;
    HHGear^.State:= State;
    HHGear^.Active:= true;
    FollowGear:= HHGear;
--- a/hedgewars/HHHandlers.inc	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/HHHandlers.inc	Fri Sep 21 18:55:44 2007 +0000
@@ -89,8 +89,8 @@
 
 procedure AfterAttack;
 begin
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^,
-     CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+with CurrentHedgehog^.Gear^,
+     CurrentHedgehog^ do
      begin
         Inc(AttacksNum);
         State:= State and not gstAttacking;
@@ -98,7 +98,7 @@
            else begin
            TurnTimeLeft:= Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType].TimeAfterTurn;
            State:= State or gstAttacked;
-           OnUsedAmmo(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog])
+           OnUsedAmmo(CurrentHedgehog^)
            end;
      AttackBar:= 0;
      end
--- a/hedgewars/uAI.pas	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/uAI.pas	Fri Sep 21 18:55:44 2007 +0000
@@ -45,7 +45,7 @@
    until hasThread = 0
    end;
 
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+with CurrentHedgehog^ do
      if Gear <> nil then
         if BotLevel <> 0 then
            begin
@@ -68,7 +68,7 @@
 for i:= 0 to Pred(Targets.Count) do
     if (Targets.ar[i].Score >= 0) and (not StopThinking) then
        begin
-       with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+       with CurrentHedgehog^ do
             a:= Ammo^[CurSlot, CurAmmo].AmmoType;
        aa:= a;
        repeat
@@ -115,7 +115,7 @@
         if a = High(TAmmoType) then a:= Low(TAmmoType)
                                else inc(a)
        until (a = aa) or
-             (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].AttacksNum > 0) or
+             (CurrentHedgehog^.AttacksNum > 0) or
              StopThinking
        end
 end;
@@ -317,7 +317,7 @@
 const StartTicks: Longword = 0;
       cStopThinkTime = 40;
 begin
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+with CurrentHedgehog^ do
      if (Gear <> nil)
         and ((Gear^.State and gstHHDriven) <> 0)
         and (TurnTimeLeft < cHedgehogTurnTime - 50) then
--- a/hedgewars/uGame.pas	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/uGame.pas	Fri Sep 21 18:55:44 2007 +0000
@@ -52,8 +52,7 @@
     begin
     if not CurrentTeam^.ExtDriven then
        begin
-       with CurrentTeam^ do
-           if Hedgehogs[CurrHedgehog].BotLevel <> 0 then ProcessBot;
+       if CurrentHedgehog^.BotLevel <> 0 then ProcessBot;
        ProcessGears
        end else
        begin
--- a/hedgewars/uGears.pas	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/uGears.pas	Fri Sep 21 18:55:44 2007 +0000
@@ -186,8 +186,8 @@
 
 if CurrentTeam <> nil then
    begin
-   Result^.Hedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
-   Result^.IntersectGear:= CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear
+   Result^.Hedgehog:= CurrentHedgehog;
+   Result^.IntersectGear:= CurrentHedgehog^.Gear
    end;
    
 case Kind of
@@ -327,7 +327,7 @@
          inc(StepDamage, t)
          end;
       team:= PHedgehog(Gear^.Hedgehog)^.Team;
-      if CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear = Gear then
+      if CurrentHedgehog^.Gear = Gear then
          FreeActionsList; // to avoid ThinkThread on drawned gear
       PHedgehog(Gear^.Hedgehog)^.Gear:= nil;
       inc(KilledHHs);
@@ -406,7 +406,7 @@
                  //AwareOfExplosion(0, 0, 0);
                  if isInMultiShoot then isInMultiShoot:= false
                     else begin
-                    with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+                    with CurrentHedgehog^ do
                          if MaxStepDamage < StepDamage then MaxStepDamage:= StepDamage;
                     StepDamage:= 0;
                     ParseCommand('/nextturn', true);
@@ -417,8 +417,8 @@
 
 if TurnTimeLeft > 0 then
    if CurrentTeam <> nil then
-      if CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil then
-         if ((CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.State and gstAttacking) = 0)
+      if CurrentHedgehog^.Gear <> nil then
+         if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0)
             and not isInMultiShoot then dec(TurnTimeLeft);
 
 inc(GameTicks)
--- a/hedgewars/uTeams.pas	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/uTeams.pas	Fri Sep 21 18:55:44 2007 +0000
@@ -71,6 +71,7 @@
              end;
 
 var CurrentTeam: PTeam = nil;
+    CurrentHedgehog: PHedgehog = nil;
     TeamsArray: array[0..Pred(cMaxTeams)] of PTeam;
     TeamsCount: Longword = 0;
     ClansArray: array[0..Pred(cMaxTeams)] of PClan;
@@ -169,7 +170,8 @@
     until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam);
 until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil;
 
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
+with CurrentHedgehog^ do
      begin
      with Gear^ do
           begin
@@ -187,7 +189,7 @@
 g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1);
 g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed);
 {$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF}
-ApplyAmmoChanges(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]);
+ApplyAmmoChanges(CurrentHedgehog^);
 if CurrentTeam^.ExtDriven then SetDefaultBinds
                           else SetBinds(CurrentTeam^.Binds);
 bShowFinger:= true;
--- a/hedgewars/uWorld.pas	Thu Sep 20 20:00:10 2007 +0000
+++ b/hedgewars/uWorld.pas	Fri Sep 21 18:55:44 2007 +0000
@@ -92,7 +92,7 @@
 if CurrentTeam = nil then exit;
 Slot:= 0;
 Pos:= -1;
-with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+with CurrentHedgehog^ do
      begin
      if Ammo = nil then exit;
      SlotsNum:= 0;
@@ -235,11 +235,11 @@
         1: begin
            r:= StuffPoz[sPowerBar];
            {$WARNINGS OFF}
-           r.w:= (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear^.Power * 256) div cPowerDivisor;
+           r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
            {$WARNINGS ON}
            DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
            end;
-        2: with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+        2: with CurrentHedgehog^ do
                 begin
                 tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
                 tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
@@ -329,7 +329,7 @@
 if isCursorVisible then
    begin
    if not bShowAmmoMenu then
-     with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
+     with CurrentHedgehog^ do
        if (Gear^.State and gstHHChooseTarget) <> 0 then
          begin
          i:= Ammo^[CurSlot, CurAmmo].Pos;