author | unc0rr |
Tue, 17 Jun 2008 21:28:15 +0000 | |
changeset 1005 | 9d2e8f3a4fa6 |
parent 971 | d2c49b730771 |
child 1011 | 4fe2c4c57d10 |
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; |
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]); |
944 | 172 |
SwitchNotHoldedAmmo(CurrentHedgehog^); |
602 | 173 |
with CurrentHedgehog^ do |
4 | 174 |
begin |
175 |
with Gear^ do |
|
176 |
begin |
|
294 | 177 |
Z:= cCurrHHZ; |
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
17
diff
changeset
|
178 |
State:= gstHHDriven; |
4 | 179 |
Active:= true |
180 |
end; |
|
294 | 181 |
RemoveGearFromList(Gear); |
182 |
InsertGearToList(Gear); |
|
4 | 183 |
FollowGear:= Gear |
184 |
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
|
185 |
|
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 |
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
|
187 |
|
4 | 188 |
ResetKbd; |
351 | 189 |
|
190 |
cWindSpeed:= rndSign(GetRandom * cMaxWindSpeed); |
|
498 | 191 |
g:= AddGear(0, 0, gtATSmoothWindCh, 0, _0, _0, 1); |
351 | 192 |
g^.Tag:= hwRound(cWindSpeed * 72 / cMaxWindSpeed); |
4 | 193 |
{$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF} |
602 | 194 |
ApplyAmmoChanges(CurrentHedgehog^); |
800 | 195 |
|
351 | 196 |
if CurrentTeam^.ExtDriven then SetDefaultBinds |
197 |
else SetBinds(CurrentTeam^.Binds); |
|
176 | 198 |
bShowFinger:= true; |
800 | 199 |
|
801 | 200 |
if (CurrentTeam^.ExtDriven or (CurrentHedgehog^.BotLevel > 0)) then |
201 |
PlaySound(sndIllGetYou, false) |
|
202 |
else |
|
203 |
PlaySound(sndYesSir, false); |
|
800 | 204 |
|
4 | 205 |
TurnTimeLeft:= cHedgehogTurnTime |
206 |
end; |
|
207 |
||
549 | 208 |
function AddTeam(TeamColor: Longword): PTeam; |
351 | 209 |
var Result: PTeam; |
549 | 210 |
c: LongInt; |
4 | 211 |
begin |
547 | 212 |
TryDo(TeamsCount <= cMaxTeams, 'Too many teams', true); |
17 | 213 |
New(Result); |
80 | 214 |
TryDo(Result <> nil, 'AddTeam: Result = nil', true); |
4 | 215 |
FillChar(Result^, sizeof(TTeam), 0); |
351 | 216 |
Result^.AttackBar:= 2; |
217 |
Result^.CurrHedgehog:= cMaxHHIndex; |
|
547 | 218 |
|
219 |
TeamsArray[TeamsCount]:= Result; |
|
220 |
inc(TeamsCount); |
|
221 |
||
549 | 222 |
c:= Pred(ClansCount); |
223 |
while (c >= 0) and (ClansArray[c]^.Color <> TeamColor) do dec(c); |
|
224 |
if c < 0 then |
|
225 |
begin |
|
226 |
new(Result^.Clan); |
|
227 |
FillChar(Result^.Clan^, sizeof(TClan), 0); |
|
228 |
ClansArray[ClansCount]:= Result^.Clan; |
|
229 |
inc(ClansCount); |
|
230 |
with Result^.Clan^ do |
|
231 |
begin |
|
550 | 232 |
ClanIndex:= Pred(ClansCount); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
233 |
Color:= TeamColor |
549 | 234 |
end |
235 |
end else |
|
236 |
begin |
|
237 |
Result^.Clan:= ClansArray[c]; |
|
238 |
end; |
|
239 |
||
240 |
with Result^.Clan^ do |
|
241 |
begin |
|
242 |
Teams[TeamsNumber]:= Result; |
|
243 |
inc(TeamsNumber) |
|
244 |
end; |
|
245 |
||
351 | 246 |
CurrentTeam:= Result; |
247 |
AddTeam:= Result |
|
4 | 248 |
end; |
249 |
||
250 |
procedure FreeTeamsList; |
|
547 | 251 |
var t: LongInt; |
4 | 252 |
begin |
547 | 253 |
for t:= 0 to Pred(TeamsCount) do Dispose(TeamsArray[t]); |
254 |
TeamsCount:= 0 |
|
4 | 255 |
end; |
256 |
||
47 | 257 |
procedure RecountAllTeamsHealth; |
547 | 258 |
var t: LongInt; |
259 |
begin |
|
260 |
for t:= 0 to Pred(TeamsCount) do |
|
261 |
RecountTeamHealth(TeamsArray[t]) |
|
47 | 262 |
end; |
263 |
||
264 |
procedure InitTeams; |
|
547 | 265 |
var i, t: LongInt; |
371 | 266 |
th: LongInt; |
47 | 267 |
begin |
547 | 268 |
for t:= 0 to Pred(TeamsCount) do |
269 |
with TeamsArray[t]^ do |
|
47 | 270 |
begin |
271 |
th:= 0; |
|
4 | 272 |
for i:= 0 to cMaxHHIndex do |
547 | 273 |
if Hedgehogs[i].Gear <> nil then |
274 |
inc(th, Hedgehogs[i].Gear^.Health); |
|
47 | 275 |
if th > MaxTeamHealth then MaxTeamHealth:= th; |
4 | 276 |
end; |
47 | 277 |
RecountAllTeamsHealth |
4 | 278 |
end; |
279 |
||
280 |
function TeamSize(p: PTeam): Longword; |
|
351 | 281 |
var i, Result: Longword; |
4 | 282 |
begin |
283 |
Result:= 0; |
|
284 |
for i:= 0 to cMaxHHIndex do |
|
351 | 285 |
if p^.Hedgehogs[i].Gear <> nil then inc(Result); |
286 |
TeamSize:= Result |
|
4 | 287 |
end; |
288 |
||
549 | 289 |
procedure RecountClanHealth(clan: PClan); |
290 |
var i: LongInt; |
|
291 |
begin |
|
292 |
with clan^ do |
|
293 |
begin |
|
294 |
ClanHealth:= 0; |
|
295 |
for i:= 0 to Pred(TeamsNumber) do |
|
296 |
inc(ClanHealth, Teams[i]^.TeamHealth) |
|
297 |
end |
|
298 |
end; |
|
299 |
||
47 | 300 |
procedure RecountTeamHealth(team: PTeam); |
371 | 301 |
var i: LongInt; |
47 | 302 |
begin |
303 |
with team^ do |
|
304 |
begin |
|
557 | 305 |
NewTeamHealthBarWidth:= 0; |
47 | 306 |
for i:= 0 to cMaxHHIndex do |
307 |
if Hedgehogs[i].Gear <> nil then |
|
557 | 308 |
inc(NewTeamHealthBarWidth, Hedgehogs[i].Gear^.Health); |
309 |
TeamHealth:= NewTeamHealthBarWidth; |
|
310 |
if NewTeamHealthBarWidth > MaxTeamHealth then |
|
47 | 311 |
begin |
557 | 312 |
MaxTeamHealth:= NewTeamHealthBarWidth; |
47 | 313 |
RecountAllTeamsHealth; |
557 | 314 |
end else NewTeamHealthBarWidth:= (NewTeamHealthBarWidth * cTeamHealthWidth) div MaxTeamHealth |
49 | 315 |
end; |
549 | 316 |
|
317 |
RecountClanHealth(team^.Clan); |
|
318 |
||
498 | 319 |
AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0) |
47 | 320 |
end; |
321 |
||
72 | 322 |
procedure RestoreTeamsFromSave; |
547 | 323 |
var t: LongInt; |
72 | 324 |
begin |
547 | 325 |
for t:= 0 to Pred(TeamsCount) do |
326 |
TeamsArray[t]^.ExtDriven:= false |
|
72 | 327 |
end; |
328 |
||
4 | 329 |
initialization |
330 |
||
331 |
finalization |
|
332 |
||
333 |
FreeTeamsList |
|
334 |
||
335 |
end. |