author | unc0rr |
Wed, 14 May 2008 14:13:18 +0000 | |
changeset 931 | ab4d98858a40 |
parent 927 | 2c1675344a6f |
child 941 | b5222ddafe1f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
19 |
unit uTeams; |
|
20 |
interface |
|
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
801
diff
changeset
|
21 |
uses SDLh, uConsts, uKeys, uGears, uRandom, uFloat, uStats; |
4 | 22 |
{$INCLUDE options.inc} |
534 | 23 |
|
24 |
type PHHAmmo = ^THHAmmo; |
|
25 |
THHAmmo = array[0..cMaxSlotIndex, 0..cMaxSlotAmmoIndex] of TAmmo; |
|
26 |
||
4 | 27 |
type PHedgehog = ^THedgehog; |
28 |
PTeam = ^TTeam; |
|
549 | 29 |
PClan = ^TClan; |
4 | 30 |
THedgehog = record |
74 | 31 |
Name: string[MAXNAMELEN]; |
4 | 32 |
Gear: PGear; |
762 | 33 |
NameTagTex: PTexture; |
34 |
HealthTagTex: PTexture; |
|
4 | 35 |
Ammo: PHHAmmo; |
288 | 36 |
AmmoStore: Longword; |
4 | 37 |
CurSlot, CurAmmo: LongWord; |
38 |
Team: PTeam; |
|
39 |
AttacksNum: Longword; |
|
40 |
visStepPos: LongWord; |
|
5 | 41 |
BotLevel : LongWord; // 0 - Human player |
814
7fb4417b7bc1
Start implementing better statistics implementation (does nothing yet)
unc0rr
parents:
801
diff
changeset
|
42 |
stats: TStatistics; |
4 | 43 |
end; |
44 |
TTeam = record |
|
549 | 45 |
Clan: PClan; |
74 | 46 |
TeamName: string[MAXNAMELEN]; |
4 | 47 |
ExtDriven: boolean; |
167 | 48 |
Binds: TBinds; |
4 | 49 |
Hedgehogs: array[0..cMaxHHIndex] of THedgehog; |
551 | 50 |
CurrHedgehog: LongWord; |
762 | 51 |
NameTagTex: PTexture; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
52 |
CrosshairTex, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
53 |
GraveTex, |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
54 |
HealthTex: PTexture; |
4 | 55 |
GraveName: string; |
56 |
FortName: string; |
|
371 | 57 |
TeamHealth: LongInt; |
557 | 58 |
TeamHealthBarWidth, |
59 |
NewTeamHealthBarWidth: LongInt; |
|
371 | 60 |
DrawHealthY: LongInt; |
4 | 61 |
AttackBar: LongWord; |
550 | 62 |
HedgehogsNumber: Longword; |
4 | 63 |
end; |
549 | 64 |
TClan = record |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
65 |
Color: Longword; |
549 | 66 |
Teams: array[0..Pred(cMaxTeams)] of PTeam; |
67 |
TeamsNumber: Longword; |
|
551 | 68 |
CurrTeam: LongWord; |
549 | 69 |
ClanHealth: LongInt; |
550 | 70 |
ClanIndex: LongInt; |
549 | 71 |
end; |
4 | 72 |
|
73 |
var CurrentTeam: PTeam = nil; |
|
602 | 74 |
CurrentHedgehog: PHedgehog = nil; |
547 | 75 |
TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; |
76 |
TeamsCount: Longword = 0; |
|
549 | 77 |
ClansArray: array[0..Pred(cMaxTeams)] of PClan; |
78 |
ClansCount: Longword = 0; |
|
304 | 79 |
CurMinAngle, CurMaxAngle: Longword; |
4 | 80 |
|
549 | 81 |
function AddTeam(TeamColor: Longword): PTeam; |
4 | 82 |
procedure SwitchHedgehog; |
83 |
procedure InitTeams; |
|
84 |
function TeamSize(p: PTeam): Longword; |
|
47 | 85 |
procedure RecountTeamHealth(team: PTeam); |
72 | 86 |
procedure RestoreTeamsFromSave; |
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
87 |
function CheckForWin: boolean; |
4 | 88 |
|
89 |
implementation |
|
800 | 90 |
uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uSound; |
371 | 91 |
const MaxTeamHealth: LongInt = 0; |
4 | 92 |
|
93 |
procedure FreeTeamsList; forward; |
|
94 |
||
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
95 |
function CheckForWin: boolean; |
576 | 96 |
var AliveClan: PClan; |
306 | 97 |
s: shortstring; |
548 | 98 |
t, AliveCount: LongInt; |
83 | 99 |
begin |
548 | 100 |
AliveCount:= 0; |
549 | 101 |
for t:= 0 to Pred(ClansCount) do |
102 |
if ClansArray[t]^.ClanHealth > 0 then |
|
548 | 103 |
begin |
104 |
inc(AliveCount); |
|
549 | 105 |
AliveClan:= ClansArray[t] |
548 | 106 |
end; |
107 |
||
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
576
diff
changeset
|
108 |
if (AliveCount > 1) or |
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
576
diff
changeset
|
109 |
((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false); |
351 | 110 |
CheckForWin:= true; |
83 | 111 |
|
112 |
TurnTimeLeft:= 0; |
|
548 | 113 |
if AliveCount = 0 then |
83 | 114 |
begin // draw |
115 |
AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState); |
|
306 | 116 |
SendStat(siGameResult, trmsg[sidDraw]); |
498 | 117 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000) |
83 | 118 |
end else // win |
549 | 119 |
with AliveClan^ do |
120 |
begin |
|
121 |
if TeamsNumber = 1 then |
|
122 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName) // team wins |
|
123 |
else |
|
124 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName); // clan wins |
|
125 |
||
126 |
AddCaption(s, $FFFFFF, capgrpGameState); |
|
127 |
SendStat(siGameResult, s); |
|
128 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000) |
|
129 |
end; |
|
307 | 130 |
SendStats |
83 | 131 |
end; |
132 |
||
4 | 133 |
procedure SwitchHedgehog; |
551 | 134 |
var c: LongWord; |
351 | 135 |
g: PGear; |
552 | 136 |
PrevHH, PrevTeam: LongWord; |
4 | 137 |
begin |
138 |
FreeActionsList; |
|
139 |
TargetPoint.X:= NoPointX; |
|
89 | 140 |
TryDo(CurrentTeam <> nil, 'nil Team', true); |
547 | 141 |
|
351 | 142 |
with CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog] do |
294 | 143 |
if Gear <> nil then |
144 |
begin |
|
540 | 145 |
AttacksNum:= 0; |
351 | 146 |
Gear^.Message:= 0; |
534 | 147 |
Gear^.Z:= cHHZ; |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
552
diff
changeset
|
148 |
SwitchNotHoldedAmmo(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
534 | 149 |
RemoveGearFromList(Gear); |
150 |
InsertGearToList(Gear) |
|
294 | 151 |
end; |
4 | 152 |
|
550 | 153 |
c:= CurrentTeam^.Clan^.ClanIndex; |
4 | 154 |
repeat |
550 | 155 |
c:= Succ(c) mod ClansCount; |
156 |
with ClansArray[c]^ do |
|
157 |
repeat |
|
552 | 158 |
PrevTeam:= CurrTeam; |
550 | 159 |
CurrTeam:= Succ(CurrTeam) mod TeamsNumber; |
160 |
CurrentTeam:= Teams[CurrTeam]; |
|
161 |
with CurrentTeam^ do |
|
552 | 162 |
begin |
163 |
PrevHH:= CurrHedgehog; |
|
550 | 164 |
repeat |
552 | 165 |
CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber; |
166 |
until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH) |
|
167 |
end |
|
168 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam); |
|
550 | 169 |
until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil; |
83 | 170 |
|
602 | 171 |
CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
172 |
with CurrentHedgehog^ do |
|
4 | 173 |
begin |
174 |
with Gear^ do |
|
175 |
begin |
|
294 | 176 |
Z:= cCurrHHZ; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
17
diff
changeset
|
177 |
State:= gstHHDriven; |
4 | 178 |
Active:= true |
179 |
end; |
|
294 | 180 |
RemoveGearFromList(Gear); |
181 |
InsertGearToList(Gear); |
|
4 | 182 |
FollowGear:= Gear |
183 |
end; |
|
184 |
ResetKbd; |
|
351 | 185 |
|
186 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 187 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 188 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 189 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 190 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 191 |
|
351 | 192 |
if CurrentTeam^.ExtDriven then SetDefaultBinds |
193 |
else SetBinds(CurrentTeam^.Binds); |
|
176 | 194 |
bShowFinger:= true; |
800 | 195 |
|
801 | 196 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
197 |
PlaySound(sndIllGetYou, false) |
|
198 |
else |
|
199 |
PlaySound(sndYesSir, false); |
|
800 | 200 |
|
4 | 201 |
TurnTimeLeft:= cHedgehogTurnTime |
202 |
end; |
|
203 |
||
549 | 204 |
function AddTeam(TeamColor: Longword): PTeam; |
351 | 205 |
var Result: PTeam; |
549 | 206 |
c: LongInt; |
4 | 207 |
begin |
547 | 208 |
TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true); |
17 | 209 |
New(Result); |
80 | 210 |
TryDo(Result <> nil, 'AddTeam: Result = nil', true); |
4 | 211 |
FillChar(Result^, sizeof(TTeam), 0); |
351 | 212 |
Result^.AttackBar:= 2; |
213 |
Result^.CurrHedgehog:= cMaxHHIndex; |
|
547 | 214 |
|
215 |
TeamsArray[TeamsCount]:= Result; |
|
216 |
inc(TeamsCount); |
|
217 |
||
549 | 218 |
c:= Pred(ClansCount); |
219 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
220 |
if c < 0 then |
|
221 |
begin |
|
222 |
new(Result^.Clan); |
|
223 |
FillChar(Result^.Clan^, sizeof(TClan), 0); |
|
224 |
ClansArray[ClansCount]:= Result^.Clan; |
|
225 |
inc(ClansCount); |
|
226 |
with Result^.Clan^ do |
|
227 |
begin |
|
550 | 228 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
229 |
Color:= TeamColor |
549 | 230 |
end |
231 |
end else |
|
232 |
begin |
|
233 |
Result^.Clan:= ClansArray[c]; |
|
234 |
end; |
|
235 |
||
236 |
with Result^.Clan^ do |
|
237 |
begin |
|
238 |
Teams[TeamsNumber]:= Result; |
|
239 |
inc(TeamsNumber) |
|
240 |
end; |
|
241 |
||
351 | 242 |
CurrentTeam:= Result; |
243 |
AddTeam:= Result |
|
4 | 244 |
end; |
245 |
||
246 |
procedure FreeTeamsList; |
|
547 | 247 |
var t: LongInt; |
4 | 248 |
begin |
547 | 249 |
for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]); |
250 |
TeamsCount:= 0 |
|
4 | 251 |
end; |
252 |
||
47 | 253 |
procedure RecountAllTeamsHealth; |
547 | 254 |
var t: LongInt; |
255 |
begin |
|
256 |
for t:= 0 to Pred(TeamsCount) do |
|
257 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 258 |
end; |
259 |
||
260 |
procedure InitTeams; |
|
547 | 261 |
var i, t: LongInt; |
371 | 262 |
th: LongInt; |
47 | 263 |
begin |
547 | 264 |
for t:= 0 to Pred(TeamsCount) do |
265 |
with TeamsArray[t]^ do |
|
47 | 266 |
begin |
267 |
th:= 0; |
|
4 | 268 |
for i:= 0 to cMaxHHIndex do |
547 | 269 |
if Hedgehogs[i].Gear <> nil then |
270 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 271 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 272 |
end; |
47 | 273 |
RecountAllTeamsHealth |
4 | 274 |
end; |
275 |
||
276 |
function TeamSize(p: PTeam): Longword; |
|
351 | 277 |
var i, Result: Longword; |
4 | 278 |
begin |
279 |
Result:= 0; |
|
280 |
for i:= 0 to cMaxHHIndex do |
|
351 | 281 |
if p^.Hedgehogs[i].Gear <> nil then inc(Result); |
282 |
TeamSize:= Result |
|
4 | 283 |
end; |
284 |
||
549 | 285 |
procedure RecountClanHealth(clan: PClan); |
286 |
var i: LongInt; |
|
287 |
begin |
|
288 |
with clan^ do |
|
289 |
begin |
|
290 |
ClanHealth:= 0; |
|
291 |
for i:= 0 to Pred(TeamsNumber) do |
|
292 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
293 |
end |
|
294 |
end; |
|
295 |
||
47 | 296 |
procedure RecountTeamHealth(team: PTeam); |
371 | 297 |
var i: LongInt; |
47 | 298 |
begin |
299 |
with team^ do |
|
300 |
begin |
|
557 | 301 |
NewTeamHealthBarWidth:= 0; |
47 | 302 |
for i:= 0 to cMaxHHIndex do |
303 |
if Hedgehogs[i].Gear <> nil then |
|
557 | 304 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
305 |
TeamHealth:= NewTeamHealthBarWidth; |
|
306 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
|
47 | 307 |
begin |
557 | 308 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
47 | 309 |
RecountAllTeamsHealth; |
557 | 310 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
49 | 311 |
end; |
549 | 312 |
|
313 |
RecountClanHealth(team^.Clan); |
|
314 |
||
498 | 315 |
AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0) |
47 | 316 |
end; |
317 |
||
72 | 318 |
procedure RestoreTeamsFromSave; |
547 | 319 |
var t: LongInt; |
72 | 320 |
begin |
547 | 321 |
for t:= 0 to Pred(TeamsCount) do |
322 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 323 |
end; |
324 |
||
4 | 325 |
initialization |
326 |
||
327 |
finalization |
|
328 |
||
329 |
FreeTeamsList |
|
330 |
||
331 |
end. |