author | unc0rr |
Sun, 15 Jan 2006 14:14:12 +0000 | |
changeset 49 | 3afe33c1cf06 |
parent 48 | 0f396d0c429d |
child 55 | e09f7c952a40 |
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; |
|
52 |
if GameType = gmtDemo then CurrentTeam.ExtDriven:= true |
|
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 |
|
70 |
else if (id[1]='h')and(id[2]='h')and(id[3]>='0')and(id[3]<='7') then |
|
71 |
CurrentTeam.Hedgehogs[byte(id[3])-48].Name:= s |
|
72 |
else OutError(errmsgUnknownVariable + ' "' + id + '"') |
|
73 |
end; |
|
74 |
||
75 |
procedure chGrave(var s: shortstring); |
|
76 |
begin |
|
77 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/grave"', true); |
|
78 |
if s[1]='"' then Delete(s, 1, 1); |
|
79 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
80 |
CurrentTeam.GraveName:= s |
|
81 |
end; |
|
82 |
||
83 |
procedure chFort(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.FortName:= s |
|
89 |
end; |
|
90 |
||
91 |
procedure chColor(var id: shortstring); |
|
92 |
var c: integer; |
|
93 |
begin |
|
94 |
if CurrentTeam = nil then OutError(errmsgIncorrectUse + ' "/color"', true); |
|
95 |
val(id, CurrentTeam.Color, c); |
|
96 |
AdjustColor(CurrentTeam.Color) |
|
97 |
end; |
|
98 |
||
99 |
procedure chAdd(var id: shortstring); |
|
100 |
var s: shortstring; |
|
101 |
c: integer; |
|
102 |
Gear: PGear; |
|
103 |
b: byte; |
|
104 |
begin |
|
105 |
if (not isDeveloperMode)or(CurrentTeam=nil) then exit; |
|
106 |
SplitBySpace(id, s); |
|
107 |
if (id[1]='h')and(id[2]='h')and(id[3]>='0')and(id[3]<='7') then |
|
108 |
begin |
|
109 |
b:= byte(id[3])-48; |
|
110 |
val(s, CurrentTeam.Hedgehogs[b].BotLevel, c); |
|
111 |
Gear:= AddGear(0, 0, gtHedgehog, 0); |
|
112 |
Gear.Hedgehog:= @CurrentTeam.Hedgehogs[b]; |
|
113 |
PHedgehog(Gear.Hedgehog).Team:= CurrentTeam; |
|
114 |
CurrentTeam.Hedgehogs[b].Gear:= Gear |
|
115 |
end |
|
116 |
else OutError(errmsgUnknownVariable + ' "' + id + '"', true) |
|
117 |
end; |
|
118 |
||
119 |
procedure chBind(var id: shortstring); |
|
120 |
var s: shortstring; |
|
121 |
b: integer; |
|
122 |
begin |
|
123 |
if CurrentTeam = nil then exit; |
|
124 |
SplitBySpace(id, s); |
|
125 |
if s[1]='"' then Delete(s, 1, 1); |
|
126 |
if s[byte(s[0])]='"' then Delete(s, byte(s[0]), 1); |
|
127 |
b:= KeyNameToCode(id); |
|
128 |
if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"') |
|
129 |
else CurrentTeam.Aliases[b]:= s |
|
130 |
end; |
|
131 |
||
132 |
procedure chLeft_p(var s: shortstring); |
|
133 |
begin |
|
134 |
if CheckNoTeamOrHH then exit; |
|
135 |
if not CurrentTeam.ExtDriven then SendIPC('L'); |
|
136 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
137 |
Message:= Message or gm_Left |
|
138 |
end; |
|
139 |
||
140 |
procedure chLeft_m(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 and not gm_Left |
|
146 |
end; |
|
147 |
||
148 |
procedure chRight_p(var s: shortstring); |
|
149 |
begin |
|
150 |
if CheckNoTeamOrHH then exit; |
|
151 |
if not CurrentTeam.ExtDriven then SendIPC('R'); |
|
152 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
153 |
Message:= Message or gm_Right |
|
154 |
end; |
|
155 |
||
156 |
procedure chRight_m(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 and not gm_Right |
|
162 |
end; |
|
163 |
||
164 |
procedure chUp_p(var s: shortstring); |
|
165 |
begin |
|
166 |
if CheckNoTeamOrHH then exit; |
|
167 |
if not CurrentTeam.ExtDriven then SendIPC('U'); |
|
168 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
169 |
Message:= Message or gm_Up |
|
170 |
end; |
|
171 |
||
172 |
procedure chUp_m(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 and not gm_Up |
|
178 |
end; |
|
179 |
||
180 |
procedure chDown_p(var s: shortstring); |
|
181 |
begin |
|
182 |
if CheckNoTeamOrHH then exit; |
|
183 |
if not CurrentTeam.ExtDriven then SendIPC('D'); |
|
184 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
185 |
Message:= Message or gm_Down |
|
186 |
end; |
|
187 |
||
188 |
procedure chDown_m(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 and not gm_Down |
|
194 |
end; |
|
195 |
||
196 |
procedure chLJump(var s: shortstring); |
|
197 |
begin |
|
198 |
if CheckNoTeamOrHH then exit; |
|
199 |
if not CurrentTeam.ExtDriven then SendIPC('j'); |
|
200 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
201 |
Message:= Message or gm_LJump |
|
202 |
end; |
|
203 |
||
204 |
procedure chHJump(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_HJump |
|
210 |
end; |
|
211 |
||
212 |
procedure chAttack_p(var s: shortstring); |
|
213 |
begin |
|
214 |
if CheckNoTeamOrHH then exit; |
|
215 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
216 |
begin |
|
217 |
{$IFDEF DEBUGFILE}AddFileLog('/+attack: Gear.State = '+inttostr(State));{$ENDIF} |
|
218 |
if ((State and gstHHDriven)<>0)and((State and (gstAttacked or gstHHChooseTarget or gstMoving)) = 0) then |
|
219 |
begin |
|
220 |
FollowGear:= CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear; |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
13
diff
changeset
|
221 |
if (State and (gstAttacked or gstHHChooseTarget) = 0)and(CurAmmoGear = nil) then |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
13
diff
changeset
|
222 |
State:= State or gstAttacking; |
4 | 223 |
if not CurrentTeam.ExtDriven then SendIPC('A'); |
224 |
Message:= Message or gm_Attack |
|
225 |
end |
|
226 |
end |
|
227 |
end; |
|
228 |
||
229 |
procedure chAttack_m(var s: shortstring); |
|
230 |
begin |
|
231 |
if CheckNoTeamOrHH then exit; |
|
232 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^, |
|
233 |
CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
|
234 |
begin |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
13
diff
changeset
|
235 |
Message:= Message and not gm_Attack; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
13
diff
changeset
|
236 |
if not CurrentTeam.ExtDriven then SendIPC('a') |
4 | 237 |
end |
238 |
end; |
|
239 |
||
240 |
procedure chSwitch(var s: shortstring); |
|
241 |
begin |
|
242 |
if CheckNoTeamOrHH then exit; |
|
243 |
if not CurrentTeam.ExtDriven then SendIPC('S'); |
|
244 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
245 |
Message:= Message or gm_Switch |
|
246 |
end; |
|
247 |
||
248 |
procedure chNextTurn(var s: shortstring); |
|
249 |
begin |
|
250 |
if AllInactive then |
|
251 |
begin |
|
252 |
if not CurrentTeam.ExtDriven then SendIPC('N'); |
|
253 |
{$IFDEF DEBUGFILE}AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));{$ENDIF} |
|
254 |
SwitchHedgehog; |
|
255 |
end |
|
256 |
end; |
|
257 |
||
258 |
procedure chSay(var s: shortstring); |
|
259 |
begin |
|
260 |
WriteLnToConsole('> ' + s); |
|
261 |
SendIPC('s'+s) |
|
262 |
end; |
|
263 |
||
264 |
procedure chTimer(var s: shortstring); |
|
265 |
begin |
|
266 |
if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit; |
|
267 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
|
268 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then |
|
269 |
begin |
|
270 |
Ammo[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48); |
|
271 |
with CurrentTeam^ do |
|
272 |
ApplyAmmoChanges(@Hedgehogs[CurrHedgehog]); |
|
273 |
if not CurrentTeam.ExtDriven then SendIPC(s); |
|
274 |
end |
|
275 |
end; |
|
276 |
||
277 |
procedure chSlot(var s: shortstring); |
|
278 |
var slot: LongWord; |
|
279 |
caSlot, caAmmo: PLongword; |
|
280 |
begin |
|
281 |
if (s[0] <> #1) or (CurrentTeam = nil) then exit; |
|
282 |
slot:= byte(s[1]) - 49; |
|
10 | 283 |
if slot > cMaxSlotIndex then exit; |
4 | 284 |
if not CurrentTeam.ExtDriven then SendIPC(char(byte(s[1]) + 79)); |
285 |
with CurrentTeam^ do |
|
286 |
begin |
|
287 |
with Hedgehogs[CurrHedgehog] do |
|
288 |
begin |
|
289 |
if ((Gear.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) |
|
290 |
or ((Gear.State and gstHHDriven) = 0) then exit; // во время стрельбы исключает смену оружия |
|
291 |
if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end |
|
292 |
else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; |
|
293 |
if caSlot^ = slot then |
|
294 |
begin |
|
295 |
inc(caAmmo^); |
|
10 | 296 |
if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo[slot, caAmmo^].Count = 0) then caAmmo^:= 0 |
4 | 297 |
end else |
298 |
if Ammo[slot, 0].Count > 0 then |
|
299 |
begin |
|
300 |
caSlot^:= slot; |
|
301 |
caAmmo^:= 0; |
|
302 |
end; |
|
303 |
TargetPoint.X:= NoPointX; |
|
304 |
end; |
|
305 |
ApplyAmmoChanges(@Hedgehogs[CurrHedgehog]) |
|
306 |
end |
|
307 |
end; |
|
308 |
||
309 |
procedure chPut(var s: shortstring); |
|
310 |
begin |
|
311 |
if CheckNoTeamOrHH then exit; |
|
312 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
313 |
if (State and gstHHChooseTarget) <> 0 then |
|
314 |
begin |
|
315 |
isCursorVisible:= false; |
|
316 |
if not CurrentTeam.ExtDriven then |
|
317 |
begin |
|
318 |
SDL_GetMouseState(@TargetPoint.X, @TargetPoint.Y); |
|
319 |
dec(TargetPoint.X, WorldDx); |
|
320 |
dec(TargetPoint.Y, WorldDy); |
|
321 |
s[0]:= #9; |
|
322 |
s[1]:= 'p'; |
|
323 |
PInteger(@s[2])^:= TargetPoint.X; |
|
324 |
PInteger(@s[6])^:= TargetPoint.Y; |
|
325 |
SendIPC(s) |
|
326 |
end; |
|
327 |
AdjustMPoint; |
|
328 |
State:= State and not gstHHChooseTarget; |
|
329 |
end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', true) |
|
330 |
end; |
|
331 |
||
332 |
procedure chCapture(var s: shortstring); |
|
333 |
begin |
|
334 |
flagMakeCapture:= true |
|
335 |
end; |
|
336 |
||
48 | 337 |
procedure chSkip(var s: shortstring); |
338 |
begin |
|
339 |
if not CurrentTeam.ExtDriven then SendIPC(','); |
|
340 |
TurnTimeLeft:= 0 |
|
341 |
end; |
|
342 |