author | unc0rr |
Wed, 28 Dec 2005 22:18:11 +0000 | |
changeset 32 | 78bff13b11c0 |
parent 13 | 7a5db822fd3f |
child 37 | 2b7f2a43b999 |
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 |
|
235 |
{$IFDEF DEBUGFILE}AddFileLog('/-attack: Gear.State = '+inttostr(State)+' CurAmmoGear = '+inttostr(longword(CurAmmoGear)));{$ENDIF} |
|
32
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
13
diff
changeset
|
236 |
Message:= Message and not gm_Attack; |
78bff13b11c0
With this patch the game doesn't crash when gaming by net
unc0rr
parents:
13
diff
changeset
|
237 |
if not CurrentTeam.ExtDriven then SendIPC('a') |
4 | 238 |
end |
239 |
end; |
|
240 |
||
241 |
procedure chSwitch(var s: shortstring); |
|
242 |
begin |
|
243 |
if CheckNoTeamOrHH then exit; |
|
244 |
if not CurrentTeam.ExtDriven then SendIPC('S'); |
|
245 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
246 |
Message:= Message or gm_Switch |
|
247 |
end; |
|
248 |
||
249 |
procedure chNextTurn(var s: shortstring); |
|
250 |
begin |
|
251 |
if AllInactive then |
|
252 |
begin |
|
253 |
if not CurrentTeam.ExtDriven then SendIPC('N'); |
|
254 |
{$IFDEF DEBUGFILE}AddFileLog('Doing SwitchHedgehog: time '+inttostr(GameTicks));{$ENDIF} |
|
255 |
SwitchHedgehog; |
|
256 |
end |
|
257 |
end; |
|
258 |
||
259 |
procedure chSay(var s: shortstring); |
|
260 |
begin |
|
261 |
WriteLnToConsole('> ' + s); |
|
262 |
SendIPC('s'+s) |
|
263 |
end; |
|
264 |
||
265 |
procedure chTimer(var s: shortstring); |
|
266 |
begin |
|
267 |
if (s[0] <> #1) or (s[1] < '1') or (s[1] > '5') or (CurrentTeam = nil) then exit; |
|
268 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog] do |
|
269 |
if (Ammo[CurSlot, CurAmmo].Propz and ammoprop_Timerable) <> 0 then |
|
270 |
begin |
|
271 |
Ammo[CurSlot, CurAmmo].Timer:= 1000 * (byte(s[1]) - 48); |
|
272 |
with CurrentTeam^ do |
|
273 |
ApplyAmmoChanges(@Hedgehogs[CurrHedgehog]); |
|
274 |
if not CurrentTeam.ExtDriven then SendIPC(s); |
|
275 |
end |
|
276 |
end; |
|
277 |
||
278 |
procedure chSlot(var s: shortstring); |
|
279 |
var slot: LongWord; |
|
280 |
caSlot, caAmmo: PLongword; |
|
281 |
begin |
|
282 |
if (s[0] <> #1) or (CurrentTeam = nil) then exit; |
|
283 |
slot:= byte(s[1]) - 49; |
|
10 | 284 |
if slot > cMaxSlotIndex then exit; |
4 | 285 |
if not CurrentTeam.ExtDriven then SendIPC(char(byte(s[1]) + 79)); |
286 |
with CurrentTeam^ do |
|
287 |
begin |
|
288 |
with Hedgehogs[CurrHedgehog] do |
|
289 |
begin |
|
290 |
if ((Gear.State and (gstAttacking or gstAttacked)) <> 0) or (AttacksNum > 0) |
|
291 |
or ((Gear.State and gstHHDriven) = 0) then exit; // во время стрельбы исключает смену оружия |
|
292 |
if CurAmmoGear = nil then begin caSlot:= @CurSlot; caAmmo:= @CurAmmo end |
|
293 |
else begin caSlot:= @AltSlot; caAmmo:= @AltAmmo end; |
|
294 |
if caSlot^ = slot then |
|
295 |
begin |
|
296 |
inc(caAmmo^); |
|
10 | 297 |
if (caAmmo^ > cMaxSlotAmmoIndex) or (Ammo[slot, caAmmo^].Count = 0) then caAmmo^:= 0 |
4 | 298 |
end else |
299 |
if Ammo[slot, 0].Count > 0 then |
|
300 |
begin |
|
301 |
caSlot^:= slot; |
|
302 |
caAmmo^:= 0; |
|
303 |
end; |
|
304 |
TargetPoint.X:= NoPointX; |
|
305 |
end; |
|
306 |
ApplyAmmoChanges(@Hedgehogs[CurrHedgehog]) |
|
307 |
end |
|
308 |
end; |
|
309 |
||
310 |
procedure chPut(var s: shortstring); |
|
311 |
begin |
|
312 |
if CheckNoTeamOrHH then exit; |
|
313 |
with CurrentTeam.Hedgehogs[CurrentTeam.CurrHedgehog].Gear^ do |
|
314 |
if (State and gstHHChooseTarget) <> 0 then |
|
315 |
begin |
|
316 |
isCursorVisible:= false; |
|
317 |
if not CurrentTeam.ExtDriven then |
|
318 |
begin |
|
319 |
SDL_GetMouseState(@TargetPoint.X, @TargetPoint.Y); |
|
320 |
dec(TargetPoint.X, WorldDx); |
|
321 |
dec(TargetPoint.Y, WorldDy); |
|
322 |
s[0]:= #9; |
|
323 |
s[1]:= 'p'; |
|
324 |
PInteger(@s[2])^:= TargetPoint.X; |
|
325 |
PInteger(@s[6])^:= TargetPoint.Y; |
|
326 |
SendIPC(s) |
|
327 |
end; |
|
328 |
AdjustMPoint; |
|
329 |
State:= State and not gstHHChooseTarget; |
|
330 |
end else if CurrentTeam.ExtDriven then OutError('got /put while not being in choose target mode', true) |
|
331 |
end; |
|
332 |
||
333 |
procedure chCapture(var s: shortstring); |
|
334 |
begin |
|
335 |
flagMakeCapture:= true |
|
336 |
end; |
|
337 |