author | unc0rr |
Thu, 21 Sep 2006 17:57:35 +0000 | |
changeset 157 | 8e3e11bb0a5f |
parent 154 | 5667e6f38704 |
child 161 | d8870bbf960e |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2004, 2005 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* Distributed under the terms of the BSD-modified licence: |
|
6 |
* |
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8 |
* of this software and associated documentation files (the "Software"), to deal |
|
9 |
* with the Software without restriction, including without limitation the |
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is |
|
12 |
* furnished to do so, subject to the following conditions: |
|
13 |
* |
|
14 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
15 |
* this list of conditions and the following disclaimer. |
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
17 |
* this list of conditions and the following disclaimer in the documentation |
|
18 |
* and/or other materials provided with the distribution. |
|
19 |
* 3. The name of the author may not be used to endorse or promote products |
|
20 |
* derived from this software without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
|
23 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|
24 |
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
|
25 |
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
26 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
27 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
|
28 |
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
|
29 |
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
|
30 |
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
|
31 |
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
*) |
|
33 |
||
34 |
function CheckNoTeamOrHH: boolean; |
|
35 |
begin |
|
36 |
Result:= (CurrentTeam=nil) or (CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear = nil); |
|
37 |
{$IFDEF DEBUGFILE} |
|
38 |
if Result then |
|
39 |
if CurrentTeam = nil then AddFileLog('CONSOLE: CurTeam = nil') |
|
40 |
else AddFileLog('CONSOLE: CurTeam <> nil, Gear = nil') |
|
41 |
{$ENDIF} |
|
42 |
end; |
|
43 |
//////////////////////////////////////////////////////////////////////////////// |
|
44 |
procedure chQuit(var s: shortstring); |
|
45 |
begin |
|
46 |
GameState:= gsExit |
|
47 |
end; |
|
48 |
||
49 |
procedure chAddTeam(var s: shortstring); |
|
145 | 50 |
const TeamsCount: Longword = 0; |
4 | 51 |
begin |
145 | 52 |
if isDeveloperMode then |
53 |
begin |
|
54 |
inc(TeamsCount); |
|
55 |
TryDo(TeamsCount <= 5, 'Too many teams', true); |
|
56 |
AddTeam |
|
57 |
end; |
|
58 |
||
72 | 59 |
if GameType in [gmtDemo, gmtSave] then CurrentTeam.ExtDriven:= true |
4 | 60 |
end; |
61 |
||
62 |
procedure chTeamLocal(var s: shortstring); |
|
63 |
begin |
|
64 |
if not isDeveloperMode then exit; |
|
65 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/rdriven"', true); |
|
66 |
CurrentTeam.ExtDriven:= true |
|
67 |
end; |
|
68 |
||
69 |
procedure chName(var id: shortstring); |
|
70 |
var s: shortstring; |
|
71 |
begin |
|
72 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/name"', true); |
|
73 |
SplitBySpace(id, s); |
|
74 |
if s[1]='"' then Delete(s, 1, 1); |
|
75 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
76 |
if id = 'team' then CurrentTeam.TeamName:= s |
|
83 | 77 |
else if (id[1] = 'h') and (id[2] = 'h') |
78 |
and (id[3] >= '0') and (id[3] <= chr(ord('0')+cMaxHHIndex)) then |
|
4 | 79 |
CurrentTeam.Hedgehogs[byte(id[3])-48].Name:= s |
80 |
else OutError(errmsgUnknownVariable + ' "' + id + '"') |
|
81 |
end; |
|
82 |
||
83 |
procedure chGrave(var s: shortstring); |
|
84 |
begin |
|
85 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true); |
|
86 |
if s[1]='"' then Delete(s, 1, 1); |
|
87 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
88 |
CurrentTeam.GraveName:= s |
|
89 |
end; |
|
90 |
||
91 |
procedure chFort(var s: shortstring); |
|
92 |
begin |
|
93 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true); |
|
94 |
if s[1]='"' then Delete(s, 1, 1); |
|
95 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
96 |
CurrentTeam.FortName:= s |
|
97 |
end; |
|
98 |
||
99 |
procedure chColor(var id: shortstring); |
|
100 |
var c: integer; |
|
101 |
begin |
|
102 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/color"', true); |
|
103 |
val(id, CurrentTeam.Color, c); |
|
104 |
AdjustColor(CurrentTeam.Color) |
|
105 |
end; |
|
106 |
||
107 |
procedure chAdd(var id: shortstring); |
|
108 |
var s: shortstring; |
|
109 |
c: integer; |
|
110 |
Gear: PGear; |
|
111 |
b: byte; |
|
112 |
begin |
|
113 |
if (not isDeveloperMode)or(CurrentTeam=nil) then exit; |
|
114 |
SplitBySpace(id, s); |
|
115 |
if (id[1]='h')and(id[2]='h')and(id[3]>='0')and(id[3]<='7') then |
|
116 |
begin |
|
117 |
b:= byte(id[3])-48; |
|
118 |
val(s, CurrentTeam.Hedgehogs[b].BotLevel, c); |
|
119 |
Gear:= AddGear(0, 0, gtHedgehog, 0); |
|
120 |
Gear.Hedgehog:= @CurrentTeam.Hedgehogs[b]; |
|
121 |
PHedgehog(Gear.Hedgehog).Team:= CurrentTeam; |
|
122 |
CurrentTeam.Hedgehogs[b].Gear:= Gear |
|
123 |
end |
|
124 |
else OutError(errmsgUnknownVariable + ' "' + id + '"', true) |
|
125 |
end; |
|
126 |
||
127 |
procedure chBind(var id: shortstring); |
|
128 |
var s: shortstring; |
|
129 |
b: integer; |
|
130 |
begin |
|
131 |
if CurrentTeam = nil then exit; |
|
132 |
SplitBySpace(id, s); |
|
133 |
if s[1]='"' then Delete(s, 1, 1); |
|
134 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
135 |
b:= KeyNameToCode(id); |
|
136 |
if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"') |
|
137 |
else CurrentTeam.Aliases[b]:= s |
|
138 |
end; |
|
139 |
||
140 |
procedure chLeft_p(var s: shortstring); |
|
141 |
begin |
|
142 |
if CheckNoTeamOrHH then exit; |
|
143 |
if not CurrentTeam.ExtDriven then SendIPC('L'); |
|
144 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
145 |
Message:= Message or gm_Left |
|
146 |
end; |
|
147 |
||
148 |
procedure chLeft_m(var s: shortstring); |
|
149 |
begin |
|
150 |
if CheckNoTeamOrHH then exit; |
|
151 |
if not CurrentTeam.ExtDriven then SendIPC('l'); |
|
152 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
153 |
Message:= Message and not gm_Left |
|
154 |
end; |
|
155 |
||
156 |
procedure chRight_p(var s: shortstring); |
|
157 |
begin |
|
158 |
if CheckNoTeamOrHH then exit; |
|
159 |
if not CurrentTeam.ExtDriven then SendIPC('R'); |
|
160 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
161 |
Message:= Message or gm_Right |
|
162 |
end; |
|
163 |
||
164 |
procedure chRight_m(var s: shortstring); |
|
165 |
begin |
|
166 |
if CheckNoTeamOrHH then exit; |
|
167 |
if not CurrentTeam.ExtDriven then SendIPC('r'); |
|
168 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
169 |
Message:= Message and not gm_Right |
|
170 |
end; |
|
171 |
||
172 |
procedure chUp_p(var s: shortstring); |
|
173 |
begin |
|
174 |
if CheckNoTeamOrHH then exit; |
|
175 |
if not CurrentTeam.ExtDriven then SendIPC('U'); |
|
176 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
177 |
Message:= Message or gm_Up |
|
178 |
end; |
|
179 |
||
180 |
procedure chUp_m(var s: shortstring); |
|
181 |
begin |
|
182 |
if CheckNoTeamOrHH then exit; |
|
183 |
if not CurrentTeam.ExtDriven then SendIPC('u'); |
|
184 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
185 |
Message:= Message and not gm_Up |
|
186 |
end; |
|
187 |
||
188 |
procedure chDown_p(var s: shortstring); |
|
189 |
begin |
|
190 |
if CheckNoTeamOrHH then exit; |
|
191 |
if not CurrentTeam.ExtDriven then SendIPC('D'); |
|
192 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
193 |
Message:= Message or gm_Down |
|
194 |
end; |
|
195 |
||
196 |
procedure chDown_m(var s: shortstring); |
|
197 |
begin |
|
198 |
if CheckNoTeamOrHH then exit; |
|
199 |
if not CurrentTeam.ExtDriven then SendIPC('d'); |
|
200 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
201 |
Message:= Message and not gm_Down |
|
202 |
end; |
|
203 |
||
204 |
procedure chLJump(var s: shortstring); |
|
205 |
begin |
|
206 |
if CheckNoTeamOrHH then exit; |
|
207 |
if not CurrentTeam.ExtDriven then SendIPC('j'); |
|
208 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
209 |
Message:= Message or gm_LJump |
|
210 |
end; |
|
211 |
||
212 |
procedure chHJump(var s: shortstring); |
|
213 |
begin |
|
214 |
if CheckNoTeamOrHH then exit; |
|
215 |
if not CurrentTeam.ExtDriven then SendIPC('J'); |
|
216 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
217 |
Message:= Message or gm_HJump |
|
218 |
end; |
|
219 |
||
220 |
procedure chAttack_p(var s: shortstring); |
|
221 |
begin |
|
222 |
if CheckNoTeamOrHH then exit; |
|
223 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
224 |
begin |
|
225 |
{$IFDEF DEBUGFILE}AddFileLog('/+attack: Gear.State = '+inttostr(State));{$ENDIF} |
|
226 |
if ((State and gstHHDriven)<>0)and((State and (gstAttacked or gstHHChooseTarget or gstMoving)) = 0) then |
|
227 |
begin |
|
228 |
FollowGear:= CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear; |
|
229 |
if not CurrentTeam.ExtDriven then SendIPC('A'); |
|
230 |
Message:= Message or gm_Attack |
|
231 |
end |
|
232 |
end |
|
233 |
end; |
|
234 |
||
235 |
procedure chAttack_m(var s: shortstring); |
|
236 |
begin |
|
237 |
if CheckNoTeamOrHH then exit; |
|
95 | 238 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
4 | 239 |
begin |
95 | 240 |
if not CurrentTeam.ExtDriven and |
241 |
((Message and gm_Attack) <> 0) then SendIPC('a'); |
|
242 |
Message:= Message and not gm_Attack |
|
4 | 243 |
end |
244 |
end; |
|
245 |
||
246 |
procedure chSwitch(var s: shortstring); |
|
247 |
begin |
|
248 |
if CheckNoTeamOrHH then exit; |
|
249 |
if not CurrentTeam.ExtDriven then SendIPC('S'); |
|
250 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
251 |
Message:= Message or gm_Switch |
|
252 |
end; |
|
253 |
||
254 |
procedure chNextTurn(var s: shortstring); |
|
255 |
begin |
|
256 |
if AllInactive then |
|
257 |
begin |
|
258 |
if not CurrentTeam.ExtDriven then SendIPC('N'); |
|
259 |
{$IFDEF DEBUGFILE}AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));{$ENDIF} |
|
260 |
SwitchHedgehog; |
|
261 |
end |
|
262 |
end; |
|
263 |
||
264 |
procedure chSay(var s: shortstring); |
|
265 |
begin |
|
266 |
WriteLnToConsole('> ' + s); |
|
267 |
SendIPC('s'+s) |
|
268 |
end; |
|
269 |
||
270 |
procedure chTimer(var s: shortstring); |
|
271 |
begin |
|
272 |
if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit; |
|
273 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
|
274 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then |
|
275 |
begin |
|
276 |
Ammo[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48); |
|
277 |
with CurrentTeam^ do |
|
70 | 278 |
ApplyAmmoChanges(Hedgehogs[CurrHedgehog]); |
4 | 279 |
if not CurrentTeam.ExtDriven then SendIPC(s); |
280 |
end |
|
281 |
end; |
|
282 |
||
283 |
procedure chSlot(var s: shortstring); |
|
284 |
var slot: LongWord; |
|
285 |
caSlot, caAmmo: PLongword; |
|
286 |
begin |
|
95 | 287 |
if (s[0] <> #1) or CheckNoTeamOrHH then exit; |
4 | 288 |
slot:= byte(s[1]) - 49; |
10 | 289 |
if slot > cMaxSlotIndex then exit; |
4 | 290 |
if not CurrentTeam.ExtDriven then SendIPC(char(byte(s[1]) + 79)); |
291 |
with CurrentTeam^ do |
|
292 |
begin |
|
293 |
with Hedgehogs[CurrHedgehog] do |
|
294 |
begin |
|
295 |
if ((Gear.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) |
|
296 |
or ((Gear.State and gstHHDriven) = 0) then exit; // во время стрельбы исключает смену оружия |
|
297 |
if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end |
|
298 |
else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; |
|
299 |
if caSlot^ = slot then |
|
300 |
begin |
|
301 |
inc(caAmmo^); |
|
10 | 302 |
if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo[slot, caAmmo^].Count = 0) then caAmmo^:= 0 |
4 | 303 |
end else |
304 |
if Ammo[slot, 0].Count > 0 then |
|
305 |
begin |
|
306 |
caSlot^:= slot; |
|
307 |
caAmmo^:= 0; |
|
308 |
end; |
|
309 |
TargetPoint.X:= NoPointX; |
|
310 |
end; |
|
70 | 311 |
ApplyAmmoChanges(Hedgehogs[CurrHedgehog]) |
4 | 312 |
end |
313 |
end; |
|
314 |
||
315 |
procedure chPut(var s: shortstring); |
|
316 |
begin |
|
317 |
if CheckNoTeamOrHH then exit; |
|
318 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
319 |
if (State and gstHHChooseTarget) <> 0 then |
|
320 |
begin |
|
321 |
isCursorVisible:= false; |
|
322 |
if not CurrentTeam.ExtDriven then |
|
323 |
begin |
|
324 |
SDL_GetMouseState(@TargetPoint.X, @TargetPoint.Y); |
|
325 |
dec(TargetPoint.X, WorldDx); |
|
326 |
dec(TargetPoint.Y, WorldDy); |
|
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
145
diff
changeset
|
327 |
SendIPCXY('p', TargetPoint.X, TargetPoint.Y); |
4 | 328 |
end; |
329 |
State:= State and not gstHHChooseTarget; |
|
95 | 330 |
end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', false) |
4 | 331 |
end; |
332 |
||
333 |
procedure chCapture(var s: shortstring); |
|
334 |
begin |
|
335 |
flagMakeCapture:= true |
|
336 |
end; |
|
337 |
||
48 | 338 |
procedure chSkip(var s: shortstring); |
339 |
begin |
|
340 |
if not CurrentTeam.ExtDriven then SendIPC(','); |
|
341 |
TurnTimeLeft:= 0 |
|
342 |
end; |
|
343 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
344 |
procedure chSetMap(var s: shortstring); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
345 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
346 |
if isDeveloperMode then |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
347 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
348 |
Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
349 |
InitStepsFlags:= InitStepsFlags or cifMap |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
350 |
end |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
351 |
end; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
352 |
|
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
353 |
procedure chSetTheme(var s: shortstring); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
354 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
355 |
if isDeveloperMode then |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
356 |
begin |
80 | 357 |
Pathz[ptCurrTheme]:= Pathz[ptThemes] + '/' + s; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
358 |
InitStepsFlags:= InitStepsFlags or cifTheme |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
359 |
end |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
360 |
end; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
361 |
|
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
362 |
procedure chSetSeed(var s: shortstring); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
363 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
364 |
if isDeveloperMode then |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
365 |
begin |
102 | 366 |
SetRandomSeed(s); |
81 | 367 |
cSeed:= s; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
368 |
InitStepsFlags:= InitStepsFlags or cifRandomize |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
369 |
end |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
370 |
end; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
371 |