--- a/hedgewars/CCHandlers.inc Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/CCHandlers.inc Mon Jul 02 21:33:21 2007 +0000
@@ -46,15 +46,11 @@
end
end;
-const TeamsCount: Longword = 0;
-
procedure chAddTeam(var s: shortstring);
begin
if isDeveloperMode then
begin
- inc(TeamsCount);
ParseCommand('ammstore 93919294221912103323', true);
- TryDo(TeamsCount <= 6, 'Too many teams', true);
AddTeam;
--- a/hedgewars/GSHandlers.inc Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/GSHandlers.inc Mon Jul 02 21:33:21 2007 +0000
@@ -874,19 +874,18 @@
end;
procedure doStepTeamHealthSorter(Gear: PGear);
-var team: PTeam;
- i, t: Longword;
+var i, t: Longword;
begin
AllInactive:= false;
-team:= TeamsList;
i:= 0;
-while team <> nil do
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
- thexchar[i].oy:= team^.DrawHealthY;
- thexchar[i].team:= team;
+ thexchar[i].oy:= DrawHealthY;
+ thexchar[i].team:= TeamsArray[t];
inc(i);
- team:= team^.Next
end;
+
thexchcnt:= i;
for i:= 1 to thexchcnt do
for t:= 0 to thexchcnt - 2 do
@@ -896,6 +895,7 @@
thexchar[t]:= thexchar[Succ(t)];
thexchar[Succ(t)]:= thexchar[5]
end;
+
t:= cScreenHeight - 4;
for i:= 0 to Pred(thexchcnt) do
with thexchar[i] do
@@ -903,6 +903,7 @@
dec(t, team^.HealthRect.h + 2);
ny:= t
end;
+
Gear^.Timer:= 640;
Gear^.doStep:= @doStepTeamHealthSorterWork;
currsorter:= Gear
--- a/hedgewars/uAIMisc.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uAIMisc.pas Mon Jul 02 21:33:21 2007 +0000
@@ -69,27 +69,25 @@
end = (X: 0; Y: 0; Radius: 0);
procedure FillTargets;
-var t: PTeam;
- i: Longword;
+var i, t: Longword;
begin
Targets.Count:= 0;
-t:= TeamsList;
-while t <> nil do
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
for i:= 0 to cMaxHHIndex do
- if (t^.Hedgehogs[i].Gear <> nil)
- and (t^.Hedgehogs[i].Gear <> ThinkingHH) then
+ if (Hedgehogs[i].Gear <> nil)
+ and (Hedgehogs[i].Gear <> ThinkingHH) then
begin
- with Targets.ar[Targets.Count], t^.Hedgehogs[i] do
+ with Targets.ar[Targets.Count], Hedgehogs[i] do
begin
Point.X:= hwRound(Gear^.X);
Point.Y:= hwRound(Gear^.Y);
- if t^.Color <> CurrentTeam^.Color then Score:= Gear^.Health
- else Score:= -Gear^.Health
+ if Color <> CurrentTeam^.Color then Score:= Gear^.Health
+ else Score:= -Gear^.Health
end;
inc(Targets.Count)
end;
- t:= t^.Next
end
end;
--- a/hedgewars/uAmmos.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uAmmos.pas Mon Jul 02 21:33:21 2007 +0000
@@ -79,16 +79,15 @@
end;
procedure AssignStores;
-var tteam: PTeam;
+var t: LongInt;
i: Longword;
begin
-tteam:= TeamsList;
-while tteam <> nil do
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ 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
+ if Hedgehogs[i].Gear <> nil then
+ Hedgehogs[i].Ammo:= GetAmmoByNum(Hedgehogs[i].AmmoStore);
end
end;
--- a/hedgewars/uConsts.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uConsts.pas Mon Jul 02 21:33:21 2007 +0000
@@ -115,6 +115,7 @@
cTransparentColor: Longword = $000000;
+ cMaxTeams = 6;
cMaxHHIndex = 7;
cMaxHHs = 30;
cMaxSpawnPoints = 1024;
--- a/hedgewars/uGears.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uGears.pas Mon Jul 02 21:33:21 2007 +0000
@@ -774,37 +774,34 @@
end;
procedure AssignHHCoords;
-var Team: PTeam;
- i, t: LongInt;
+var i, t, p: LongInt;
ar: array[0..Pred(cMaxHHs)] of PGear;
Count: Longword;
begin
-Team:= TeamsList;
-
if (GameFlags and gfForts) <> 0 then
begin
t:= 0;
- while Team <> nil do
+ for p:= 0 to Pred(TeamsCount) do
+ with TeamsArray[p]^ do
begin
for i:= 0 to cMaxHHIndex do
- with Team^.Hedgehogs[i] do
+ with Hedgehogs[i] do
if Gear <> nil then FindPlace(Gear, false, t, t + 1024);
inc(t, 1024);
- Team:= Team^.Next
end
end else // mix hedgehogs
begin
Count:= 0;
- while Team <> nil do
+ for p:= 0 to Pred(TeamsCount) do
+ with TeamsArray[p]^ do
begin
for i:= 0 to cMaxHHIndex do
- with Team^.Hedgehogs[i] do
+ with Hedgehogs[i] do
if Gear <> nil then
begin
ar[Count]:= Gear;
inc(Count)
end;
- Team:= Team^.Next
end;
while (Count > 0) do
--- a/hedgewars/uLand.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uLand.pas Mon Jul 02 21:33:21 2007 +0000
@@ -488,25 +488,22 @@
end;
procedure MakeFortsMap;
-var p: PTeam;
- tmpsurf: PSDL_Surface;
+var tmpsurf: PSDL_Surface;
begin
WriteLnToConsole('Generating forts land...');
-p:= TeamsList;
-TryDo(p <> nil, 'No teams on map!', true);
+TryDo(TeamsCount = 2, 'More or less than 2 teams on map in forts mode!', true);
+
with PixelFormat^ do
LandSurface:= SDL_CreateRGBSurface(SDL_HWSURFACE, 2048, 1024, BitsPerPixel, RMask, GMask, BMask, AMask);
SDL_FillRect(LandSurface, nil, 0);
-tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p^.FortName + 'L', false, true, true);
+
+tmpsurf:= LoadImage(Pathz[ptForts] + '/' + TeamsArray[0]^.FortName + 'L', false, true, true);
BlitImageAndGenerateCollisionInfo(0, 0, tmpsurf, LandSurface);
SDL_FreeSurface(tmpsurf);
-p:= p^.Next;
-TryDo(p <> nil, 'Only one team on map!', true);
-tmpsurf:= LoadImage(Pathz[ptForts] + '/' + p^.FortName + 'R', false, true, true);
+
+tmpsurf:= LoadImage(Pathz[ptForts] + '/' + TeamsArray[1]^.FortName + 'R', false, true, true);
BlitImageAndGenerateCollisionInfo(1024, 0, tmpsurf, LandSurface);
SDL_FreeSurface(tmpsurf);
-p:= p^.Next;
-TryDo(p = nil, 'More than 2 teams on map in forts mode!', true);
end;
procedure LoadMap;
--- a/hedgewars/uStore.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uStore.pas Mon Jul 02 21:33:21 2007 +0000
@@ -132,7 +132,7 @@
tmpsurf: PSDL_Surface;
procedure WriteNames(Font: THWFont);
- var Team: PTeam;
+ var t: LongInt;
i: LongInt;
r, rr: TSDL_Rect;
drY: LongInt;
@@ -140,81 +140,77 @@
r.x:= 0;
r.y:= 272;
drY:= cScreenHeight - 4;
- Team:= TeamsList;
- while Team<>nil do
+ for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
r.w:= 104;
- Team^.NameTag:= RenderString(Team^.TeamName, Team^.Color, Font);
+ NameTag:= RenderString(TeamName, Color, Font);
r.w:= cTeamHealthWidth + 5;
- r.h:= Team^.NameTag^.h;
+ r.h:= NameTag^.h;
DrawRoundRect(@r, cWhiteColor, cColorNearBlack, StoreSurface, true);
- Team^.HealthRect:= r;
+ HealthRect:= r;
rr:= r;
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4);
- DrawRoundRect(@rr, Team^.AdjColor, Team^.AdjColor, StoreSurface, false);
+ DrawRoundRect(@rr, AdjColor, AdjColor, StoreSurface, false);
inc(r.y, r.h);
dec(drY, r.h + 2);
- Team^.DrawHealthY:= drY;
+ DrawHealthY:= drY;
for i:= 0 to 7 do
- with Team^.Hedgehogs[i] do
+ with Hedgehogs[i] do
if Gear <> nil then
- NameTag:= RenderString(Name, Team^.Color, fnt16);
- Team:= Team^.Next
+ NameTag:= RenderString(Name, Color, fnt16);
end;
end;
procedure MakeCrossHairs;
- var Team: PTeam;
+ var t: LongInt;
tmpsurf: PSDL_Surface;
s: string;
begin
s:= Pathz[ptGraphics] + '/' + cCHFileName;
tmpsurf:= LoadImage(s, true, true, false);
- Team:= TeamsList;
- while Team<>nil do
+ for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
- Team^.CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
- TryDo(Team^.CrosshairSurf <> nil, errmsgCreateSurface, true);
- SDL_FillRect(Team^.CrosshairSurf, nil, Team^.AdjColor);
- SDL_UpperBlit(tmpsurf, nil, Team^.CrosshairSurf, nil);
- TryDo(SDL_SetColorKey(Team^.CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
- Team:= Team^.Next
+ CrosshairSurf:= SDL_CreateRGBSurface(SDL_HWSURFACE, tmpsurf^.w, tmpsurf^.h, cBits, PixelFormat^.RMask, PixelFormat^.GMask, PixelFormat^.BMask, PixelFormat^.AMask);
+ TryDo(CrosshairSurf <> nil, errmsgCreateSurface, true);
+ SDL_FillRect(CrosshairSurf, nil, AdjColor);
+ SDL_UpperBlit(tmpsurf, nil, CrosshairSurf, nil);
+ TryDo(SDL_SetColorKey(CrosshairSurf, SDL_SRCCOLORKEY or SDL_RLEACCEL, 0) = 0, errmsgTransparentSet, true);
end;
SDL_FreeSurface(tmpsurf)
end;
procedure InitHealth;
- var p: PTeam;
- i: LongInt;
+ var i, t: LongInt;
begin
- p:= TeamsList;
- while p <> nil do
+ for t:= 0 to Pred(TeamsCount) do
+ if TeamsArray[t] <> nil then
+ with TeamsArray[t]^ do
begin
for i:= 0 to cMaxHHIndex do
- if p^.Hedgehogs[i].Gear <> nil then
- RenderHealth(p^.Hedgehogs[i]);
- p:= p^.Next
+ if Hedgehogs[i].Gear <> nil then
+ RenderHealth(Hedgehogs[i]);
end
end;
procedure LoadGraves;
- var p: PTeam;
- l: LongInt;
+ var t, l: LongInt;
begin
- p:= TeamsList;
l:= 512;
- while p <> nil do
+ for t:= 0 to Pred(TeamsCount) do
+ if TeamsArray[t] <> nil then
+ with TeamsArray[t]^ do
begin
dec(l, 32);
- if p^.GraveName = '' then p^.GraveName:= 'Simple';
- LoadToSurface(Pathz[ptGraves] + '/' + p^.GraveName, StoreSurface, l, 512);
- p^.GraveRect.x:= l;
- p^.GraveRect.y:= 512;
- p^.GraveRect.w:= 32;
- p^.GraveRect.h:= 256;
- p:= p^.Next
+ if GraveName = '' then GraveName:= 'Simple';
+ LoadToSurface(Pathz[ptGraves] + '/' + GraveName, StoreSurface, l, 512);
+ GraveRect.x:= l;
+ GraveRect.y:= 512;
+ GraveRect.w:= 32;
+ GraveRect.h:= 256;
end
end;
--- a/hedgewars/uTeams.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uTeams.pas Mon Jul 02 21:33:21 2007 +0000
@@ -42,7 +42,6 @@
MaxStepDamage: Longword;
end;
TTeam = record
- Next: PTeam;
Color, AdjColor: Longword;
TeamName: string[MAXNAMELEN];
ExtDriven: boolean;
@@ -62,7 +61,8 @@
end;
var CurrentTeam: PTeam = nil;
- TeamsList: PTeam = nil;
+ TeamsArray: array[0..Pred(cMaxTeams)] of PTeam;
+ TeamsCount: Longword = 0;
CurMinAngle, CurMaxAngle: Longword;
function AddTeam: PTeam;
@@ -84,34 +84,20 @@
function CheckForWin: boolean;
var team, AliveTeam: PTeam;
- AliveCount: Longword;
s: shortstring;
begin
-AliveCount:= 0;
-AliveTeam:= nil;
-team:= TeamsList;
-while team <> nil do
- begin
- if team^.TeamHealth > 0 then
- begin
- inc(AliveCount);
- AliveTeam:= team
- end;
- team:= team^.Next
- end;
-
-if AliveCount >= 2 then exit(false);
+if TeamsCount >= 2 then exit(false);
CheckForWin:= true;
TurnTimeLeft:= 0;
-if AliveCount = 0 then
+if TeamsCount = 0 then
begin // draw
AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState);
SendStat(siGameResult, trmsg[sidDraw]);
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000)
end else // win
begin
- s:= Format(trmsg[sidWinner], AliveTeam^.TeamName);
+ s:= Format(trmsg[sidWinner], TeamsArray[0]^.TeamName);
AddCaption(s, $FFFFFF, capgrpGameState);
SendStat(siGameResult, s);
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000)
@@ -120,14 +106,14 @@
end;
procedure SwitchHedgehog;
-var tteam: PTeam;
- th: LongInt;
+var th: LongInt;
+ t: LongWord;
g: PGear;
begin
FreeActionsList;
TargetPoint.X:= NoPointX;
TryDo(CurrentTeam <> nil, 'nil Team', true);
-tteam:= CurrentTeam;
+
with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
if Gear <> nil then
begin
@@ -138,16 +124,14 @@
InsertGearToList(Gear)
end;
+t:= 0;
+while CurrentTeam <> TeamsArray[t] do inc(t);
+CurrentTeam:= TeamsArray[(t + 1) mod TeamsCount];
+
+th:= CurrentTeam^.CurrHedgehog;
repeat
- CurrentTeam:= CurrentTeam^.Next;
- if CurrentTeam = nil then CurrentTeam:= TeamsList;
- th:= CurrentTeam^.CurrHedgehog;
- repeat
- CurrentTeam^.CurrHedgehog:= Succ(CurrentTeam^.CurrHedgehog) mod (cMaxHHIndex + 1);
- until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (CurrentTeam^.CurrHedgehog = th)
-until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (CurrentTeam = tteam);
-
-TryDo(CurrentTeam <> tteam, 'Switch hedgehog: only one team?!', true);
+ CurrentTeam^.CurrHedgehog:= Succ(CurrentTeam^.CurrHedgehog) mod (cMaxHHIndex + 1);
+until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (CurrentTeam^.CurrHedgehog = th);
with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do
begin
@@ -177,58 +161,46 @@
function AddTeam: PTeam;
var Result: PTeam;
begin
+TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true);
New(Result);
TryDo(Result <> nil, 'AddTeam: Result = nil', true);
FillChar(Result^, sizeof(TTeam), 0);
Result^.AttackBar:= 2;
Result^.CurrHedgehog:= cMaxHHIndex;
-if TeamsList = nil then TeamsList:= Result
- else begin
- Result^.Next:= TeamsList;
- TeamsList:= Result
- end;
+
+TeamsArray[TeamsCount]:= Result;
+inc(TeamsCount);
+
CurrentTeam:= Result;
AddTeam:= Result
end;
procedure FreeTeamsList;
-var t, tt: PTeam;
+var t: LongInt;
begin
-tt:= TeamsList;
-TeamsList:= nil;
-while tt <> nil do
- begin
- t:= tt;
- tt:= tt^.Next;
- Dispose(t)
- end;
+for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]);
+TeamsCount:= 0
end;
procedure RecountAllTeamsHealth;
-var p: PTeam;
-begin
-p:= TeamsList;
-while p <> nil do
- begin
- RecountTeamHealth(p);
- p:= p^.Next
- end
+var t: LongInt;
+begin
+for t:= 0 to Pred(TeamsCount) do
+ RecountTeamHealth(TeamsArray[t])
end;
procedure InitTeams;
-var p: PTeam;
- i: LongInt;
+var i, t: LongInt;
th: LongInt;
begin
-p:= TeamsList;
-while p <> nil do
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
th:= 0;
for i:= 0 to cMaxHHIndex do
- if p^.Hedgehogs[i].Gear <> nil then
- inc(th, p^.Hedgehogs[i].Gear^.Health);
+ if Hedgehogs[i].Gear <> nil then
+ inc(th, Hedgehogs[i].Gear^.Health);
if th > MaxTeamHealth then MaxTeamHealth:= th;
- p:= p^.Next
end;
RecountAllTeamsHealth
end;
@@ -307,14 +279,10 @@
end;
procedure RestoreTeamsFromSave;
-var p: PTeam;
+var t: LongInt;
begin
-p:= TeamsList;
-while p <> nil do
- begin
- p^.ExtDriven:= false;
- p:= p^.Next
- end;
+for t:= 0 to Pred(TeamsCount) do
+ TeamsArray[t]^.ExtDriven:= false
end;
procedure SetWeapon(weap: TAmmoType);
@@ -331,21 +299,19 @@
end;
procedure SendStats;
-var p: PTeam;
- i: LongInt;
+var i, t: LongInt;
msd: Longword; msdhh: PHedgehog;
begin
msd:= 0; msdhh:= nil;
-p:= TeamsList;
-while p <> nil do
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
for i:= 0 to cMaxHHIndex do
- if p^.Hedgehogs[i].MaxStepDamage > msd then
+ if Hedgehogs[i].MaxStepDamage > msd then
begin
- msdhh:= @(p^.Hedgehogs[i]);
- msd:= p^.Hedgehogs[i].MaxStepDamage
+ msdhh:= @Hedgehogs[i];
+ msd:= Hedgehogs[i].MaxStepDamage
end;
- p:= p^.Next
end;
if msdhh <> nil then SendStat(siMaxStepDamage, inttostr(msdhh^.MaxStepDamage) + ' ' +
msdhh^.Name + ' (' + msdhh^.Team^.TeamName + ')');
--- a/hedgewars/uWorld.pas Mon Jul 02 18:35:31 2007 +0000
+++ b/hedgewars/uWorld.pas Mon Jul 02 21:33:21 2007 +0000
@@ -153,7 +153,6 @@
procedure DrawWorld(Lag: LongInt; Surface: PSDL_Surface);
var i, t: LongInt;
r: TSDL_Rect;
- team: PTeam;
tdx, tdy: Double;
grp: TCapGroup;
s: string[15];
@@ -273,25 +272,24 @@
end;
// Teams Healths
-team:= TeamsList;
-while team <> nil do
+for t:= 0 to Pred(TeamsCount) do
+ with TeamsArray[t]^ do
begin
- 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^.TeamHealthBarWidth;
+ r.x:= cScreenWidth div 2 - NameTag^.w - 3;
+ r.y:= DrawHealthY;
+ r.w:= NameTag^.w;
+ r.h:= NameTag^.h;
+ SDL_UpperBlit(NameTag, nil, Surface, @r);
+ r:= HealthRect;
+ r.w:= 2 + TeamHealthBarWidth;
DrawFromStoreRect(cScreenWidth div 2,
- Team^.DrawHealthY,
+ DrawHealthY,
@r, Surface);
inc(r.x, cTeamHealthWidth + 2);
r.w:= 3;
- DrawFromStoreRect(cScreenWidth div 2 + team^.TeamHealthBarWidth + 2,
- Team^.DrawHealthY,
+ DrawFromStoreRect(cScreenWidth div 2 + TeamHealthBarWidth + 2,
+ DrawHealthY,
@r, Surface);
- team:= team^.Next
end;
// Lag alert