2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2004-2010 Andrey Korotaev <unC0Rr@gmail.com>
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
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.
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
19
{$INCLUDE "options.inc"}
23
uses SDLh, uGears, uConsts, uFloat, uRandom;
26
var FollowGear: PGear;
27
WindBarWidth: LongInt;
28
bShowAmmoMenu: boolean;
32
WaterColor, DeepWaterColor: TSDL_Color;
36
HorizontOffset: LongInt;
46
procedure DrawWorld(Lag: LongInt);
47
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
48
procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
49
procedure HideMission;
50
procedure ShakeCamera(amount: LongWord);
54
uses uStore, uMisc, uTeams, uIO, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand, GLunit;
56
type TCaptionStr = record
61
var cWaveWidth, cWaveHeight: LongInt;
62
Captions: array[TCapGroup] of TCaptionStr;
63
AMSlotSize, AMxOffset, AMyOffset, AMWidth, AMxShift, SlotsNum: LongInt;
64
tmpSurface: PSDL_Surface;
66
timeTexture: PTexture;
69
SoundTimerTicks: Longword;
71
amSel: TAmmoType = amNothing;
73
missionTimer: LongInt;
80
// helper functions to create the goal/game mode string
81
function AddGoal(s: ansistring; gf: longword; si: TGoalStrId; i: LongInt): ansistring;
84
if (GameFlags and gf) <> 0 then
87
s:= s + format(trgoal[si], t) + '|'
92
function AddGoal(s: ansistring; gf: longword; si: TGoalStrId): ansistring;
94
if (GameFlags and gf) <> 0 then
95
s:= s + trgoal[si] + '|';
101
if (GameFlags and gfRandomOrder) <> 0 then // shuffle them up a bit
103
for i:= 0 to ClansCount * 4 do
105
t:= GetRandom(ClansCount);
109
ClansArray[0]:= ClansArray[t];
111
ClansArray[t]^.ClanIndex:= t;
112
ClansArray[0]^.ClanIndex:= 0;
113
if (LocalClan = t) then LocalClan:= 0
114
else if (LocalClan = 0) then LocalClan:= t
117
CurrentTeam:= ClansArray[0]^.Teams[0];
120
// if special game flags/settings are changed, add them to the game mode notice window and then show it
121
g:= ''; // no text/things to note yet
123
// check different game flags (goals/game modes first for now)
124
g:= AddGoal(g, gfKing, gidKing); // king?
126
// other important flags
127
g:= AddGoal(g, gfForts, gidForts); // forts?
128
g:= AddGoal(g, gfLowGravity, gidLowGravity); // low gravity?
129
g:= AddGoal(g, gfInvulnerable, gidInvulnerable); // invulnerability?
130
g:= AddGoal(g, gfVampiric, gidVampiric); // vampirism?
131
g:= AddGoal(g, gfKarma, gidKarma); // karma?
132
g:= AddGoal(g, gfPlaceHog, gidPlaceHog); // placement?
133
g:= AddGoal(g, gfArtillery, gidArtillery); // artillery?
134
g:= AddGoal(g, gfSolidLand, gidSolidLand); // solid land?
135
g:= AddGoal(g, gfSharedAmmo, gidSharedAmmo); // shared ammo?
136
g:= AddGoal(g, gfResetHealth, gidResetHealth);
137
g:= AddGoal(g, gfAISurvival, gidAISurvival);
138
g:= AddGoal(g, gfInfAttack, gidInfAttack);
139
g:= AddGoal(g, gfResetWeps, gidResetWeps);
140
g:= AddGoal(g, gfPerHogAmmo, gidPerHogAmmo);
142
// modified damage modificator?
143
if cDamagePercent <> 100 then
144
g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
147
ScreenFade:= sfFromBlack;
148
ScreenFadeValue:= sfMax;
151
// modified mine timers?
152
if cMinesTime <> 3000 then
154
if cMinesTime = 0 then
155
g:= AddGoal(g, gfAny, gidNoMineTimer)
156
else if cMinesTime < 0 then
157
g:= AddGoal(g, gfAny, gidRandomMineTimer)
159
g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime div 1000);
162
// if the string has been set, show it for (default timeframe) seconds
163
if g <> '' then ShowMission(trgoal[gidCaption], trgoal[gidSubCaption], g, 1, 0);
165
cWaveWidth:= SpritesData[sprWater].Width;
166
//cWaveHeight:= SpritesData[sprWater].Height;
169
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50);
170
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
172
prevPoint.Y:= cScreenHeight div 2;
173
WorldDx:= - (LAND_WIDTH div 2) + cScreenWidth div 2;
174
WorldDy:= - (LAND_HEIGHT - (playHeight div 2)) + (cScreenHeight div 2);
178
AMyOffset:= 10 + 123; // moved downwards
179
AMWidth:= (cMaxSlotAmmoIndex + 1) * AMSlotSize + AMxOffset;
183
AMWidth:= (cMaxSlotAmmoIndex + 2) * AMSlotSize + AMxOffset;
191
procedure ShowAmmoMenu;
192
const MENUSPEED = 15;
193
const BORDERSIZE = 2;
194
var x, y, i, t, g: LongInt;
195
Slot, Pos, STurns: LongInt;
198
if (TurnTimeLeft = 0) or (not CurrentTeam^.ExtDriven and (((CurAmmoGear = nil) or ((Ammoz[CurAmmoGear^.AmmoType].Ammo.Propz and ammoprop_AltAttack) = 0)) and hideAmmoMenu)) then
199
bShowAmmoMenu:= false;
200
if bShowAmmoMenu then
203
if AMxShift = AMWidth then prevPoint.X:= 0;
204
if (cReducedQuality and rqSlowMenu) <> 0 then
207
if AMxShift > MENUSPEED then
208
dec(AMxShift, MENUSPEED)
215
CursorPoint.X:= cScreenWidth shr 1;
216
CursorPoint.Y:= cScreenHeight shr 1;
217
prevPoint:= CursorPoint;
218
SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y)
220
if (cReducedQuality and rqSlowMenu) <> 0 then
223
if AMxShift < (AMWidth - MENUSPEED) then
224
inc(AMxShift, MENUSPEED)
229
if (CurrentTeam <> nil) and (CurrentHedgehog <> nil) and (not CurrentTeam^.ExtDriven) and (CurrentHedgehog^.BotLevel = 0) then
230
Ammo:= CurrentHedgehog^.Ammo
231
else if (LocalAmmo <> -1) then
232
Ammo:= GetAmmoByNum(LocalAmmo);
236
bShowAmmoMenu:= false;
240
x:= (cScreenWidth shr 1) - AMWidth + AMxShift;
243
Slot:= cMaxSlotIndex;
247
DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
248
for i:= 0 to cMaxSlotAmmoIndex do
249
DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
250
DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 1);
253
for i:= 0 to cMaxSlotIndex do
254
if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
256
if (cScreenHeight - CursorPoint.Y >= y) and (cScreenHeight - CursorPoint.Y <= y + AMSlotSize) then Slot:= i;
258
DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
261
while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
263
DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
264
if (Ammo^[i, t].AmmoType <> amNothing) then
266
STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
270
DrawSprite(sprAMAmmosBW, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
271
if STurns < 100 then DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns);
273
DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
275
and (CursorPoint.X >= x + g * AMSlotSize)
276
and (CursorPoint.X <= x + (g + 1) * AMSlotSize) then
278
if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
285
for g:= g to cMaxSlotAmmoIndex do
286
DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
287
DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
291
DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2);
292
for i:= 0 to cMaxSlotAmmoIndex do
293
DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
294
DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3);
297
y:= cScreenHeight - AMyOffset;
298
DrawSprite(sprAMCorners, x - BORDERSIZE, y, 2);
299
for i:= 0 to cMaxSlotAmmoIndex + 1 do
300
DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 1);
301
DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 3);
303
DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
304
for i:= 0 to cMaxSlotAmmoIndex do
305
DrawSprite(sprAMSlot, x + i * AMSlotSize, y, 2);
306
DrawSprite(sprAMSlot, x + (cMaxSlotAmmoIndex + 1) * AMSlotSize, y, 1);
307
DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
309
for i:= cMaxSlotIndex downto 0 do
310
if ((i = 0) and (Ammo^[i, 1].Count > 0)) or ((i <> 0) and (Ammo^[i, 0].Count > 0)) then
312
if (cScreenHeight - CursorPoint.Y >= y - AMSlotSize) and (cScreenHeight - CursorPoint.Y <= y) then Slot:= i;
315
DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
316
DrawSprite(sprAMSlot, x, y, 1);
317
DrawSprite(sprAMSlotKeys, x, y + 1, i);
320
while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
322
DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
323
if (Ammo^[i, t].AmmoType <> amNothing) then
325
STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
329
DrawSprite(sprAMAmmosBW, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
330
if STurns < 100 then DrawSprite(sprTurnsLeft, x + (g + 1) * AMSlotSize - 16, y + AMSlotSize - 16, STurns);
332
DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
334
and (CursorPoint.X >= x + g * AMSlotSize)
335
and (CursorPoint.X <= x + (g + 1) * AMSlotSize) then
337
if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
344
for g:= g to cMaxSlotAmmoIndex + 1 do
345
DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
346
DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
350
DrawSprite(sprAMCorners, x - BORDERSIZE, y, 0);
351
for i:= 0 to cMaxSlotAmmoIndex + 1 do
352
DrawSprite(sprAMBorderHorizontal, x + i * AMSlotSize, y, 0);
353
DrawSprite(sprAMCorners, x + AMWidth - AMxOffset, y, 1);
358
if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
360
if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
362
amSel:= Ammo^[Slot, Pos].AmmoType;
363
RenderWeaponTooltip(amSel)
367
DrawTexture(cScreenWidth div 2 - (AMWidth - 10) + AMxShift, AMyOffset - 25, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
369
if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
370
DrawTexture(cScreenWidth div 2 + AMxOffset - 45, AMyOffset - 25, CountTexz[Ammo^[Slot, Pos].Count]);
372
DrawTexture(cScreenWidth div 2 - (AMWidth - 10) + AMxShift, cScreenHeight - AMyOffset - 25, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
373
if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
374
DrawTexture(cScreenWidth div 2 + AMxOffset - 45, cScreenHeight - AMyOffset - 25, CountTexz[Ammo^[Slot, Pos].Count]);
377
if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
379
bShowAmmoMenu:= false;
380
SetWeapon(Ammo^[Slot, Pos].AmmoType);
389
if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
391
ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1);
393
ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
397
if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
400
procedure DrawWater(Alpha: byte; OffsetY: LongInt);
401
var VertexBuffer: array [0..3] of TVertex2f;
405
WaterColorArray[0].a := Alpha;
406
WaterColorArray[1].a := Alpha;
407
WaterColorArray[2].a := Alpha;
408
WaterColorArray[3].a := Alpha;
410
lw:= cScreenWidth / cScaleFactor;
411
lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
414
r.y:= OffsetY + WorldDy + cWaterLine;
415
if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
420
glDisable(GL_TEXTURE_2D);
421
VertexBuffer[0].X:= -lw;
422
VertexBuffer[0].Y:= r.y;
423
VertexBuffer[1].X:= lw;
424
VertexBuffer[1].Y:= r.y;
425
VertexBuffer[2].X:= lw;
426
VertexBuffer[2].Y:= lh;
427
VertexBuffer[3].X:= -lw;
428
VertexBuffer[3].Y:= lh;
430
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
431
glEnableClientState(GL_COLOR_ARRAY);
432
glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
434
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
436
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
438
glDisableClientState(GL_COLOR_ARRAY);
439
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
440
glColor4ub($FF, $FF, $FF, $FF); // must not be Tint() as color array seems to stay active and color reset is required
441
glEnable(GL_TEXTURE_2D);
445
procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
446
var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
447
lw, waves, shift: GLfloat;
449
lw:= cScreenWidth / cScaleFactor;
450
waves:= lw * 2 / cWaveWidth;
452
Tint(LongInt(tnt) * WaterColorArray[2].r div 255 + 255 - tnt,
453
LongInt(tnt) * WaterColorArray[2].g div 255 + 255 - tnt,
454
LongInt(tnt) * WaterColorArray[2].b div 255 + 255 - tnt,
458
glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
460
VertexBuffer[0].X:= -lw;
461
VertexBuffer[0].Y:= cWaterLine + WorldDy + dY;
462
VertexBuffer[1].X:= lw;
463
VertexBuffer[1].Y:= VertexBuffer[0].Y;
464
VertexBuffer[2].X:= lw;
465
VertexBuffer[2].Y:= VertexBuffer[0].Y + SpritesData[sprWater].Height;
466
VertexBuffer[3].X:= -lw;
467
VertexBuffer[3].Y:= VertexBuffer[2].Y;
469
shift:= - lw / cWaveWidth;
470
TextureBuffer[0].X:= shift + (( - WorldDx + LongInt(RealTicks shr 6) * Dir + dX) mod cWaveWidth) / (cWaveWidth - 1);
471
TextureBuffer[0].Y:= 0;
472
TextureBuffer[1].X:= TextureBuffer[0].X + waves;
473
TextureBuffer[1].Y:= TextureBuffer[0].Y;
474
TextureBuffer[2].X:= TextureBuffer[1].X;
475
TextureBuffer[2].Y:= SpritesData[sprWater].Texture^.ry;
476
TextureBuffer[3].X:= TextureBuffer[0].X;
477
TextureBuffer[3].Y:= TextureBuffer[2].Y;
480
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
481
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
482
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
484
Tint($FF, $FF, $FF, $FF);
486
{for i:= -1 to cWaterSprCount do
488
i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
489
cWaterLine + WorldDy + dY,
493
procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt);
494
var i, w, h, lw, lh, rw, rh, sw: LongInt;
496
sw:= round(cScreenWidth / cScaleFactor);
497
if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
499
w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
500
h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
502
if i > 0 then dec(i, w);
503
dec(i, w * (sw div w + 1));
505
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
511
w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
512
h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
513
lw:= SpritesData[sprL].Width * SpritesData[spr].Texture^.Scale;
514
lh:= SpritesData[sprL].Height * SpritesData[spr].Texture^.Scale;
515
rw:= SpritesData[sprR].Width * SpritesData[spr].Texture^.Scale;
516
rh:= SpritesData[sprR].Height * SpritesData[spr].Texture^.Scale;
518
DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
521
while i >= -sw - lw do
523
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
530
DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
537
procedure DrawWorld(Lag: LongInt);
544
offset, offsetX, offsetY, ScreenBottom: LongInt;
545
VertexBuffer: array [0..3] of TVertex2f;
549
if ZoomValue < zoom then
551
zoom:= zoom - 0.002 * Lag;
552
if ZoomValue > zoom then
556
if ZoomValue > zoom then
558
zoom:= zoom + 0.002 * Lag;
559
if ZoomValue < zoom then
567
glClear(GL_COLOR_BUFFER_BIT);
569
//glScalef(1.0, 1.0, 1.0);
574
if (cReducedQuality and rqNoBackground) = 0 then
576
// Offsets relative to camera - spare them to wimpier cpus, no bg or flakes for them anyway
577
ScreenBottom:= (WorldDy - trunc(cScreenHeight/cScaleFactor) - (cScreenHeight div 2) + cWaterLine);
578
offsetY:= 10 * min(0, -145 - ScreenBottom);
579
SkyOffset:= offsetY div 35 + cWaveHeight;
580
HorizontOffset:= SkyOffset;
581
if ScreenBottom > SkyOffset then
582
HorizontOffset:= HorizontOffset + ((ScreenBottom-SkyOffset) div 20);
585
DrawRepeated(sprSky, sprSkyL, sprSkyR, (WorldDx + LAND_WIDTH div 2) * 3 div 8, SkyOffset);
586
DrawRepeated(sprHorizont, sprHorizontL, sprHorizontR, (WorldDx + LAND_WIDTH div 2) * 3 div 5, HorizontOffset);
591
if (cReducedQuality and rq2DWater) = 0 then
594
DrawWater(255, SkyOffset);
595
DrawWaves( 1, 0 - WorldDx div 32, - cWaveHeight + offsetY div 35, 64);
596
DrawWaves( -1, 25 + WorldDx div 25, - cWaveHeight + offsetY div 38, 48);
597
DrawWaves( 1, 75 - WorldDx div 19, - cWaveHeight + offsetY div 45, 32);
598
DrawWaves(-1, 100 + WorldDx div 14, - cWaveHeight + offsetY div 70, 24);
601
DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0);
603
DrawLand(WorldDx, WorldDy);
608
if CurrentTeam <> nil then
611
r:= StuffPoz[sPowerBar];
613
r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
615
DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
617
2: with CurrentHedgehog^ do
619
tdx:= hwSign(Gear^.dX) * Sin(Gear^.Angle * Pi / cMaxAngle);
620
tdy:= - Cos(Gear^.Angle * Pi / cMaxAngle);
621
for i:= (Gear^.Power * 24) div cPowerDivisor downto 0 do
623
hwRound(Gear^.X) + GetLaunchX(CurAmmoType, hwSign(Gear^.dX), Gear^.Angle) + LongInt(round(WorldDx + tdx * (24 + i * 2))) - 16,
624
hwRound(Gear^.Y) + GetLaunchY(CurAmmoType, Gear^.Angle) + LongInt(round(WorldDy + tdy * (24 + i * 2))) - 16,
635
DrawWater(cWaterOpacity, 0);
638
DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12);
640
if (cReducedQuality and rq2DWater) = 0 then
642
//DrawWater(cWaterOpacity, - offsetY div 40);
643
DrawWaves(-1, 50 + WorldDx div 6, - cWaveHeight - offsetY div 40, 8);
644
DrawWater(cWaterOpacity, - offsetY div 20);
645
DrawWaves( 1, 75 - WorldDx div 4, - cWaveHeight - offsetY div 20, 2);
646
DrawWater(cWaterOpacity, - offsetY div 10);
647
DrawWaves( -1, 25 + WorldDx div 3, - cWaveHeight - offsetY div 10, 0);
650
DrawWaves(-1, 50, - (cWaveHeight shr 1), 0);
655
if (TargetPoint.X <> NoPointX) and (CurrentTeam <> nil) and (CurrentHedgehog <> nil) then
657
with PHedgehog(CurrentHedgehog)^ do
659
if (CurAmmoType = amBee) then
660
DrawRotatedF(sprTargetBee, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360)
662
DrawRotatedF(sprTargetP, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
667
// this scale is used to keep the various widgets at the same dimension at all zoom levels
668
SetScale(cDefaultZoomLevel);
673
offsetX:= cScreenHeight - 13;
678
if ((TurnTimeLeft <> 0) and (TurnTimeLeft < 1000000)) or (ReadyTimeLeft <> 0) then
680
if ReadyTimeLeft <> 0 then
681
i:= Succ(Pred(ReadyTimeLeft) div 1000)
683
i:= Succ(Pred(TurnTimeLeft) div 1000);
686
else if i>9 then t:= 96
688
DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
692
DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
695
DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
700
if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
702
if TimeTrialStopTime = 0 then i:= RealTicks - TimeTrialStartTime else i:= TimeTrialStopTime - TimeTrialStartTime;
705
DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
708
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
712
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
716
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
719
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 11);
723
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
727
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 6);
730
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 10);
734
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
738
DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
740
DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0);
748
if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48
752
for grp:= Low(TCapGroup) to High(TCapGroup) do
753
with Captions[grp] do
756
DrawCentered(0, offset, Tex);
757
inc(offset, Tex^.h + 2);
758
if EndTime <= RealTicks then
767
for t:= 0 to Pred(TeamsCount) do
768
with TeamsArray[t]^ do
770
highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
776
DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY, NameTagTex);
779
DrawTexture(-14, cScreenHeight + DrawHealthY, FlagTex);
784
r.w:= 2 + TeamHealthBarWidth;
786
DrawFromRect(14, cScreenHeight + DrawHealthY, @r, HealthTex);
788
// draw health bar's right border
789
inc(r.x, cTeamHealthWidth + 2);
791
DrawFromRect(TeamHealthBarWidth + 16, cScreenHeight + DrawHealthY, @r, HealthTex);
793
// draw ai kill counter for gfAISurvival
794
if (GameFlags and gfAISurvival) <> 0 then begin
795
DrawTexture(TeamHealthBarWidth + 22, cScreenHeight + DrawHealthY,
799
// if highlighted, draw flag and other contents again to keep their colors
800
// this approach should be faster than drawing all borders one by one tinted or not
803
Tint($FF, $FF, $FF, $FF);
808
r.w:= NameTagTex^.w - 4;
809
r.h:= NameTagTex^.h - 4;
810
DrawFromRect(-NameTagTex^.w - 14, cScreenHeight + DrawHealthY + 2, @r, NameTagTex);
814
DrawFromRect(-12, cScreenHeight + DrawHealthY + 2, @r, FlagTex);
816
r.w:= TeamHealthBarWidth + 1;
817
r.h:= HealthTex^.h - 4;
818
DrawFromRect(16, cScreenHeight + DrawHealthY + 2, @r, HealthTex);
823
if isInLag then DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12);
827
offsetX:= cScreenHeight - 13;
828
offsetY:= (cScreenWidth shr 1) + 74;
833
DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0);
834
if WindBarWidth > 0 then
837
r.x:= 8 - (RealTicks shr 6) mod 8;
842
DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0);
845
if WindBarWidth < 0 then
848
r.x:= (Longword(WindBarWidth) + RealTicks shr 6) mod 8;
851
r.w:= - WindBarWidth;
853
DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
857
if (AMxShift < AMWidth) or bShowAmmoMenu then ShowAmmoMenu;
860
if isCursorVisible and bShowAmmoMenu then
861
DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
865
if fastUntilLag then DrawCentered(0, (cScreenHeight shr 1), SyncTexture);
866
if isPaused then DrawCentered(0, (cScreenHeight shr 1), PauseTexture);
867
if not isFirstFrame and (missionTimer <> 0) or isPaused or fastUntilLag or (GameState = gsConfirm) then
869
if (ReadyTimeLeft = 0) and (missionTimer > 0) then dec(missionTimer, Lag);
870
if missionTimer < 0 then missionTimer:= 0; // avoid subtracting below 0
871
if missionTex <> nil then
872
DrawCentered(0, min((cScreenHeight shr 1) + 100, cScreenHeight - 48 - missionTex^.h), missionTex);
884
if cShowFPS or (GameType = gmtDemo) then inc(CountTicks, Lag);
885
if (GameType = gmtDemo) and (CountTicks >= 1000) then
887
i:=GameTicks div 1000;
890
if t < 10 then s:= '0' + s;
893
s:= inttostr(t) + ':' + s;
894
if t < 10 then s:= '0' + s;
895
s:= inttostr(i div 60) + ':' + s;
897
if timeTexture <> nil then
898
FreeTexture(timeTexture);
901
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
902
tmpSurface:= doSurfaceConversion(tmpSurface);
903
timeTexture:= Surface2Tex(tmpSurface, false);
904
SDL_FreeSurface(tmpSurface)
907
if timeTexture <> nil then
908
DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture);
912
if CountTicks >= 1000 then
917
s:= inttostr(FPS) + ' fps';
918
if fpsTexture <> nil then
919
FreeTexture(fpsTexture);
921
tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
922
tmpSurface:= doSurfaceConversion(tmpSurface);
923
fpsTexture:= Surface2Tex(tmpSurface, false);
924
SDL_FreeSurface(tmpSurface)
926
if fpsTexture <> nil then
927
DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
930
if CountTicks >= 1000 then CountTicks:= 0;
933
inc(SoundTimerTicks, Lag);
934
if SoundTimerTicks >= 50 then
937
if cVolumeDelta <> 0 then
939
str(ChangeVolume(cVolumeDelta), s);
940
AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
944
if GameState = gsConfirm then
945
DrawCentered(0, (cScreenHeight shr 1), ConfirmTexture);
947
if ScreenFade <> sfNone then
949
if not isFirstFrame then
951
sfToBlack, sfToWhite: if ScreenFadeValue + Lag * ScreenFadeSpeed < sfMax then
952
inc(ScreenFadeValue, Lag * ScreenFadeSpeed)
954
ScreenFadeValue:= sfMax;
955
sfFromBlack, sfFromWhite: if ScreenFadeValue - Lag * ScreenFadeSpeed > 0 then
956
dec(ScreenFadeValue, Lag * ScreenFadeSpeed)
960
if ScreenFade <> sfNone then
963
sfToBlack, sfFromBlack: Tint(0, 0, 0, ScreenFadeValue * 255 div 1000);
964
sfToWhite, sfFromWhite: Tint($FF, $FF, $FF, ScreenFadeValue * 255 div 1000);
967
VertexBuffer[0].X:= -cScreenWidth;
968
VertexBuffer[0].Y:= cScreenHeight;
969
VertexBuffer[1].X:= -cScreenWidth;
970
VertexBuffer[1].Y:= 0;
971
VertexBuffer[2].X:= cScreenWidth;
972
VertexBuffer[2].Y:= 0;
973
VertexBuffer[3].X:= cScreenWidth;
974
VertexBuffer[3].Y:= cScreenHeight;
976
glDisable(GL_TEXTURE_2D);
978
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
979
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
981
glEnable(GL_TEXTURE_2D);
982
Tint($FF, $FF, $FF, $FF);
983
if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then ScreenFade:= sfNone
990
if isCursorVisible then
992
if not bShowAmmoMenu then
994
with CurrentHedgehog^ do
995
if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then
997
i:= GetAmmoEntry(CurrentHedgehog^)^.Pos;
998
with Ammoz[CurAmmoType] do
1000
DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
1002
DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
1005
isFirstFrame:= false
1008
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
1010
//if Group in [capgrpGameState] then WriteLnToConsole(s);
1011
if Captions[Group].Tex <> nil then
1012
FreeTexture(Captions[Group].Tex);
1013
Captions[Group].Tex:= nil;
1015
Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
1018
capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
1020
Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
1024
procedure MoveCamera;
1025
var EdgesDist, wdy: LongInt;
1026
PrevSentPointTime: LongWord = 0;
1029
if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus then
1031
SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
1032
CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
1033
CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
1037
if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
1038
if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
1041
prevPoint:= CursorPoint;
1046
CursorPoint.X:= (prevPoint.X * 7 + hwRound(FollowGear^.X) + hwSign(FollowGear^.dX) * 100 + WorldDx) div 8;
1047
CursorPoint.Y:= (prevPoint.Y * 7 + cScreenHeight - (hwRound(FollowGear^.Y) + WorldDy)) div 8;
1050
wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
1051
if WorldDy < wdy then WorldDy:= wdy;
1053
if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
1055
if AMxShift < AMWidth then
1058
if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth;
1059
if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
1060
if CursorPoint.Y < cScreenHeight - AMyOffset - SlotsNum * AMSlotSize then CursorPoint.Y:= cScreenHeight - AMyOffset - SlotsNum * AMSlotSize;
1061
if CursorPoint.Y > cScreenHeight - AMyOffset then CursorPoint.Y:= cScreenHeight - AMyOffset;
1063
if CursorPoint.X < cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMWidth + AMSlotSize;
1064
if CursorPoint.X > cScreenWidth div 2 + AMxShift - AMxOffset then CursorPoint.X:= cScreenWidth div 2 + AMxShift - AMxOffset;
1065
if CursorPoint.Y > AMyOffset + (SlotsNum + 1) * AMSlotSize then CursorPoint.Y:= AMyOffset + (SlotsNum + 1) * AMSlotSize;
1066
if CursorPoint.Y < AMyOffset + AMSlotSize then CursorPoint.Y:= AMyOffset + AMSlotSize;
1068
prevPoint:= CursorPoint;
1069
if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
1073
if isCursorVisible then
1075
if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
1077
SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
1078
PrevSentPointTime:= GameTicks
1080
EdgesDist:= cCursorEdgesDist
1083
EdgesDist:= cGearScrEdgesDist;
1085
// this generates the border around the screen that moves the camera when cursor is near it
1086
if isCursorVisible or (FollowGear <> nil) then
1088
if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
1090
WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
1091
CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
1094
if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
1096
WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
1097
CursorPoint.X:= cScreenWidth div 2 - EdgesDist
1099
if CursorPoint.Y < EdgesDist then
1101
WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
1102
CursorPoint.Y:= EdgesDist
1105
if CursorPoint.Y > cScreenHeight - EdgesDist then
1107
WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
1108
CursorPoint.Y:= cScreenHeight - EdgesDist
1114
WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
1115
WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
1117
CursorPoint.Y:= cScreenHeight div 2;
1120
// this moves the camera according to CursorPoint X and Y
1121
prevPoint:= CursorPoint;
1122
if cHasFocus then SDL_WarpMouse(CursorPoint.X + (cScreenWidth shr 1), cScreenHeight - CursorPoint.Y);
1123
if WorldDy > LAND_HEIGHT + 1024 then WorldDy:= LAND_HEIGHT + 1024;
1124
if WorldDy < wdy then WorldDy:= wdy;
1125
if WorldDx < - LAND_WIDTH - 1024 then WorldDx:= - LAND_WIDTH - 1024;
1126
if WorldDx > 1024 then WorldDx:= 1024;
1129
procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
1135
if time = 0 then time:= 5000;
1136
missionTimer:= time;
1137
if missionTex <> nil then
1138
FreeTexture(missionTex);
1145
missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, MissionIcons, @r)
1149
r.x:= ((-icon - 1) shr 5) * 32;
1150
r.y:= ((-icon - 1) mod 32) * 32;
1151
missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, SpritesData[sprAMAmmos].Surface, @r)
1155
procedure HideMission;
1158
if missionTex <> nil then FreeTexture(missionTex);
1161
procedure ShakeCamera(amount: LongWord);
1163
amount:= max(1, amount);
1164
WorldDx:= WorldDx - amount + LongInt(getRandom(1 + amount * 2));
1165
WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2));
1168
procedure initModule;
1173
bShowAmmoMenu:= false;
1175
bShowFinger:= false;
1182
SoundTimerTicks:= 0;
1189
FillChar(Captions, sizeof(Captions), 0)
1192
procedure freeModule;