author | displacer |
Mon, 07 Jan 2008 15:44:13 +0000 | |
changeset 693 | 32a546d1eb3e |
parent 690 | e9d35e319328 |
child 753 | 40fc0deb388f |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
393 | 3 |
* Copyright (c) 2004-2007 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 uWorld; |
|
20 |
interface |
|
351 | 21 |
uses SDLh, uGears, uConsts, uFloat; |
4 | 22 |
{$INCLUDE options.inc} |
371 | 23 |
const WorldDx: LongInt = -512; |
24 |
WorldDy: LongInt = -256; |
|
4 | 25 |
|
26 |
procedure InitWorld; |
|
371 | 27 |
procedure DrawWorld(Lag: LongInt; Surface: PSDL_Surface); |
108 | 28 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 29 |
|
30 |
{$IFDEF COUNTTICKS} |
|
31 |
var cntTicks: LongWord; |
|
32 |
{$ENDIF} |
|
33 |
var FollowGear: PGear = nil; |
|
371 | 34 |
WindBarWidth: LongInt = 0; |
161 | 35 |
bShowAmmoMenu: boolean = false; |
162 | 36 |
bSelected: boolean = false; |
176 | 37 |
bShowFinger: boolean = false; |
191
a03c2d037e24
Bots are in the same thread as game. Fixes FreePascal issues.
unc0rr
parents:
183
diff
changeset
|
38 |
Frames: Longword = 0; |
4 | 39 |
|
40 |
implementation |
|
174 | 41 |
uses uStore, uMisc, uTeams, uIO, uConsole, uKeys, uLocale, uSound; |
564 | 42 |
const FPS: Longword = 0; |
4 | 43 |
CountTicks: Longword = 0; |
174 | 44 |
SoundTimerTicks: Longword = 0; |
4 | 45 |
prevPoint: TPoint = (X: 0; Y: 0); |
161 | 46 |
|
4 | 47 |
type TCaptionStr = record |
83 | 48 |
Surf: PSDL_Surface; |
4 | 49 |
EndTime: LongWord; |
50 |
end; |
|
51 |
||
371 | 52 |
var cWaterSprCount: LongInt; |
175 | 53 |
Captions: array[TCapGroup] of TCaptionStr; |
371 | 54 |
AMxLeft, AMxCurr, SlotsNum: LongInt; |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
55 |
fpsSurface: PSDL_Surface; |
4 | 56 |
|
57 |
procedure InitWorld; |
|
58 |
begin |
|
74 | 59 |
cWaterSprCount:= 1 + cScreenWidth div (SpritesData[sprWater].Width); |
284 | 60 |
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50); |
74 | 61 |
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2); |
62 |
prevPoint.X:= cScreenWidth div 2; |
|
63 |
prevPoint.Y:= cScreenHeight div 2; |
|
64 |
WorldDx:= - 1024 + cScreenWidth div 2; |
|
161 | 65 |
WorldDy:= - 512 + cScreenHeight div 2; |
66 |
AMxLeft:= cScreenWidth - 210; |
|
67 |
AMxCurr:= cScreenWidth |
|
68 |
end; |
|
69 |
||
70 |
procedure ShowAmmoMenu(Surface: PSDL_Surface); |
|
71 |
const MENUSPEED = 15; |
|
371 | 72 |
var x, y, i, t: LongInt; |
73 |
Slot, Pos: LongInt; |
|
161 | 74 |
begin |
75 |
if (TurnTimeLeft = 0) or KbdKeyPressed then bShowAmmoMenu:= false; |
|
165 | 76 |
if bShowAmmoMenu then |
77 |
begin |
|
78 |
if AMxCurr = cScreenWidth then prevPoint.X:= 0; |
|
79 |
if AMxCurr > AMxLeft then dec(AMxCurr, MENUSPEED); |
|
80 |
end else |
|
81 |
begin |
|
82 |
if AMxCurr = AMxLeft then |
|
83 |
begin |
|
84 |
CursorPoint.X:= cScreenWidth div 2; |
|
85 |
CursorPoint.Y:= cScreenHeight div 2; |
|
86 |
prevPoint:= CursorPoint; |
|
87 |
SDL_WarpMouse(CursorPoint.X, CursorPoint.Y) |
|
88 |
end; |
|
89 |
if AMxCurr < cScreenWidth then inc(AMxCurr, MENUSPEED); |
|
90 |
end; |
|
161 | 91 |
|
92 |
if CurrentTeam = nil then exit; |
|
162 | 93 |
Slot:= 0; |
94 |
Pos:= -1; |
|
602 | 95 |
with CurrentHedgehog^ do |
161 | 96 |
begin |
97 |
if Ammo = nil then exit; |
|
162 | 98 |
SlotsNum:= 0; |
161 | 99 |
x:= AMxCurr; |
100 |
y:= cScreenHeight - 40; |
|
101 |
dec(y); |
|
102 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
|
103 |
dec(y); |
|
104 |
DrawSprite(sprAMBorders, x, y, 1, Surface); |
|
105 |
dec(y, 33); |
|
106 |
DrawSprite(sprAMSlotName, x, y, 0, Surface); |
|
107 |
for i:= cMaxSlotIndex downto 0 do |
|
351 | 108 |
if Ammo^[i, 0].Count > 0 then |
161 | 109 |
begin |
162 | 110 |
if (CursorPoint.Y >= y - 33) and (CursorPoint.Y < y) then Slot:= i; |
161 | 111 |
dec(y, 33); |
162 | 112 |
inc(SlotsNum); |
161 | 113 |
DrawSprite(sprAMSlot, x, y, 0, Surface); |
114 |
DrawSprite(sprAMSlotKeys, x + 2, y + 1, i, Surface); |
|
115 |
t:= 0; |
|
351 | 116 |
while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do |
161 | 117 |
begin |
371 | 118 |
DrawSprite(sprAMAmmos, x + t * 33 + 35, y + 1, LongInt(Ammo^[i, t].AmmoType), Surface); |
162 | 119 |
if (Slot = i) and (CursorPoint.X >= x + t * 33 + 35) and (CursorPoint.X < x + t * 33 + 68) then |
120 |
begin |
|
121 |
DrawSprite(sprAMSelection, x + t * 33 + 35, y + 1, 0, Surface); |
|
122 |
Pos:= t; |
|
123 |
end; |
|
161 | 124 |
inc(t) |
125 |
end |
|
126 |
end; |
|
127 |
dec(y, 1); |
|
162 | 128 |
DrawSprite(sprAMBorders, x, y, 0, Surface); |
129 |
||
130 |
if (Pos >= 0) then |
|
351 | 131 |
if Ammo^[Slot, Pos].Count > 0 then |
162 | 132 |
begin |
351 | 133 |
DXOutText(AMxCurr + 10, cScreenHeight - 68, fnt16, trAmmo[Ammoz[Ammo^[Slot, Pos].AmmoType].NameId], Surface); |
134 |
if Ammo^[Slot, Pos].Count < 10 then |
|
135 |
DXOutText(AMxCurr + 175, cScreenHeight - 68, fnt16, chr(Ammo^[Slot, Pos].Count + 48) + 'x', Surface); |
|
162 | 136 |
if bSelected then |
137 |
begin |
|
165 | 138 |
bShowAmmoMenu:= false; |
351 | 139 |
SetWeapon(Ammo^[Slot, Pos].AmmoType); |
165 | 140 |
bSelected:= false; |
141 |
exit |
|
162 | 142 |
end; |
143 |
end; |
|
144 |
end; |
|
145 |
||
146 |
bSelected:= false; |
|
564 | 147 |
if AMxLeft = AMxCurr then DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
4 | 148 |
end; |
149 |
||
162 | 150 |
procedure MoveCamera; forward; |
151 |
||
371 | 152 |
procedure DrawWorld(Lag: LongInt; Surface: PSDL_Surface); |
153 |
var i, t: LongInt; |
|
4 | 154 |
r: TSDL_Rect; |
107 | 155 |
tdx, tdy: Double; |
175 | 156 |
grp: TCapGroup; |
174 | 157 |
s: string[15]; |
80 | 158 |
|
371 | 159 |
procedure DrawRepeated(spr: TSprite; Shift: LongInt); |
160 |
var i, w: LongInt; |
|
80 | 161 |
begin |
162 |
w:= SpritesData[spr].Width; |
|
82 | 163 |
i:= Shift mod w; |
80 | 164 |
if i > 0 then dec(i, w); |
165 |
repeat |
|
166 |
DrawSprite(spr, i, WorldDy + 1024 - SpritesData[spr].Height, 0, Surface); |
|
167 |
inc(i, w) |
|
168 |
until i > cScreenWidth |
|
169 |
end; |
|
170 |
||
4 | 171 |
begin |
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
172 |
if not isPaused then MoveCamera; |
162 | 173 |
|
5 | 174 |
// Sky |
109 | 175 |
if WorldDy > 0 then |
4 | 176 |
begin |
109 | 177 |
if WorldDy > cScreenHeight then r.h:= cScreenHeight |
178 |
else r.h:= WorldDy; |
|
4 | 179 |
r.x:= 0; |
180 |
r.y:= 0; |
|
181 |
r.w:= cScreenWidth; |
|
182 |
SDL_FillRect(Surface, @r, cSkyColor) |
|
183 |
end; |
|
5 | 184 |
// background |
82 | 185 |
DrawRepeated(sprSky, WorldDx * 3 div 8); |
186 |
DrawRepeated(sprHorizont, WorldDx * 3 div 5); |
|
4 | 187 |
|
5 | 188 |
// Waves |
4 | 189 |
{$WARNINGS OFF} |
564 | 190 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy - 64, 0, Surface); |
191 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 192) and $FF), cWaterLine + WorldDy - 48, 0, Surface); |
|
4 | 192 |
{$WARNINGS ON} |
193 |
||
194 |
DrawLand(WorldDx, WorldDy, Surface); |
|
5 | 195 |
// Water |
4 | 196 |
r.y:= WorldDy + cWaterLine + 32; |
197 |
if r.y < cScreenHeight then |
|
198 |
begin |
|
23 | 199 |
if r.y < 0 then r.y:= 0; |
4 | 200 |
r.h:= cScreenHeight - r.y; |
201 |
r.x:= 0; |
|
202 |
r.w:= cScreenWidth; |
|
203 |
SDL_FillRect(Surface, @r, cWaterColor) |
|
204 |
end; |
|
205 |
||
206 |
DrawGears(Surface); |
|
207 |
||
5 | 208 |
// Waves |
4 | 209 |
{$WARNINGS OFF} |
564 | 210 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) + 64) and $FF), cWaterLine + WorldDy - 32, 0, Surface); |
211 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx - (RealTicks shr 6) + 128) and $FF), cWaterLine + WorldDy - 16, 0, Surface); |
|
212 |
for i:= -1 to cWaterSprCount do DrawSprite(sprWater, i * 256 + ((WorldDx + (RealTicks shr 6) ) and $FF), cWaterLine + WorldDy , 0, Surface); |
|
4 | 213 |
{$WARNINGS ON} |
214 |
||
79 | 215 |
// Turn time |
4 | 216 |
if TurnTimeLeft <> 0 then |
217 |
begin |
|
218 |
i:= Succ(Pred(TurnTimeLeft) div 1000); |
|
219 |
if i>99 then t:= 112 |
|
220 |
else if i>9 then t:= 96 |
|
221 |
else t:= 80; |
|
222 |
DrawSprite(sprFrame, t, cScreenHeight - 48, 1, Surface); |
|
223 |
while i > 0 do |
|
224 |
begin |
|
225 |
dec(t, 32); |
|
226 |
DrawSprite(sprBigDigit, t, cScreenHeight - 48, i mod 10, Surface); |
|
227 |
i:= i div 10 |
|
228 |
end; |
|
229 |
DrawSprite(sprFrame, t - 4, cScreenHeight - 48, 0, Surface); |
|
230 |
end; |
|
79 | 231 |
|
232 |
// Attack bar |
|
4 | 233 |
if CurrentTeam <> nil then |
234 |
case AttackBar of |
|
689 | 235 |
(* 1: begin |
4 | 236 |
r:= StuffPoz[sPowerBar]; |
237 |
{$WARNINGS OFF} |
|
602 | 238 |
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor; |
4 | 239 |
{$WARNINGS ON} |
240 |
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface); |
|
241 |
end; |
|
689 | 242 |
*) 2: with CurrentHedgehog^ do |
74 | 243 |
begin |
351 | 244 |
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle); |
245 |
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle); |
|
246 |
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do |
|
526 | 247 |
DrawSprite(sprPower, hwRound(Gear^.X) + system.round(WorldDx + tdx * (24 + i * 2)) - 16, |
248 |
hwRound(Gear^.Y) + system.round(WorldDy + tdy * (24 + i * 2)) - 12, |
|
74 | 249 |
i, Surface) |
250 |
end |
|
4 | 251 |
end; |
252 |
||
5 | 253 |
// Target |
4 | 254 |
if TargetPoint.X <> NoPointX then DrawSprite(sprTargetP, TargetPoint.X + WorldDx - 16, TargetPoint.Y + WorldDy - 16, 0, Surface); |
255 |
||
256 |
// Captions |
|
175 | 257 |
i:= 8; |
258 |
for grp:= Low(TCapGroup) to High(TCapGroup) do |
|
259 |
with Captions[grp] do |
|
295 | 260 |
if Surf <> nil then |
175 | 261 |
begin |
262 |
DrawCentered(cScreenWidth div 2, i + cConsoleYAdd, Surf, Surface); |
|
351 | 263 |
inc(i, Surf^.h + 2); |
564 | 264 |
if EndTime <= RealTicks then |
175 | 265 |
begin |
266 |
SDL_FreeSurface(Surf); |
|
267 |
Surf:= nil; |
|
268 |
EndTime:= 0 |
|
269 |
end |
|
270 |
end; |
|
4 | 271 |
|
47 | 272 |
// Teams Healths |
547 | 273 |
for t:= 0 to Pred(TeamsCount) do |
274 |
with TeamsArray[t]^ do |
|
47 | 275 |
begin |
547 | 276 |
r.x:= cScreenWidth div 2 - NameTag^.w - 3; |
277 |
r.y:= DrawHealthY; |
|
278 |
r.w:= NameTag^.w; |
|
279 |
r.h:= NameTag^.h; |
|
280 |
SDL_UpperBlit(NameTag, nil, Surface, @r); |
|
690 | 281 |
|
282 |
r.x:= 0; |
|
283 |
r.y:= 0; |
|
547 | 284 |
r.w:= 2 + TeamHealthBarWidth; |
690 | 285 |
r.h:= HealthSurf^.h; |
286 |
||
287 |
DrawFromRect(cScreenWidth div 2, |
|
547 | 288 |
DrawHealthY, |
690 | 289 |
@r, HealthSurf, Surface); |
290 |
||
83 | 291 |
inc(r.x, cTeamHealthWidth + 2); |
292 |
r.w:= 3; |
|
690 | 293 |
|
294 |
DrawFromRect(cScreenWidth div 2 + TeamHealthBarWidth + 2, |
|
547 | 295 |
DrawHealthY, |
690 | 296 |
@r, HealthSurf, Surface); |
47 | 297 |
end; |
298 |
||
5 | 299 |
// Lag alert |
564 | 300 |
if isInLag then DrawSprite(sprLag, 32, 32 + cConsoleYAdd, (RealTicks shr 7) mod 12, Surface); |
4 | 301 |
|
5 | 302 |
// Wind bar |
689 | 303 |
DrawSprite(sprWindBar, cScreenWidth - 180, cScreenHeight - 30, 0, Surface); |
6 | 304 |
if WindBarWidth > 0 then |
5 | 305 |
begin |
689 | 306 |
{$WARNINGS OFF} |
307 |
r.x:= 8 - (RealTicks shr 6) mod 8; |
|
308 |
{$WARNINGS ON} |
|
309 |
r.y:= 0; |
|
310 |
r.w:= WindBarWidth; |
|
311 |
r.h:= 13; |
|
312 |
DrawSpriteFromRect(sprWindR, r, cScreenWidth - 103, cScreenHeight - 28, 13, 0, Surface); |
|
5 | 313 |
end else |
6 | 314 |
if WindBarWidth < 0 then |
5 | 315 |
begin |
689 | 316 |
{$WARNINGS OFF} |
317 |
r.x:= (WindBarWidth + RealTicks shr 6) mod 8; |
|
318 |
{$WARNINGS ON} |
|
319 |
r.y:= 0; |
|
320 |
r.w:= - WindBarWidth; |
|
321 |
r.h:= 13; |
|
322 |
DrawSpriteFromRect(sprWindL, r, cScreenWidth - 106 + WindBarWidth, cScreenHeight - 28, 13, 0, Surface); |
|
5 | 323 |
end; |
324 |
||
161 | 325 |
// AmmoMenu |
326 |
if (AMxCurr < cScreenWidth) or bShowAmmoMenu then ShowAmmoMenu(Surface); |
|
327 |
||
5 | 328 |
// Cursor |
408 | 329 |
if isCursorVisible then |
330 |
begin |
|
331 |
if not bShowAmmoMenu then |
|
602 | 332 |
with CurrentHedgehog^ do |
408 | 333 |
if (Gear^.State and gstHHChooseTarget) <> 0 then |
334 |
begin |
|
335 |
i:= Ammo^[CurSlot, CurAmmo].Pos; |
|
336 |
with Ammoz[Ammo^[CurSlot, CurAmmo].AmmoType] do |
|
337 |
if PosCount > 1 then |
|
338 |
DrawSprite(PosSprite, CursorPoint.X - SpritesData[PosSprite].Width div 2, |
|
339 |
CursorPoint.Y - SpritesData[PosSprite].Height div 2, |
|
340 |
i, Surface); |
|
341 |
end; |
|
564 | 342 |
DrawSprite(sprArrow, CursorPoint.X, CursorPoint.Y, (RealTicks shr 6) mod 8, Surface) |
408 | 343 |
end; |
4 | 344 |
|
345 |
{$IFDEF COUNTTICKS} |
|
346 |
DXOutText(10, 10, fnt16, inttostr(cntTicks), Surface); |
|
347 |
{$ENDIF} |
|
348 |
||
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
349 |
if isPaused then DrawCentered(cScreenWidth div 2, cScreenHeight div 2, PauseSurface, Surface); |
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
244
diff
changeset
|
350 |
|
4 | 351 |
inc(Frames); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
352 |
if cShowFPS then |
4 | 353 |
begin |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
354 |
inc(CountTicks, Lag); |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
355 |
if CountTicks >= 1000 then |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
356 |
begin |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
357 |
FPS:= Frames; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
358 |
Frames:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
359 |
CountTicks:= 0; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
360 |
s:= inttostr(FPS) + ' fps'; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
361 |
if fpsSurface <> nil then SDL_FreeSurface(fpsSurface); |
351 | 362 |
fpsSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), $FFFFFF); |
298
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
363 |
end; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
364 |
r.x:= cScreenWidth - 50; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
365 |
r.y:= 10; |
112e61bd2cc2
Render FPS value to its own surface one time a second
unc0rr
parents:
295
diff
changeset
|
366 |
SDL_UpperBlit(fpsSurface, nil, Surface, @r) |
4 | 367 |
end; |
174 | 368 |
|
369 |
inc(SoundTimerTicks, Lag); |
|
370 |
if SoundTimerTicks >= 50 then |
|
371 |
begin |
|
372 |
SoundTimerTicks:= 0; |
|
373 |
if cVolumeDelta <> 0 then |
|
374 |
begin |
|
375 |
str(ChangeVolume(cVolumeDelta), s); |
|
175 | 376 |
AddCaption(Format(trmsg[sidVolume], s), $FFFFFF, capgrpVolume) |
174 | 377 |
end |
378 |
end |
|
4 | 379 |
end; |
380 |
||
108 | 381 |
procedure AddCaption(s: string; Color: Longword; Group: TCapGroup); |
4 | 382 |
begin |
83 | 383 |
if Group in [capgrpGameState, capgrpNetSay] then WriteLnToConsole(s); |
175 | 384 |
if Captions[Group].Surf <> nil then SDL_FreeSurface(Captions[Group].Surf); |
4 | 385 |
|
175 | 386 |
Captions[Group].Surf:= RenderString(s, Color, fntBig); |
564 | 387 |
Captions[Group].EndTime:= RealTicks + 1500 |
4 | 388 |
end; |
389 |
||
79 | 390 |
procedure MoveCamera; |
4 | 391 |
const PrevSentPointTime: LongWord = 0; |
371 | 392 |
var EdgesDist: LongInt; |
4 | 393 |
begin |
678 | 394 |
if (not (CurrentTeam^.ExtDriven and isCursorVisible)) |
395 |
and cHasFocus then SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y); |
|
396 |
||
4 | 397 |
if (FollowGear <> nil) then |
57 | 398 |
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then |
4 | 399 |
begin |
400 |
FollowGear:= nil; |
|
401 |
exit |
|
402 |
end |
|
403 |
else begin |
|
678 | 404 |
CursorPoint.x:= (prevPoint.x * 7 + (hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100) + WorldDx) div 8; |
405 |
CursorPoint.y:= (prevPoint.y * 7 + (hwRound(FollowGear^.Y) + WorldDy)) div 8 |
|
4 | 406 |
end; |
407 |
||
408 |
if ((CursorPoint.X = prevPoint.X)and(CursorPoint.Y = prevpoint.Y)) then exit; |
|
409 |
||
162 | 410 |
if AMxCurr < cScreenWidth then |
411 |
begin |
|
412 |
if CursorPoint.X < AMxCurr + 35 then CursorPoint.X:= AMxCurr + 35; |
|
413 |
if CursorPoint.X > AMxCurr + 200 then CursorPoint.X:= AMxCurr + 200; |
|
414 |
if CursorPoint.Y < cScreenHeight - 75 - SlotsNum * 33 then CursorPoint.Y:= cScreenHeight - 75 - SlotsNum * 33; |
|
415 |
if CursorPoint.Y > cScreenHeight - 76 then CursorPoint.Y:= cScreenHeight - 76; |
|
416 |
prevPoint:= CursorPoint; |
|
308 | 417 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
162 | 418 |
exit |
419 |
end; |
|
420 |
||
4 | 421 |
if isCursorVisible then |
422 |
begin |
|
351 | 423 |
if (not CurrentTeam^.ExtDriven)and(GameTicks >= PrevSentPointTime + cSendCursorPosTime) then |
4 | 424 |
begin |
154
5667e6f38704
Network protocol uses integers in network byte order
unc0rr
parents:
146
diff
changeset
|
425 |
SendIPCXY('P', CursorPoint.X - WorldDx, CursorPoint.Y - WorldDy); |
4 | 426 |
PrevSentPointTime:= GameTicks |
427 |
end; |
|
428 |
end; |
|
351 | 429 |
|
4 | 430 |
if isCursorVisible or (FollowGear <> nil) then |
431 |
begin |
|
284 | 432 |
if isCursorVisible then EdgesDist:= cCursorEdgesDist |
433 |
else EdgesDist:= cGearScrEdgesDist; |
|
434 |
if CursorPoint.X < EdgesDist then |
|
4 | 435 |
begin |
284 | 436 |
WorldDx:= WorldDx - CursorPoint.X + EdgesDist; |
437 |
CursorPoint.X:= EdgesDist |
|
4 | 438 |
end else |
284 | 439 |
if CursorPoint.X > cScreenWidth - EdgesDist then |
4 | 440 |
begin |
284 | 441 |
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth - EdgesDist; |
442 |
CursorPoint.X:= cScreenWidth - EdgesDist |
|
4 | 443 |
end; |
284 | 444 |
if CursorPoint.Y < EdgesDist then |
4 | 445 |
begin |
284 | 446 |
WorldDy:= WorldDy - CursorPoint.Y + EdgesDist; |
447 |
CursorPoint.Y:= EdgesDist |
|
4 | 448 |
end else |
284 | 449 |
if CursorPoint.Y > cScreenHeight - EdgesDist then |
4 | 450 |
begin |
284 | 451 |
WorldDy:= WorldDy - CursorPoint.Y + cScreenHeight - EdgesDist; |
452 |
CursorPoint.Y:= cScreenHeight - EdgesDist |
|
4 | 453 |
end; |
454 |
end else |
|
308 | 455 |
if cHasFocus then |
456 |
begin |
|
70 | 457 |
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X; |
458 |
WorldDy:= WorldDy - CursorPoint.Y + prevPoint.Y; |
|
4 | 459 |
CursorPoint.X:= (cScreenWidth shr 1); |
460 |
CursorPoint.Y:= (cScreenHeight shr 1); |
|
308 | 461 |
end; |
351 | 462 |
|
308 | 463 |
if cHasFocus then SDL_WarpMouse(CursorPoint.X, CursorPoint.Y); |
4 | 464 |
prevPoint:= CursorPoint; |
75 | 465 |
if WorldDy < cScreenHeight - cWaterLine - cVisibleWater then WorldDy:= cScreenHeight - cWaterLine - cVisibleWater; |
4 | 466 |
if WorldDy > 2048 then WorldDy:= 2048; |
467 |
if WorldDx < -2048 then WorldDx:= -2048; |
|
468 |
if WorldDx > cScreenWidth then WorldDx:= cScreenWidth; |
|
469 |
end; |
|
470 |
||
471 |
initialization |
|
472 |
FillChar(Captions, sizeof(Captions), 0) |
|
473 |
||
474 |
end. |