hedgewars/uTeams.pas
changeset 1299 fc801a832e0e
parent 1251 1f545d9a10ca
child 1351 aa7aefec5c1b
equal deleted inserted replaced
1298:18fdc25fe65d 1299:fc801a832e0e
    20 interface
    20 interface
    21 uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats, GL;
    21 uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats, GL;
    22 {$INCLUDE options.inc}
    22 {$INCLUDE options.inc}
    23 
    23 
    24 type PHHAmmo = ^THHAmmo;
    24 type PHHAmmo = ^THHAmmo;
    25      THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo;
    25 	THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo;
    26 
    26 
    27 type PHedgehog = ^THedgehog;
    27 	PHedgehog = ^THedgehog;
    28      PTeam     = ^TTeam;
    28 	PTeam     = ^TTeam;
    29      PClan     = ^TClan;
    29 	PClan     = ^TClan;
    30      THedgehog = record
    30 	
    31                  Name: string[MAXNAMELEN];
    31 	THedgehog = record
    32                  Gear: PGear;
    32 			Name: string[MAXNAMELEN];
    33                  NameTagTex,
    33 			Gear: PGear;
    34                  HealthTagTex,
    34 			NameTagTex,
    35                  HatTex: PTexture;
    35 			HealthTagTex,
    36                  Ammo: PHHAmmo;
    36 			HatTex: PTexture;
    37                  AmmoStore: Longword;
    37 			Ammo: PHHAmmo;
    38                  CurSlot, CurAmmo: LongWord;
    38 			AmmoStore: Longword;
    39                  Team: PTeam;
    39 			CurSlot, CurAmmo: LongWord;
    40                  AttacksNum: Longword;
    40 			Team: PTeam;
    41                  visStepPos: LongWord;
    41 			AttacksNum: Longword;
    42                  BotLevel  : LongWord; // 0 - Human player
    42 			visStepPos: LongWord;
    43                  HatVisibility: GLfloat;
    43 			BotLevel  : LongWord; // 0 - Human player
    44                  stats: TStatistics;
    44 			HatVisibility: GLfloat;
    45                  Hat: String;
    45 			stats: TStatistics;
    46                  end;
    46 			Hat: String;
    47      TTeam = record
    47 			end;
    48              Clan: PClan;
    48 			
    49              TeamName: string[MAXNAMELEN];
    49 	TTeam = record
    50              ExtDriven: boolean;
    50 			Clan: PClan;
    51              Binds: TBinds;
    51 			TeamName: string[MAXNAMELEN];
    52              Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
    52 			ExtDriven: boolean;
    53              CurrHedgehog: LongWord;
    53 			Binds: TBinds;
    54              NameTagTex: PTexture;
    54 			Hedgehogs: array[0..cMaxHHIndex] of THedgehog;
    55              CrosshairTex,
    55 			CurrHedgehog: LongWord;
    56              GraveTex,
    56 			NameTagTex: PTexture;
    57              HealthTex: PTexture;
    57 			CrosshairTex,
    58              GraveName: string;
    58 			GraveTex,
    59              FortName: string;
    59 			HealthTex: PTexture;
    60              TeamHealth: LongInt;
    60 			GraveName: string;
    61              TeamHealthBarWidth,
    61 			FortName: string;
    62              NewTeamHealthBarWidth: LongInt;
    62 			TeamHealth: LongInt;
    63              DrawHealthY: LongInt;
    63 			TeamHealthBarWidth,
    64              AttackBar: LongWord;
    64 			NewTeamHealthBarWidth: LongInt;
    65              HedgehogsNumber: Longword;
    65 			DrawHealthY: LongInt;
    66              end;
    66 			AttackBar: LongWord;
    67      TClan = record
    67 			HedgehogsNumber: Longword;
    68              Color: Longword;
    68 			hasSurrendered: boolean;
    69              Teams: array[0..Pred(cMaxTeams)] of PTeam;
    69 			end;
    70              TeamsNumber: Longword;
    70 			
    71              CurrTeam: LongWord;
    71 	TClan = record
    72              ClanHealth: LongInt;
    72 			Color: Longword;
    73              ClanIndex: LongInt;
    73 			Teams: array[0..Pred(cMaxTeams)] of PTeam;
    74              TurnNumber: LongWord;
    74 			TeamsNumber: Longword;
    75              end;
    75 			CurrTeam: LongWord;
       
    76 			ClanHealth: LongInt;
       
    77 			ClanIndex: LongInt;
       
    78 			TurnNumber: LongWord;
       
    79 			end;
    76 
    80 
    77 var CurrentTeam: PTeam = nil;
    81 var CurrentTeam: PTeam = nil;
    78     CurrentHedgehog: PHedgehog = nil;
    82 	CurrentHedgehog: PHedgehog = nil;
    79     TeamsArray: array[0..Pred(cMaxTeams)] of PTeam;
    83 	TeamsArray: array[0..Pred(cMaxTeams)] of PTeam;
    80     TeamsCount: Longword = 0;
    84 	TeamsCount: Longword = 0;
    81     ClansArray: array[0..Pred(cMaxTeams)] of PClan;
    85 	ClansArray: array[0..Pred(cMaxTeams)] of PClan;
    82     ClansCount: Longword = 0;
    86 	ClansCount: Longword = 0;
    83     CurMinAngle, CurMaxAngle: Longword;
    87 	CurMinAngle, CurMaxAngle: Longword;
    84 
    88 
    85 function  AddTeam(TeamColor: Longword): PTeam;
    89 function  AddTeam(TeamColor: Longword): PTeam;
    86 procedure SwitchHedgehog;
    90 procedure SwitchHedgehog;
    87 procedure AfterSwitchHedgehog;
    91 procedure AfterSwitchHedgehog;
    88 procedure InitTeams;
    92 procedure InitTeams;
   102     s: shortstring;
   106     s: shortstring;
   103     t, AliveCount, i, j: LongInt;
   107     t, AliveCount, i, j: LongInt;
   104 begin
   108 begin
   105 AliveCount:= 0;
   109 AliveCount:= 0;
   106 for t:= 0 to Pred(ClansCount) do
   110 for t:= 0 to Pred(ClansCount) do
   107     if ClansArray[t]^.ClanHealth > 0 then
   111 	if ClansArray[t]^.ClanHealth > 0 then
   108        begin
   112 		begin
   109        inc(AliveCount);
   113 		inc(AliveCount);
   110        AliveClan:= ClansArray[t]
   114 		AliveClan:= ClansArray[t]
   111        end;
   115 		end;
   112 
   116 
   113 if  (AliveCount > 1) or
   117 if (AliveCount > 1)
   114    ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false);
   118 or ((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false);
   115 CheckForWin:= true;
   119 CheckForWin:= true;
   116 
   120 
   117 TurnTimeLeft:= 0;
   121 TurnTimeLeft:= 0;
   118 if AliveCount = 0 then
   122 if AliveCount = 0 then
   119 	begin // draw
   123 	begin // draw
   149 FreeActionsList;
   153 FreeActionsList;
   150 TargetPoint.X:= NoPointX;
   154 TargetPoint.X:= NoPointX;
   151 TryDo(CurrentTeam <> nil, 'nil Team', true);
   155 TryDo(CurrentTeam <> nil, 'nil Team', true);
   152 
   156 
   153 with CurrentHedgehog^ do
   157 with CurrentHedgehog^ do
   154      if Gear <> nil then
   158 	if Gear <> nil then
   155         begin
   159 		begin
   156         AttacksNum:= 0;
   160 		AttacksNum:= 0;
   157         Gear^.Message:= 0;
   161 		Gear^.Message:= 0;
   158         Gear^.Z:= cHHZ;
   162 		Gear^.Z:= cHHZ;
   159         RemoveGearFromList(Gear);
   163 		RemoveGearFromList(Gear);
   160         InsertGearToList(Gear)
   164 		InsertGearToList(Gear)
   161         end;
   165 		end;
   162 
   166 
   163 c:= CurrentTeam^.Clan^.ClanIndex;
   167 c:= CurrentTeam^.Clan^.ClanIndex;
   164 repeat
   168 repeat
   165 	inc(c);
   169 	inc(c);
   166 	if c = ClansCount then
   170 	if c = ClansCount then
   178 				begin
   182 				begin
   179 				PrevHH:= CurrHedgehog;
   183 				PrevHH:= CurrHedgehog;
   180 				repeat
   184 				repeat
   181 					CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber;
   185 					CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber;
   182 				until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH)
   186 				until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH)
   183 			end
   187 				end
   184 		until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam);
   188 		until ((CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) and (not CurrentTeam^.hasSurrendered)) or (PrevTeam = CurrTeam);
   185 until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil;
   189 until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil;
   186 
   190 
   187 CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog])
   191 CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog])
   188 end;
   192 end;
   189 
   193 
   190 procedure AfterSwitchHedgehog;
   194 procedure AfterSwitchHedgehog;
   191 var g: PGear;
   195 var g: PGear;
   192 begin
   196 begin
   193 SwitchNotHoldedAmmo(CurrentHedgehog^);
   197 SwitchNotHoldedAmmo(CurrentHedgehog^);
   194 with CurrentHedgehog^ do
   198 with CurrentHedgehog^ do
   195      begin
   199 	begin
   196      with Gear^ do
   200 	with Gear^ do
   197           begin
   201 		begin
   198           Z:= cCurrHHZ;
   202 		Z:= cCurrHHZ;
   199           State:= gstHHDriven;
   203 		State:= gstHHDriven;
   200           Active:= true
   204 		Active:= true
   201           end;
   205 		end;
   202      RemoveGearFromList(Gear);
   206 	RemoveGearFromList(Gear);
   203      InsertGearToList(Gear);
   207 	InsertGearToList(Gear);
   204      FollowGear:= Gear
   208 	FollowGear:= Gear
   205      end;
   209 	end;
   206 
   210 
   207 inc(CurrentTeam^.Clan^.TurnNumber);
   211 inc(CurrentTeam^.Clan^.TurnNumber);
   208 
   212 
   209 ResetKbd;
   213 ResetKbd;
   210 
   214 
   217 if CurrentTeam^.ExtDriven then SetDefaultBinds
   221 if CurrentTeam^.ExtDriven then SetDefaultBinds
   218                           else SetBinds(CurrentTeam^.Binds);
   222                           else SetBinds(CurrentTeam^.Binds);
   219 bShowFinger:= true;
   223 bShowFinger:= true;
   220 
   224 
   221 if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then
   225 if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then
   222    PlaySound(sndIllGetYou, false)
   226 	PlaySound(sndIllGetYou, false)
   223 else
   227 else
   224    PlaySound(sndYesSir, false);
   228 	PlaySound(sndYesSir, false);
   225 
   229 
   226 TurnTimeLeft:= cHedgehogTurnTime
   230 TurnTimeLeft:= cHedgehogTurnTime
   227 end;
   231 end;
   228 
   232 
   229 function AddTeam(TeamColor: Longword): PTeam;
   233 function AddTeam(TeamColor: Longword): PTeam;