author | unc0rr |
Wed, 13 Sep 2006 19:26:16 +0000 | |
changeset 144 | e6084b0c9316 |
parent 110 | 330a2dbacd67 |
child 145 | e593d5266e01 |
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); |
|
50 |
begin |
|
51 |
if isDeveloperMode then AddTeam; |
|
72 | 52 |
if GameType in [gmtDemo, gmtSave] then CurrentTeam.ExtDriven:= true |
4 | 53 |
end; |
54 |
||
55 |
procedure chTeamLocal(var s: shortstring); |
|
56 |
begin |
|
57 |
if not isDeveloperMode then exit; |
|
58 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/rdriven"', true); |
|
59 |
CurrentTeam.ExtDriven:= true |
|
60 |
end; |
|
61 |
||
62 |
procedure chName(var id: shortstring); |
|
63 |
var s: shortstring; |
|
64 |
begin |
|
65 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/name"', true); |
|
66 |
SplitBySpace(id, s); |
|
67 |
if s[1]='"' then Delete(s, 1, 1); |
|
68 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
69 |
if id = 'team' then CurrentTeam.TeamName:= s |
|
83 | 70 |
else if (id[1] = 'h') and (id[2] = 'h') |
71 |
and (id[3] >= '0') and (id[3] <= chr(ord('0')+cMaxHHIndex)) then |
|
4 | 72 |
CurrentTeam.Hedgehogs[byte(id[3])-48].Name:= s |
73 |
else OutError(errmsgUnknownVariable + ' "' + id + '"') |
|
74 |
end; |
|
75 |
||
76 |
procedure chGrave(var s: shortstring); |
|
77 |
begin |
|
78 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true); |
|
79 |
if s[1]='"' then Delete(s, 1, 1); |
|
80 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
81 |
CurrentTeam.GraveName:= s |
|
82 |
end; |
|
83 |
||
84 |
procedure chFort(var s: shortstring); |
|
85 |
begin |
|
86 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true); |
|
87 |
if s[1]='"' then Delete(s, 1, 1); |
|
88 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
89 |
CurrentTeam.FortName:= s |
|
90 |
end; |
|
91 |
||
92 |
procedure chColor(var id: shortstring); |
|
93 |
var c: integer; |
|
94 |
begin |
|
95 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/color"', true); |
|
96 |
val(id, CurrentTeam.Color, c); |
|
97 |
AdjustColor(CurrentTeam.Color) |
|
98 |
end; |
|
99 |
||
100 |
procedure chAdd(var id: shortstring); |
|
101 |
var s: shortstring; |
|
102 |
c: integer; |
|
103 |
Gear: PGear; |
|
104 |
b: byte; |
|
105 |
begin |
|
106 |
if (not isDeveloperMode)or(CurrentTeam=nil) then exit; |
|
107 |
SplitBySpace(id, s); |
|
108 |
if (id[1]='h')and(id[2]='h')and(id[3]>='0')and(id[3]<='7') then |
|
109 |
begin |
|
110 |
b:= byte(id[3])-48; |
|
111 |
val(s, CurrentTeam.Hedgehogs[b].BotLevel, c); |
|
112 |
Gear:= AddGear(0, 0, gtHedgehog, 0); |
|
113 |
Gear.Hedgehog:= @CurrentTeam.Hedgehogs[b]; |
|
114 |
PHedgehog(Gear.Hedgehog).Team:= CurrentTeam; |
|
115 |
CurrentTeam.Hedgehogs[b].Gear:= Gear |
|
116 |
end |
|
117 |
else OutError(errmsgUnknownVariable + ' "' + id + '"', true) |
|
118 |
end; |
|
119 |
||
120 |
procedure chBind(var id: shortstring); |
|
121 |
var s: shortstring; |
|
122 |
b: integer; |
|
123 |
begin |
|
124 |
if CurrentTeam = nil then exit; |
|
125 |
SplitBySpace(id, s); |
|
126 |
if s[1]='"' then Delete(s, 1, 1); |
|
127 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
128 |
b:= KeyNameToCode(id); |
|
129 |
if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"') |
|
130 |
else CurrentTeam.Aliases[b]:= s |
|
131 |
end; |
|
132 |
||
133 |
procedure chLeft_p(var s: shortstring); |
|
134 |
begin |
|
135 |
if CheckNoTeamOrHH then exit; |
|
136 |
if not CurrentTeam.ExtDriven then SendIPC('L'); |
|
137 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
138 |
Message:= Message or gm_Left |
|
139 |
end; |
|
140 |
||
141 |
procedure chLeft_m(var s: shortstring); |
|
142 |
begin |
|
143 |
if CheckNoTeamOrHH then exit; |
|
144 |
if not CurrentTeam.ExtDriven then SendIPC('l'); |
|
145 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
146 |
Message:= Message and not gm_Left |
|
147 |
end; |
|
148 |
||
149 |
procedure chRight_p(var s: shortstring); |
|
150 |
begin |
|
151 |
if CheckNoTeamOrHH then exit; |
|
152 |
if not CurrentTeam.ExtDriven then SendIPC('R'); |
|
153 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
154 |
Message:= Message or gm_Right |
|
155 |
end; |
|
156 |
||
157 |
procedure chRight_m(var s: shortstring); |
|
158 |
begin |
|
159 |
if CheckNoTeamOrHH then exit; |
|
160 |
if not CurrentTeam.ExtDriven then SendIPC('r'); |
|
161 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
162 |
Message:= Message and not gm_Right |
|
163 |
end; |
|
164 |
||
165 |
procedure chUp_p(var s: shortstring); |
|
166 |
begin |
|
167 |
if CheckNoTeamOrHH then exit; |
|
168 |
if not CurrentTeam.ExtDriven then SendIPC('U'); |
|
169 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
170 |
Message:= Message or gm_Up |
|
171 |
end; |
|
172 |
||
173 |
procedure chUp_m(var s: shortstring); |
|
174 |
begin |
|
175 |
if CheckNoTeamOrHH then exit; |
|
176 |
if not CurrentTeam.ExtDriven then SendIPC('u'); |
|
177 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
178 |
Message:= Message and not gm_Up |
|
179 |
end; |
|
180 |
||
181 |
procedure chDown_p(var s: shortstring); |
|
182 |
begin |
|
183 |
if CheckNoTeamOrHH then exit; |
|
184 |
if not CurrentTeam.ExtDriven then SendIPC('D'); |
|
185 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
186 |
Message:= Message or gm_Down |
|
187 |
end; |
|
188 |
||
189 |
procedure chDown_m(var s: shortstring); |
|
190 |
begin |
|
191 |
if CheckNoTeamOrHH then exit; |
|
192 |
if not CurrentTeam.ExtDriven then SendIPC('d'); |
|
193 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
194 |
Message:= Message and not gm_Down |
|
195 |
end; |
|
196 |
||
197 |
procedure chLJump(var s: shortstring); |
|
198 |
begin |
|
199 |
if CheckNoTeamOrHH then exit; |
|
200 |
if not CurrentTeam.ExtDriven then SendIPC('j'); |
|
201 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
202 |
Message:= Message or gm_LJump |
|
203 |
end; |
|
204 |
||
205 |
procedure chHJump(var s: shortstring); |
|
206 |
begin |
|
207 |
if CheckNoTeamOrHH then exit; |
|
208 |
if not CurrentTeam.ExtDriven then SendIPC('J'); |
|
209 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
210 |
Message:= Message or gm_HJump |
|
211 |
end; |
|
212 |
||
213 |
procedure chAttack_p(var s: shortstring); |
|
214 |
begin |
|
215 |
if CheckNoTeamOrHH then exit; |
|
216 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
217 |
begin |
|
218 |
{$IFDEF DEBUGFILE}AddFileLog('/+attack: Gear.State = '+inttostr(State));{$ENDIF} |
|
219 |
if ((State and gstHHDriven)<>0)and((State and (gstAttacked or gstHHChooseTarget or gstMoving)) = 0) then |
|
220 |
begin |
|
221 |
FollowGear:= CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear; |
|
222 |
if not CurrentTeam.ExtDriven then SendIPC('A'); |
|
223 |
Message:= Message or gm_Attack |
|
224 |
end |
|
225 |
end |
|
226 |
end; |
|
227 |
||
228 |
procedure chAttack_m(var s: shortstring); |
|
229 |
begin |
|
230 |
if CheckNoTeamOrHH then exit; |
|
95 | 231 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
4 | 232 |
begin |
95 | 233 |
if not CurrentTeam.ExtDriven and |
234 |
((Message and gm_Attack) <> 0) then SendIPC('a'); |
|
235 |
Message:= Message and not gm_Attack |
|
4 | 236 |
end |
237 |
end; |
|
238 |
||
239 |
procedure chSwitch(var s: shortstring); |
|
240 |
begin |
|
241 |
if CheckNoTeamOrHH then exit; |
|
242 |
if not CurrentTeam.ExtDriven then SendIPC('S'); |
|
243 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
244 |
Message:= Message or gm_Switch |
|
245 |
end; |
|
246 |
||
247 |
procedure chNextTurn(var s: shortstring); |
|
248 |
begin |
|
249 |
if AllInactive then |
|
250 |
begin |
|
251 |
if not CurrentTeam.ExtDriven then SendIPC('N'); |
|
252 |
{$IFDEF DEBUGFILE}AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));{$ENDIF} |
|
253 |
SwitchHedgehog; |
|
254 |
end |
|
255 |
end; |
|
256 |
||
257 |
procedure chSay(var s: shortstring); |
|
258 |
begin |
|
259 |
WriteLnToConsole('> ' + s); |
|
260 |
SendIPC('s'+s) |
|
261 |
end; |
|
262 |
||
263 |
procedure chTimer(var s: shortstring); |
|
264 |
begin |
|
265 |
if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit; |
|
266 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
|
267 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then |
|
268 |
begin |
|
269 |
Ammo[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48); |
|
270 |
with CurrentTeam^ do |
|
70 | 271 |
ApplyAmmoChanges(Hedgehogs[CurrHedgehog]); |
4 | 272 |
if not CurrentTeam.ExtDriven then SendIPC(s); |
273 |
end |
|
274 |
end; |
|
275 |
||
276 |
procedure chSlot(var s: shortstring); |
|
277 |
var slot: LongWord; |
|
278 |
caSlot, caAmmo: PLongword; |
|
279 |
begin |
|
95 | 280 |
if (s[0] <> #1) or CheckNoTeamOrHH then exit; |
4 | 281 |
slot:= byte(s[1]) - 49; |
10 | 282 |
if slot > cMaxSlotIndex then exit; |
4 | 283 |
if not CurrentTeam.ExtDriven then SendIPC(char(byte(s[1]) + 79)); |
284 |
with CurrentTeam^ do |
|
285 |
begin |
|
286 |
with Hedgehogs[CurrHedgehog] do |
|
287 |
begin |
|
288 |
if ((Gear.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) |
|
289 |
or ((Gear.State and gstHHDriven) = 0) then exit; // во время стрельбы исключает смену оружия |
|
290 |
if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end |
|
291 |
else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; |
|
292 |
if caSlot^ = slot then |
|
293 |
begin |
|
294 |
inc(caAmmo^); |
|
10 | 295 |
if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo[slot, caAmmo^].Count = 0) then caAmmo^:= 0 |
4 | 296 |
end else |
297 |
if Ammo[slot, 0].Count > 0 then |
|
298 |
begin |
|
299 |
caSlot^:= slot; |
|
300 |
caAmmo^:= 0; |
|
301 |
end; |
|
302 |
TargetPoint.X:= NoPointX; |
|
303 |
end; |
|
70 | 304 |
ApplyAmmoChanges(Hedgehogs[CurrHedgehog]) |
4 | 305 |
end |
306 |
end; |
|
307 |
||
308 |
procedure chPut(var s: shortstring); |
|
309 |
begin |
|
310 |
if CheckNoTeamOrHH then exit; |
|
311 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
312 |
if (State and gstHHChooseTarget) <> 0 then |
|
313 |
begin |
|
314 |
isCursorVisible:= false; |
|
315 |
if not CurrentTeam.ExtDriven then |
|
316 |
begin |
|
317 |
SDL_GetMouseState(@TargetPoint.X, @TargetPoint.Y); |
|
318 |
dec(TargetPoint.X, WorldDx); |
|
319 |
dec(TargetPoint.Y, WorldDy); |
|
110 | 320 |
s[0]:= #5; |
4 | 321 |
s[1]:= 'p'; |
95 | 322 |
PSmallInt(@s[2])^:= TargetPoint.X; |
323 |
PSmallInt(@s[4])^:= TargetPoint.Y; |
|
4 | 324 |
SendIPC(s) |
325 |
end; |
|
326 |
State:= State and not gstHHChooseTarget; |
|
95 | 327 |
end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', false) |
4 | 328 |
end; |
329 |
||
330 |
procedure chCapture(var s: shortstring); |
|
331 |
begin |
|
332 |
flagMakeCapture:= true |
|
333 |
end; |
|
334 |
||
48 | 335 |
procedure chSkip(var s: shortstring); |
336 |
begin |
|
337 |
if not CurrentTeam.ExtDriven then SendIPC(','); |
|
338 |
TurnTimeLeft:= 0 |
|
339 |
end; |
|
340 |
||
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
341 |
procedure chSetMap(var s: shortstring); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
342 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
343 |
if isDeveloperMode then |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
344 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
345 |
Pathz[ptMapCurrent]:= Pathz[ptMaps] + '/' + s; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
346 |
InitStepsFlags:= InitStepsFlags or cifMap |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
347 |
end |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
348 |
end; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
349 |
|
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
350 |
procedure chSetTheme(var s: shortstring); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
351 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
352 |
if isDeveloperMode then |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
353 |
begin |
80 | 354 |
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
|
355 |
InitStepsFlags:= InitStepsFlags or cifTheme |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
356 |
end |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
357 |
end; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
358 |
|
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
359 |
procedure chSetSeed(var s: shortstring); |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
360 |
begin |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
361 |
if isDeveloperMode then |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
362 |
begin |
102 | 363 |
SetRandomSeed(s); |
81 | 364 |
cSeed:= s; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
365 |
InitStepsFlags:= InitStepsFlags or cifRandomize |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
366 |
end |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
367 |
end; |
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
48
diff
changeset
|
368 |