author | unc0rr |
Sat, 24 May 2008 17:34:06 +0000 | |
changeset 945 | 4ead9cde4e14 |
parent 944 | 9299c0ebfdbc |
child 971 | d2c49b730771 |
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; |
941
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
71 |
TurnNumber: LongWord; |
549 | 72 |
end; |
4 | 73 |
|
74 |
var CurrentTeam: PTeam = nil; |
|
602 | 75 |
CurrentHedgehog: PHedgehog = nil; |
547 | 76 |
TeamsArray: array[0..Pred(cMaxTeams)] of PTeam; |
77 |
TeamsCount: Longword = 0; |
|
549 | 78 |
ClansArray: array[0..Pred(cMaxTeams)] of PClan; |
79 |
ClansCount: Longword = 0; |
|
304 | 80 |
CurMinAngle, CurMaxAngle: Longword; |
4 | 81 |
|
549 | 82 |
function AddTeam(TeamColor: Longword): PTeam; |
4 | 83 |
procedure SwitchHedgehog; |
84 |
procedure InitTeams; |
|
85 |
function TeamSize(p: PTeam): Longword; |
|
47 | 86 |
procedure RecountTeamHealth(team: PTeam); |
72 | 87 |
procedure RestoreTeamsFromSave; |
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
88 |
function CheckForWin: boolean; |
4 | 89 |
|
90 |
implementation |
|
800 | 91 |
uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uSound; |
371 | 92 |
const MaxTeamHealth: LongInt = 0; |
4 | 93 |
|
94 |
procedure FreeTeamsList; forward; |
|
95 |
||
92
0c359a7a2356
- Fix win message to appear only after all hedgehogs death
unc0rr
parents:
89
diff
changeset
|
96 |
function CheckForWin: boolean; |
576 | 97 |
var AliveClan: PClan; |
306 | 98 |
s: shortstring; |
548 | 99 |
t, AliveCount: LongInt; |
83 | 100 |
begin |
548 | 101 |
AliveCount:= 0; |
549 | 102 |
for t:= 0 to Pred(ClansCount) do |
103 |
if ClansArray[t]^.ClanHealth > 0 then |
|
548 | 104 |
begin |
105 |
inc(AliveCount); |
|
549 | 106 |
AliveClan:= ClansArray[t] |
548 | 107 |
end; |
108 |
||
601
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
576
diff
changeset
|
109 |
if (AliveCount > 1) or |
78a68cc4d846
Special game mode allowing the only clan on map for training mode
unc0rr
parents:
576
diff
changeset
|
110 |
((AliveCount = 1) and ((GameFlags and gfOneClanMode) <> 0)) then exit(false); |
351 | 111 |
CheckForWin:= true; |
83 | 112 |
|
113 |
TurnTimeLeft:= 0; |
|
548 | 114 |
if AliveCount = 0 then |
83 | 115 |
begin // draw |
116 |
AddCaption(trmsg[sidDraw], $FFFFFF, capgrpGameState); |
|
306 | 117 |
SendStat(siGameResult, trmsg[sidDraw]); |
498 | 118 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000) |
83 | 119 |
end else // win |
549 | 120 |
with AliveClan^ do |
121 |
begin |
|
122 |
if TeamsNumber = 1 then |
|
123 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName) // team wins |
|
124 |
else |
|
125 |
s:= Format(trmsg[sidWinner], Teams[0]^.TeamName); // clan wins |
|
126 |
||
127 |
AddCaption(s, $FFFFFF, capgrpGameState); |
|
128 |
SendStat(siGameResult, s); |
|
129 |
AddGear(0, 0, gtATFinishGame, 0, _0, _0, 2000) |
|
130 |
end; |
|
307 | 131 |
SendStats |
83 | 132 |
end; |
133 |
||
4 | 134 |
procedure SwitchHedgehog; |
551 | 135 |
var c: LongWord; |
351 | 136 |
g: PGear; |
552 | 137 |
PrevHH, PrevTeam: LongWord; |
4 | 138 |
begin |
139 |
FreeActionsList; |
|
140 |
TargetPoint.X:= NoPointX; |
|
89 | 141 |
TryDo(CurrentTeam <> nil, 'nil Team', true); |
547 | 142 |
|
944 | 143 |
with CurrentHedgehog^ do |
294 | 144 |
if Gear <> nil then |
145 |
begin |
|
540 | 146 |
AttacksNum:= 0; |
351 | 147 |
Gear^.Message:= 0; |
534 | 148 |
Gear^.Z:= cHHZ; |
944 | 149 |
SwitchNotHoldedAmmo(CurrentHedgehog^); |
534 | 150 |
RemoveGearFromList(Gear); |
151 |
InsertGearToList(Gear) |
|
294 | 152 |
end; |
4 | 153 |
|
550 | 154 |
c:= CurrentTeam^.Clan^.ClanIndex; |
4 | 155 |
repeat |
550 | 156 |
c:= Succ(c) mod ClansCount; |
157 |
with ClansArray[c]^ do |
|
158 |
repeat |
|
552 | 159 |
PrevTeam:= CurrTeam; |
550 | 160 |
CurrTeam:= Succ(CurrTeam) mod TeamsNumber; |
161 |
CurrentTeam:= Teams[CurrTeam]; |
|
162 |
with CurrentTeam^ do |
|
552 | 163 |
begin |
164 |
PrevHH:= CurrHedgehog; |
|
550 | 165 |
repeat |
552 | 166 |
CurrHedgehog:= Succ(CurrHedgehog) mod HedgehogsNumber; |
167 |
until (Hedgehogs[CurrHedgehog].Gear <> nil) or (CurrHedgehog = PrevHH) |
|
168 |
end |
|
169 |
until (CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil) or (PrevTeam = CurrTeam); |
|
550 | 170 |
until CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog].Gear <> nil; |
83 | 171 |
|
602 | 172 |
CurrentHedgehog:= @(CurrentTeam^.Hedgehogs[CurrentTeam^.CurrHedgehog]); |
944 | 173 |
SwitchNotHoldedAmmo(CurrentHedgehog^); |
602 | 174 |
with CurrentHedgehog^ do |
4 | 175 |
begin |
176 |
with Gear^ do |
|
177 |
begin |
|
294 | 178 |
Z:= cCurrHHZ; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
17
diff
changeset
|
179 |
State:= gstHHDriven; |
4 | 180 |
Active:= true |
181 |
end; |
|
294 | 182 |
RemoveGearFromList(Gear); |
183 |
InsertGearToList(Gear); |
|
4 | 184 |
FollowGear:= Gear |
185 |
end; |
|
941
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
186 |
|
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
187 |
inc(CurrentTeam^.Clan^.TurnNumber); |
b5222ddafe1f
- Fix bug with picking up ammos from cases, when total ammo count may become more than AMMO_INFINITE
unc0rr
parents:
927
diff
changeset
|
188 |
|
4 | 189 |
ResetKbd; |
351 | 190 |
|
191 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 192 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 193 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 194 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 195 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 196 |
|
351 | 197 |
if CurrentTeam^.ExtDriven then SetDefaultBinds |
198 |
else SetBinds(CurrentTeam^.Binds); |
|
176 | 199 |
bShowFinger:= true; |
800 | 200 |
|
801 | 201 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
202 |
PlaySound(sndIllGetYou, false) |
|
203 |
else |
|
204 |
PlaySound(sndYesSir, false); |
|
800 | 205 |
|
4 | 206 |
TurnTimeLeft:= cHedgehogTurnTime |
207 |
end; |
|
208 |
||
549 | 209 |
function AddTeam(TeamColor: Longword): PTeam; |
351 | 210 |
var Result: PTeam; |
549 | 211 |
c: LongInt; |
4 | 212 |
begin |
547 | 213 |
TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true); |
17 | 214 |
New(Result); |
80 | 215 |
TryDo(Result <> nil, 'AddTeam: Result = nil', true); |
4 | 216 |
FillChar(Result^, sizeof(TTeam), 0); |
351 | 217 |
Result^.AttackBar:= 2; |
218 |
Result^.CurrHedgehog:= cMaxHHIndex; |
|
547 | 219 |
|
220 |
TeamsArray[TeamsCount]:= Result; |
|
221 |
inc(TeamsCount); |
|
222 |
||
549 | 223 |
c:= Pred(ClansCount); |
224 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
225 |
if c < 0 then |
|
226 |
begin |
|
227 |
new(Result^.Clan); |
|
228 |
FillChar(Result^.Clan^, sizeof(TClan), 0); |
|
229 |
ClansArray[ClansCount]:= Result^.Clan; |
|
230 |
inc(ClansCount); |
|
231 |
with Result^.Clan^ do |
|
232 |
begin |
|
550 | 233 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
234 |
Color:= TeamColor |
549 | 235 |
end |
236 |
end else |
|
237 |
begin |
|
238 |
Result^.Clan:= ClansArray[c]; |
|
239 |
end; |
|
240 |
||
241 |
with Result^.Clan^ do |
|
242 |
begin |
|
243 |
Teams[TeamsNumber]:= Result; |
|
244 |
inc(TeamsNumber) |
|
245 |
end; |
|
246 |
||
351 | 247 |
CurrentTeam:= Result; |
248 |
AddTeam:= Result |
|
4 | 249 |
end; |
250 |
||
251 |
procedure FreeTeamsList; |
|
547 | 252 |
var t: LongInt; |
4 | 253 |
begin |
547 | 254 |
for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]); |
255 |
TeamsCount:= 0 |
|
4 | 256 |
end; |
257 |
||
47 | 258 |
procedure RecountAllTeamsHealth; |
547 | 259 |
var t: LongInt; |
260 |
begin |
|
261 |
for t:= 0 to Pred(TeamsCount) do |
|
262 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 263 |
end; |
264 |
||
265 |
procedure InitTeams; |
|
547 | 266 |
var i, t: LongInt; |
371 | 267 |
th: LongInt; |
47 | 268 |
begin |
547 | 269 |
for t:= 0 to Pred(TeamsCount) do |
270 |
with TeamsArray[t]^ do |
|
47 | 271 |
begin |
272 |
th:= 0; |
|
4 | 273 |
for i:= 0 to cMaxHHIndex do |
547 | 274 |
if Hedgehogs[i].Gear <> nil then |
275 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 276 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 277 |
end; |
47 | 278 |
RecountAllTeamsHealth |
4 | 279 |
end; |
280 |
||
281 |
function TeamSize(p: PTeam): Longword; |
|
351 | 282 |
var i, Result: Longword; |
4 | 283 |
begin |
284 |
Result:= 0; |
|
285 |
for i:= 0 to cMaxHHIndex do |
|
351 | 286 |
if p^.Hedgehogs[i].Gear <> nil then inc(Result); |
287 |
TeamSize:= Result |
|
4 | 288 |
end; |
289 |
||
549 | 290 |
procedure RecountClanHealth(clan: PClan); |
291 |
var i: LongInt; |
|
292 |
begin |
|
293 |
with clan^ do |
|
294 |
begin |
|
295 |
ClanHealth:= 0; |
|
296 |
for i:= 0 to Pred(TeamsNumber) do |
|
297 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
298 |
end |
|
299 |
end; |
|
300 |
||
47 | 301 |
procedure RecountTeamHealth(team: PTeam); |
371 | 302 |
var i: LongInt; |
47 | 303 |
begin |
304 |
with team^ do |
|
305 |
begin |
|
557 | 306 |
NewTeamHealthBarWidth:= 0; |
47 | 307 |
for i:= 0 to cMaxHHIndex do |
308 |
if Hedgehogs[i].Gear <> nil then |
|
557 | 309 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
310 |
TeamHealth:= NewTeamHealthBarWidth; |
|
311 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
|
47 | 312 |
begin |
557 | 313 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
47 | 314 |
RecountAllTeamsHealth; |
557 | 315 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
49 | 316 |
end; |
549 | 317 |
|
318 |
RecountClanHealth(team^.Clan); |
|
319 |
||
498 | 320 |
AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0) |
47 | 321 |
end; |
322 |
||
72 | 323 |
procedure RestoreTeamsFromSave; |
547 | 324 |
var t: LongInt; |
72 | 325 |
begin |
547 | 326 |
for t:= 0 to Pred(TeamsCount) do |
327 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 328 |
end; |
329 |
||
4 | 330 |
initialization |
331 |
||
332 |
finalization |
|
333 |
||
334 |
FreeTeamsList |
|
335 |
||
336 |
end. |