~ubuntu-branches/ubuntu/quantal/hedgewars/quantal

« back to all changes in this revision

Viewing changes to hedgewars/uWorld.pas

  • Committer: Bazaar Package Importer
  • Author(s): Dmitry E. Oboukhov
  • Date: 2010-11-14 22:45:48 UTC
  • mfrom: (1.2.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20101114224548-tntbfzxa8qo9lhpn
* New upstream version.
 + New audio tracks
 + New forts: EvilChicken, Tank
 + New game modes: AI Survival Mode, Per Hedgehog Ammo,
   Reset Health, Reset Weapons, Unlimited Attacks
 + New grave: ring
 + Over 30 new hats
 + New themes: Art, Brick, Jungle, Stage
 + New maps: ShoppaKing, Sticks, TrophyRace (Mission)
 + New utilities: Portal Gun, Resurrector
 + New weapons: Flamethrower, Hammer, Old Limburger,
   Piano Strike, Sticky Mines
 + Weapons' projectiles will how be launched from their
   barrels instead of the hog's center
 + Flying Saucers may be used for moving below the water surface
 + New default game schemes: Clean Slate, Fort Mode, Timeless,
   Thinking with Portals, King Mode
 + New default weapon set: Clean Slate, Thinking with Portals
 + Bomb clusters/Melon parts inherit some of the original bomb's speed
 + Extended game statistics
 + Improved health bar updating
 + Hogs that blow themselves up will use triggers in they team color
 + Settings allow better control over the level of details/effects
 + Improved Lua support
 + On empty ammo switch to no weapon rather than the first available
   one (to avoid shooting by accident)
 + Display of hints in the frontend
 + Some improvements of existing Themes of Maps
 + Land destruction effects added
 + Improved fire effects
 + Improved Melon explosion effects
 + Online game lobby now features game filters
 + Other Frontend enhancements
 + Additional sounds
 + Show special game rules in Esc screen
 + Updated translation
 + Speed optimizations
 + Hedgewars will now use a sub directory of "My Documents"
   like other games instead of "%userprofile%/.hedgewars" under Windows
 + Added support for graphics cards/drivers that have a 512x512
   pixel textures limit
 + Team colors are more distinguishable from each other now
 * Fixed bug that allowed charging a weapon while on rope,
   leading to frozen timer
 * Various bug fixes
* Switched to 3.0 source format.
* Switched to cdbs build system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 * Hedgewars, a free turn based strategy game
 
3
 * Copyright (c) 2004-2010 Andrey Korotaev <unC0Rr@gmail.com>
 
4
 *
 
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
 
8
 *
 
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.
 
13
 *
 
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
 
17
 *)
 
18
 
 
19
{$INCLUDE "options.inc"}
 
20
 
 
21
unit uWorld;
 
22
interface
 
23
uses SDLh, uGears, uConsts, uFloat, uRandom;
 
24
 
 
25
 
 
26
var FollowGear: PGear;
 
27
    WindBarWidth: LongInt;
 
28
    bShowAmmoMenu: boolean;
 
29
    bSelected: boolean;
 
30
    bShowFinger: boolean;
 
31
    Frames: Longword;
 
32
    WaterColor, DeepWaterColor: TSDL_Color;
 
33
    WorldDx: LongInt;
 
34
    WorldDy: LongInt;
 
35
    SkyOffset: LongInt;
 
36
    HorizontOffset: LongInt;
 
37
{$IFDEF COUNTTICKS}
 
38
    cntTicks: LongWord;
 
39
{$ENDIF}
 
40
    cOffsetY: LongInt;
 
41
 
 
42
procedure initModule;
 
43
procedure freeModule;
 
44
 
 
45
procedure InitWorld;
 
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);
 
51
procedure MoveCamera;
 
52
 
 
53
implementation
 
54
uses    uStore, uMisc, uTeams, uIO, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand, GLunit;
 
55
 
 
56
type TCaptionStr = record
 
57
                   Tex: PTexture;
 
58
                   EndTime: LongWord;
 
59
                   end;
 
60
 
 
61
var cWaveWidth, cWaveHeight: LongInt;
 
62
    Captions: array[TCapGroup] of TCaptionStr;
 
63
    AMSlotSize, AMxOffset, AMyOffset, AMWidth, AMxShift, SlotsNum: LongInt;
 
64
    tmpSurface: PSDL_Surface;
 
65
    fpsTexture: PTexture;
 
66
    timeTexture: PTexture;
 
67
    FPS: Longword;
 
68
    CountTicks: Longword;
 
69
    SoundTimerTicks: Longword;
 
70
    prevPoint: TPoint;
 
71
    amSel: TAmmoType = amNothing;
 
72
    missionTex: PTexture;
 
73
    missionTimer: LongInt;
 
74
 
 
75
procedure InitWorld;
 
76
var i, t: LongInt;
 
77
    cp: PClan;
 
78
    g: ansistring;
 
79
 
 
80
    // helper functions to create the goal/game mode string
 
81
    function AddGoal(s: ansistring; gf: longword; si: TGoalStrId; i: LongInt): ansistring;
 
82
    var t: ansistring;
 
83
    begin
 
84
        if (GameFlags and gf) <> 0 then
 
85
            begin
 
86
            t:= inttostr(i);
 
87
            s:= s + format(trgoal[si], t) + '|'
 
88
            end;
 
89
        AddGoal:= s;
 
90
    end;
 
91
 
 
92
    function AddGoal(s: ansistring; gf: longword; si: TGoalStrId): ansistring;
 
93
    begin
 
94
        if (GameFlags and gf) <> 0 then
 
95
            s:= s + trgoal[si] + '|';
 
96
        AddGoal:= s;
 
97
    end;
 
98
begin
 
99
missionTimer:= 0;
 
100
 
 
101
if (GameFlags and gfRandomOrder) <> 0 then  // shuffle them up a bit
 
102
   begin
 
103
   for i:= 0 to ClansCount * 4 do
 
104
      begin
 
105
      t:= GetRandom(ClansCount);
 
106
      if t <> 0 then
 
107
         begin
 
108
         cp:= ClansArray[0];
 
109
         ClansArray[0]:= ClansArray[t];
 
110
         ClansArray[t]:= cp;
 
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
 
115
         end;
 
116
      end;
 
117
   CurrentTeam:= ClansArray[0]^.Teams[0];
 
118
   end;
 
119
 
 
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
 
122
 
 
123
// check different game flags (goals/game modes first for now)
 
124
g:= AddGoal(g, gfKing, gidKing); // king?
 
125
 
 
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);
 
141
 
 
142
// modified damage modificator?
 
143
if cDamagePercent <> 100 then
 
144
    g:= AddGoal(g, gfAny, gidDamageModifier, cDamagePercent);
 
145
 
 
146
// fade in
 
147
ScreenFade:= sfFromBlack;
 
148
ScreenFadeValue:= sfMax;
 
149
ScreenFadeSpeed:= 1;
 
150
 
 
151
// modified mine timers?
 
152
if cMinesTime <> 3000 then
 
153
    begin
 
154
    if cMinesTime = 0 then
 
155
        g:= AddGoal(g, gfAny, gidNoMineTimer)
 
156
    else if cMinesTime < 0 then
 
157
        g:= AddGoal(g, gfAny, gidRandomMineTimer)
 
158
    else
 
159
        g:= AddGoal(g, gfAny, gidMineTimer, cMinesTime div 1000);
 
160
    end;
 
161
 
 
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);
 
164
 
 
165
cWaveWidth:= SpritesData[sprWater].Width;
 
166
//cWaveHeight:= SpritesData[sprWater].Height;
 
167
cWaveHeight:= 32;
 
168
 
 
169
cGearScrEdgesDist:= Min(cScreenWidth div 2 - 100, cScreenHeight div 2 - 50);
 
170
SDL_WarpMouse(cScreenWidth div 2, cScreenHeight div 2);
 
171
prevPoint.X:= 0;
 
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);
 
175
AMSlotSize:= 33;
 
176
{$IFDEF IPHONEOS}
 
177
AMxOffset:= 10;
 
178
AMyOffset:= 10 + 123;   // moved downwards
 
179
AMWidth:= (cMaxSlotAmmoIndex + 1) * AMSlotSize + AMxOffset;
 
180
{$ELSE}
 
181
AMxOffset:= 10;
 
182
AMyOffset:= 60;
 
183
AMWidth:= (cMaxSlotAmmoIndex + 2) * AMSlotSize + AMxOffset;
 
184
{$ENDIF}
 
185
AMxShift:= AMWidth;
 
186
SkyOffset:= 0;
 
187
HorizontOffset:= 0;
 
188
end;
 
189
 
 
190
 
 
191
procedure ShowAmmoMenu;
 
192
const MENUSPEED = 15;
 
193
const BORDERSIZE = 2;
 
194
var x, y, i, t, g: LongInt;
 
195
    Slot, Pos, STurns: LongInt;
 
196
    Ammo: PHHAmmo;
 
197
begin
 
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
 
201
   begin
 
202
   FollowGear:= nil;
 
203
   if AMxShift = AMWidth then prevPoint.X:= 0;
 
204
   if (cReducedQuality and rqSlowMenu) <> 0 then
 
205
       AMxShift:= 0
 
206
   else
 
207
       if AMxShift > MENUSPEED then
 
208
           dec(AMxShift, MENUSPEED)
 
209
       else
 
210
           AMxShift:= 0;
 
211
   end else
 
212
   begin
 
213
   if AMxShift = 0 then
 
214
      begin
 
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)
 
219
      end;
 
220
   if (cReducedQuality and rqSlowMenu) <> 0 then
 
221
       AMxShift:= AMWidth
 
222
   else
 
223
       if AMxShift < (AMWidth - MENUSPEED) then
 
224
           inc(AMxShift, MENUSPEED)
 
225
       else
 
226
           AMxShift:= AMWidth;
 
227
   end;
 
228
Ammo:= nil;
 
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);
 
233
Pos:= -1;
 
234
if Ammo = nil then
 
235
    begin
 
236
    bShowAmmoMenu:= false;
 
237
    exit
 
238
    end;
 
239
SlotsNum:= 0;
 
240
x:= (cScreenWidth shr 1) - AMWidth + AMxShift;
 
241
 
 
242
{$IFDEF IPHONEOS}
 
243
Slot:= cMaxSlotIndex;
 
244
x:= x - cOffsetY;
 
245
y:= AMyOffset;
 
246
dec(y, BORDERSIZE);
 
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);
 
251
inc(y, BORDERSIZE);
 
252
 
 
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
 
255
        begin
 
256
        if (cScreenHeight - CursorPoint.Y >= y) and (cScreenHeight - CursorPoint.Y <= y + AMSlotSize) then Slot:= i;
 
257
        inc(SlotsNum);
 
258
        DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
 
259
        t:= 0;
 
260
        g:= 0;
 
261
        while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
 
262
            begin
 
263
            DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
 
264
            if (Ammo^[i, t].AmmoType <> amNothing) then
 
265
                begin
 
266
                STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
 
267
 
 
268
                if STurns >= 0 then
 
269
                    begin
 
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);
 
272
                    end else
 
273
                    DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
 
274
                if (Slot = i)
 
275
                and (CursorPoint.X >= x + g * AMSlotSize)
 
276
                and (CursorPoint.X <= x + (g + 1) * AMSlotSize) then
 
277
                    begin
 
278
                    if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
 
279
                    Pos:= t;
 
280
                    end;
 
281
                inc(g)
 
282
                end;
 
283
                inc(t)
 
284
            end;
 
285
        for g:= g to cMaxSlotAmmoIndex do
 
286
            DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
 
287
        DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
 
288
        inc(y, AMSlotSize);
 
289
        end;
 
290
 
 
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);
 
295
{$ELSE}
 
296
Slot:= 0;
 
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);
 
302
dec(y, AMSlotSize);
 
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);
 
308
 
 
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
 
311
        begin
 
312
        if (cScreenHeight - CursorPoint.Y >= y - AMSlotSize) and (cScreenHeight - CursorPoint.Y <= y) then Slot:= i;
 
313
        dec(y, AMSlotSize);
 
314
        inc(SlotsNum);
 
315
        DrawSprite(sprAMBorderVertical, x - BORDERSIZE, y, 0);
 
316
        DrawSprite(sprAMSlot, x, y, 1);
 
317
        DrawSprite(sprAMSlotKeys, x, y + 1, i);
 
318
        t:= 0;
 
319
        g:= 1;
 
320
        while (t <= cMaxSlotAmmoIndex) and (Ammo^[i, t].Count > 0) do
 
321
            begin
 
322
            DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
 
323
            if (Ammo^[i, t].AmmoType <> amNothing) then
 
324
                begin
 
325
                STurns:= Ammoz[Ammo^[i, t].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber;
 
326
 
 
327
                if STurns >= 0 then
 
328
                    begin
 
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);
 
331
                    end else
 
332
                    DrawSprite(sprAMAmmos, x + g * AMSlotSize, y + 1, LongInt(Ammo^[i, t].AmmoType)-1);
 
333
                if (Slot = i)
 
334
                and (CursorPoint.X >= x + g * AMSlotSize)
 
335
                and (CursorPoint.X <= x + (g + 1) * AMSlotSize) then
 
336
                    begin
 
337
                    if (STurns < 0) then DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 0);
 
338
                    Pos:= t;
 
339
                    end;
 
340
                inc(g)
 
341
                end;
 
342
                inc(t)
 
343
            end;
 
344
        for g:= g to cMaxSlotAmmoIndex + 1 do
 
345
            DrawSprite(sprAMSlot, x + g * AMSlotSize, y, 1);
 
346
        DrawSprite(sprAMBorderVertical, x + AMWidth - AMxOffset, y, 1);
 
347
        end;
 
348
 
 
349
dec(y, BORDERSIZE);
 
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);
 
354
{$ENDIF}
 
355
 
 
356
if (Pos >= 0) then
 
357
    begin
 
358
    if (Ammo^[Slot, Pos].Count > 0) and (Ammo^[Slot, Pos].AmmoType <> amNothing) then
 
359
        begin
 
360
        if (amSel <> Ammo^[Slot, Pos].AmmoType) or (WeaponTooltipTex = nil) then
 
361
            begin
 
362
            amSel:= Ammo^[Slot, Pos].AmmoType;
 
363
            RenderWeaponTooltip(amSel)
 
364
            end;
 
365
 
 
366
{$IFDEF IPHONEOS}
 
367
        DrawTexture(cScreenWidth div 2 - (AMWidth - 10) + AMxShift, AMyOffset - 25, Ammoz[Ammo^[Slot, Pos].AmmoType].NameTex);
 
368
 
 
369
        if Ammo^[Slot, Pos].Count < AMMO_INFINITE then
 
370
            DrawTexture(cScreenWidth div 2 + AMxOffset - 45, AMyOffset - 25, CountTexz[Ammo^[Slot, Pos].Count]);
 
371
{$ELSE}
 
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]);
 
375
{$ENDIF}
 
376
 
 
377
        if bSelected and (Ammoz[Ammo^[Slot, Pos].AmmoType].SkipTurns - CurrentTeam^.Clan^.TurnNumber < 0) then
 
378
            begin
 
379
            bShowAmmoMenu:= false;
 
380
            SetWeapon(Ammo^[Slot, Pos].AmmoType);
 
381
            bSelected:= false;
 
382
            FreeWeaponTooltip;
 
383
            exit
 
384
            end;
 
385
       end
 
386
    end
 
387
else
 
388
    FreeWeaponTooltip;
 
389
if (WeaponTooltipTex <> nil) and (AMxShift = 0) then
 
390
{$IFDEF IPHONEOS}
 
391
    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, AMyOffset - 1);
 
392
{$ELSE}
 
393
    ShowWeaponTooltip(x - WeaponTooltipTex^.w - 3, min(y + 1, cScreenHeight - WeaponTooltipTex^.h - 40));
 
394
{$ENDIF}
 
395
 
 
396
bSelected:= false;
 
397
if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
 
398
end;
 
399
 
 
400
procedure DrawWater(Alpha: byte; OffsetY: LongInt);
 
401
var VertexBuffer: array [0..3] of TVertex2f;
 
402
    r: TSDL_Rect;
 
403
    lw, lh: GLfloat;
 
404
begin
 
405
    WaterColorArray[0].a := Alpha;
 
406
    WaterColorArray[1].a := Alpha;
 
407
    WaterColorArray[2].a := Alpha;
 
408
    WaterColorArray[3].a := Alpha;
 
409
 
 
410
    lw:= cScreenWidth / cScaleFactor;
 
411
    lh:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 + 16;
 
412
 
 
413
    // Water
 
414
    r.y:= OffsetY + WorldDy + cWaterLine;
 
415
    if WorldDy < trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine then
 
416
    begin
 
417
        if r.y < 0 then
 
418
            r.y:= 0;
 
419
 
 
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;
 
429
 
 
430
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 
431
        glEnableClientState(GL_COLOR_ARRAY);
 
432
        glColorPointer(4, GL_UNSIGNED_BYTE, 0, @WaterColorArray[0]);
 
433
 
 
434
        glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 
435
 
 
436
        glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
437
 
 
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);
 
442
    end;
 
443
end;
 
444
 
 
445
procedure DrawWaves(Dir, dX, dY: LongInt; tnt: Byte);
 
446
var VertexBuffer, TextureBuffer: array [0..3] of TVertex2f;
 
447
    lw, waves, shift: GLfloat;
 
448
begin
 
449
lw:= cScreenWidth / cScaleFactor;
 
450
waves:= lw * 2 / cWaveWidth;
 
451
 
 
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,
 
455
     255
 
456
);
 
457
 
 
458
glBindTexture(GL_TEXTURE_2D, SpritesData[sprWater].Texture^.id);
 
459
 
 
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;
 
468
 
 
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;
 
478
 
 
479
 
 
480
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 
481
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]);
 
482
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
483
 
 
484
Tint($FF, $FF, $FF, $FF);
 
485
 
 
486
{for i:= -1 to cWaterSprCount do
 
487
    DrawSprite(sprWater,
 
488
        i * cWaveWidth + ((WorldDx + (RealTicks shr 6) * Dir + dX) mod cWaveWidth) - (cScreenWidth div 2),
 
489
        cWaterLine + WorldDy + dY,
 
490
        0)}
 
491
end;
 
492
 
 
493
procedure DrawRepeated(spr, sprL, sprR: TSprite; Shift, OffsetY: LongInt);
 
494
var i, w, h, lw, lh, rw, rh, sw: LongInt;
 
495
begin
 
496
    sw:= round(cScreenWidth / cScaleFactor);
 
497
    if (SpritesData[sprL].Texture = nil) or (SpritesData[sprR].Texture = nil) then
 
498
    begin
 
499
        w:= SpritesData[spr].Width * SpritesData[spr].Texture^.Scale;
 
500
        h:= SpritesData[spr].Height * SpritesData[spr].Texture^.Scale;
 
501
        i:= Shift mod w;
 
502
        if i > 0 then dec(i, w);
 
503
        dec(i, w * (sw div w + 1));
 
504
        repeat
 
505
            DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
 
506
            inc(i, w)
 
507
        until i > sw
 
508
    end
 
509
    else
 
510
    begin
 
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;
 
517
        dec(Shift, w div 2);
 
518
        DrawTexture(Shift, WorldDy + LAND_HEIGHT + OffsetY - h, SpritesData[spr].Texture, SpritesData[spr].Texture^.Scale);
 
519
 
 
520
        i:= Shift - lw;
 
521
        while i >= -sw - lw do
 
522
        begin
 
523
            DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - lh, SpritesData[sprL].Texture, SpritesData[sprL].Texture^.Scale);
 
524
            dec(i, lw);
 
525
        end;
 
526
 
 
527
        i:= Shift + w;
 
528
        while i <= sw do
 
529
        begin
 
530
            DrawTexture(i, WorldDy + LAND_HEIGHT + OffsetY - rh, SpritesData[sprR].Texture, SpritesData[sprR].Texture^.Scale);
 
531
            inc(i, rw)
 
532
        end
 
533
    end
 
534
end;
 
535
 
 
536
 
 
537
procedure DrawWorld(Lag: LongInt);
 
538
var i, t: LongInt;
 
539
    r: TSDL_Rect;
 
540
    tdx, tdy: Double;
 
541
    grp: TCapGroup;
 
542
    s: string[15];
 
543
    highlight: Boolean;
 
544
    offset, offsetX, offsetY, ScreenBottom: LongInt;
 
545
    VertexBuffer: array [0..3] of TVertex2f;
 
546
begin
 
547
    if not isPaused then
 
548
    begin
 
549
        if ZoomValue < zoom then
 
550
        begin
 
551
            zoom:= zoom - 0.002 * Lag;
 
552
            if ZoomValue > zoom then
 
553
                zoom:= ZoomValue
 
554
        end
 
555
        else
 
556
        if ZoomValue > zoom then
 
557
        begin
 
558
            zoom:= zoom + 0.002 * Lag;
 
559
            if ZoomValue < zoom then
 
560
                zoom:= ZoomValue
 
561
            end
 
562
        end
 
563
    else
 
564
        ZoomValue:= zoom;
 
565
 
 
566
    // Sky
 
567
    glClear(GL_COLOR_BUFFER_BIT);
 
568
    //glPushMatrix;
 
569
    //glScalef(1.0, 1.0, 1.0);
 
570
 
 
571
    if not isPaused then
 
572
        MoveCamera;
 
573
 
 
574
    if (cReducedQuality and rqNoBackground) = 0 then
 
575
    begin
 
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);
 
583
 
 
584
        // background
 
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);
 
587
    end;
 
588
 
 
589
    DrawVisualGears(0);
 
590
 
 
591
    if (cReducedQuality and rq2DWater) = 0 then
 
592
    begin
 
593
        // Waves
 
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);
 
599
    end
 
600
    else
 
601
        DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)), 0);
 
602
 
 
603
    DrawLand(WorldDx, WorldDy);
 
604
 
 
605
    DrawWater(255, 0);
 
606
 
 
607
// Attack bar
 
608
    if CurrentTeam <> nil then
 
609
        case AttackBar of
 
610
(*        1: begin
 
611
        r:= StuffPoz[sPowerBar];
 
612
        {$WARNINGS OFF}
 
613
        r.w:= (CurrentHedgehog^.Gear^.Power * 256) div cPowerDivisor;
 
614
        {$WARNINGS ON}
 
615
        DrawSpriteFromRect(r, cScreenWidth - 272, cScreenHeight - 48, 16, 0, Surface);
 
616
        end;*)
 
617
        2: with CurrentHedgehog^ do
 
618
                begin
 
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
 
622
                    DrawSprite(sprPower,
 
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,
 
625
                            i)
 
626
                end
 
627
        end;
 
628
 
 
629
    DrawVisualGears(1);
 
630
 
 
631
    DrawGears;
 
632
 
 
633
    DrawVisualGears(2);
 
634
 
 
635
    DrawWater(cWaterOpacity, 0);
 
636
 
 
637
    // Waves
 
638
    DrawWaves( 1, 25 - WorldDx div 9, - cWaveHeight, 12);
 
639
 
 
640
    if (cReducedQuality and rq2DWater) = 0 then
 
641
    begin
 
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);
 
648
    end
 
649
    else
 
650
        DrawWaves(-1, 50, - (cWaveHeight shr 1), 0);
 
651
 
 
652
 
 
653
{$WARNINGS OFF}
 
654
// Target
 
655
if (TargetPoint.X <> NoPointX) and (CurrentTeam <> nil) and (CurrentHedgehog <> nil) then
 
656
    begin
 
657
    with PHedgehog(CurrentHedgehog)^ do
 
658
        begin
 
659
        if (CurAmmoType = amBee) then
 
660
            DrawRotatedF(sprTargetBee, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360)
 
661
        else
 
662
            DrawRotatedF(sprTargetP, TargetPoint.X + WorldDx, TargetPoint.Y + WorldDy, 0, 0, (RealTicks shr 3) mod 360);
 
663
        end;
 
664
    end;
 
665
{$WARNINGS ON}
 
666
 
 
667
// this scale is used to keep the various widgets at the same dimension at all zoom levels
 
668
SetScale(cDefaultZoomLevel);
 
669
 
 
670
 
 
671
// Turn time
 
672
{$IFDEF IPHONEOS}
 
673
offsetX:= cScreenHeight - 13;
 
674
{$ELSE}
 
675
offsetX:= 48;
 
676
{$ENDIF}
 
677
offsetY:= cOffsetY;
 
678
if ((TurnTimeLeft <> 0) and (TurnTimeLeft < 1000000)) or (ReadyTimeLeft <> 0) then
 
679
    begin
 
680
    if ReadyTimeLeft <> 0 then
 
681
        i:= Succ(Pred(ReadyTimeLeft) div 1000)
 
682
    else
 
683
        i:= Succ(Pred(TurnTimeLeft) div 1000);
 
684
   
 
685
   if i>99 then t:= 112
 
686
      else if i>9 then t:= 96
 
687
                  else t:= 80;
 
688
   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, 1);
 
689
   while i > 0 do
 
690
         begin
 
691
         dec(t, 32);
 
692
         DrawSprite(sprBigDigit, -(cScreenWidth shr 1) + t + offsetY, cScreenHeight - offsetX, i mod 10);
 
693
         i:= i div 10
 
694
         end;
 
695
   DrawSprite(sprFrame, -(cScreenWidth shr 1) + t - 4 + offsetY, cScreenHeight - offsetX, 0);
 
696
   end;
 
697
 
 
698
{$IFNDEF IPHONEOS}
 
699
// Timetrial
 
700
if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then
 
701
    begin
 
702
    if TimeTrialStopTime = 0 then i:= RealTicks - TimeTrialStartTime else i:= TimeTrialStopTime - TimeTrialStartTime;
 
703
    t:= 272;
 
704
    // right frame
 
705
    DrawSprite(sprFrame, -cScreenWidth div 2 + t, 8, 1);
 
706
    dec(t, 32);
 
707
    // 1 ms
 
708
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
 
709
    dec(t, 32);
 
710
    i:= i div 10;
 
711
    // 10 ms
 
712
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
 
713
    dec(t, 32);
 
714
    i:= i div 10;
 
715
    // 100 ms
 
716
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
 
717
    dec(t, 16);
 
718
    // Point
 
719
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 11);
 
720
    dec(t, 32);
 
721
    i:= i div 10;
 
722
    // 1 s
 
723
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
 
724
    dec(t, 32);
 
725
    i:= i div 10;
 
726
    // 10s
 
727
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 6);
 
728
    dec(t, 16);
 
729
    // Point
 
730
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, 10);
 
731
    dec(t, 32);
 
732
    i:= i div 6;
 
733
    // 1 m
 
734
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
 
735
    dec(t, 32);
 
736
    i:= i div 10;
 
737
    // 10 m
 
738
    DrawSprite(sprBigDigit, -cScreenWidth div 2 + t, 8, i mod 10);
 
739
    // left frame
 
740
    DrawSprite(sprFrame, -cScreenWidth div 2 + t - 4, 8, 0);
 
741
    end;
 
742
{$ENDIF}
 
743
 
 
744
// Captions
 
745
{$IFDEF IPHONEOS}
 
746
offset:= 40;
 
747
{$ELSE}
 
748
if ((TrainingFlags and tfTimeTrial) <> 0) and (TimeTrialStartTime > 0) then offset:= 48
 
749
else offset:= 8;
 
750
{$ENDIF}
 
751
 
 
752
    for grp:= Low(TCapGroup) to High(TCapGroup) do
 
753
        with Captions[grp] do
 
754
            if Tex <> nil then
 
755
            begin
 
756
                DrawCentered(0, offset, Tex);
 
757
                inc(offset, Tex^.h + 2);
 
758
                if EndTime <= RealTicks then
 
759
                begin
 
760
                    FreeTexture(Tex);
 
761
                    Tex:= nil;
 
762
                    EndTime:= 0
 
763
                end;
 
764
            end;
 
765
 
 
766
// Teams Healths
 
767
for t:= 0 to Pred(TeamsCount) do
 
768
   with TeamsArray[t]^ do
 
769
      begin
 
770
      highlight:= bShowFinger and (CurrentTeam = TeamsArray[t]) and ((RealTicks mod 1000) < 500);
 
771
 
 
772
      if highlight then
 
773
         Tint(Clan^.Color);
 
774
 
 
775
      // draw name
 
776
      DrawTexture(-NameTagTex^.w - 16, cScreenHeight + DrawHealthY, NameTagTex);
 
777
 
 
778
      // draw flag
 
779
      DrawTexture(-14, cScreenHeight + DrawHealthY, FlagTex);
 
780
 
 
781
      // draw health bar
 
782
      r.x:= 0;
 
783
      r.y:= 0;
 
784
      r.w:= 2 + TeamHealthBarWidth;
 
785
      r.h:= HealthTex^.h;
 
786
      DrawFromRect(14, cScreenHeight + DrawHealthY, @r, HealthTex);
 
787
 
 
788
      // draw health bar's right border
 
789
      inc(r.x, cTeamHealthWidth + 2);
 
790
      r.w:= 3;
 
791
      DrawFromRect(TeamHealthBarWidth + 16, cScreenHeight + DrawHealthY, @r, HealthTex);
 
792
 
 
793
      // draw ai kill counter for gfAISurvival
 
794
      if (GameFlags and gfAISurvival) <> 0 then begin
 
795
          DrawTexture(TeamHealthBarWidth + 22, cScreenHeight + DrawHealthY,
 
796
              AIKillsTex);
 
797
      end;
 
798
 
 
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
 
801
      if highlight then
 
802
         begin
 
803
         Tint($FF, $FF, $FF, $FF);
 
804
 
 
805
         // draw name
 
806
         r.x:= 2;
 
807
         r.y:= 2;
 
808
         r.w:= NameTagTex^.w - 4;
 
809
         r.h:= NameTagTex^.h - 4;
 
810
         DrawFromRect(-NameTagTex^.w - 14, cScreenHeight + DrawHealthY + 2, @r, NameTagTex);
 
811
         // draw flag
 
812
         r.w:= 22;
 
813
         r.h:= 15;
 
814
         DrawFromRect(-12, cScreenHeight + DrawHealthY + 2, @r, FlagTex);
 
815
         // draw health bar
 
816
         r.w:= TeamHealthBarWidth + 1;
 
817
         r.h:= HealthTex^.h - 4;
 
818
         DrawFromRect(16, cScreenHeight + DrawHealthY + 2, @r, HealthTex);
 
819
         end;
 
820
      end;
 
821
 
 
822
// Lag alert
 
823
if isInLag then DrawSprite(sprLag, 32 - (cScreenWidth shr 1), 32, (RealTicks shr 7) mod 12);
 
824
 
 
825
// Wind bar
 
826
{$IFDEF IPHONEOS}
 
827
    offsetX:= cScreenHeight - 13;
 
828
    offsetY:= (cScreenWidth shr 1) + 74;
 
829
{$ELSE}
 
830
    offsetX:= 30;
 
831
    offsetY:= 180;
 
832
{$ENDIF}
 
833
    DrawSprite(sprWindBar, (cScreenWidth shr 1) - offsetY, cScreenHeight - offsetX, 0);
 
834
    if WindBarWidth > 0 then
 
835
    begin
 
836
        {$WARNINGS OFF}
 
837
        r.x:= 8 - (RealTicks shr 6) mod 8;
 
838
        {$WARNINGS ON}
 
839
        r.y:= 0;
 
840
        r.w:= WindBarWidth;
 
841
        r.h:= 13;
 
842
        DrawSpriteFromRect(sprWindR, r, (cScreenWidth shr 1) - offsetY + 77, cScreenHeight - offsetX + 2, 13, 0);
 
843
    end
 
844
    else
 
845
        if WindBarWidth < 0 then
 
846
        begin
 
847
            {$WARNINGS OFF}
 
848
            r.x:= (Longword(WindBarWidth) + RealTicks shr 6) mod 8;
 
849
            {$WARNINGS ON}
 
850
            r.y:= 0;
 
851
            r.w:= - WindBarWidth;
 
852
            r.h:= 13;
 
853
            DrawSpriteFromRect(sprWindL, r, (cScreenWidth shr 1) - offsetY + 74 + WindBarWidth, cScreenHeight - offsetX + 2, 13, 0);
 
854
        end;
 
855
 
 
856
// AmmoMenu
 
857
if (AMxShift < AMWidth) or bShowAmmoMenu then ShowAmmoMenu;
 
858
 
 
859
// Cursor
 
860
if isCursorVisible and bShowAmmoMenu then
 
861
   DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8);
 
862
 
 
863
DrawChat;
 
864
 
 
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
 
868
    begin
 
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);
 
873
    end;
 
874
 
 
875
// fps
 
876
{$IFDEF IPHONEOS}
 
877
offsetX:= 8;
 
878
{$ELSE}
 
879
offsetX:= 10;
 
880
{$ENDIF}
 
881
offsetY:= cOffsetY;
 
882
inc(Frames);
 
883
 
 
884
if cShowFPS or (GameType = gmtDemo) then inc(CountTicks, Lag);
 
885
if (GameType = gmtDemo) and (CountTicks >= 1000) then
 
886
   begin
 
887
   i:=GameTicks div 1000;
 
888
   t:= i mod 60;
 
889
   s:= inttostr(t);
 
890
   if t < 10 then s:= '0' + s;
 
891
   i:= i div 60;
 
892
   t:= i mod 60;
 
893
   s:= inttostr(t) + ':' + s;
 
894
   if t < 10 then s:= '0' + s;
 
895
   s:= inttostr(i div 60) + ':' + s;
 
896
 
 
897
   if timeTexture <> nil then
 
898
        FreeTexture(timeTexture);
 
899
    timeTexture:= nil;
 
900
 
 
901
   tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
 
902
   tmpSurface:= doSurfaceConversion(tmpSurface);
 
903
   timeTexture:= Surface2Tex(tmpSurface, false);
 
904
   SDL_FreeSurface(tmpSurface)
 
905
   end;
 
906
 
 
907
if timeTexture <> nil then
 
908
   DrawTexture((cScreenWidth shr 1) - 20 - timeTexture^.w - offsetY, offsetX + timeTexture^.h+5, timeTexture);
 
909
 
 
910
if cShowFPS then
 
911
   begin
 
912
   if CountTicks >= 1000 then
 
913
      begin
 
914
      FPS:= Frames;
 
915
      Frames:= 0;
 
916
      CountTicks:= 0;
 
917
      s:= inttostr(FPS) + ' fps';
 
918
      if fpsTexture <> nil then
 
919
        FreeTexture(fpsTexture);
 
920
    fpsTexture:= nil;
 
921
      tmpSurface:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(s), cWhiteColorChannels);
 
922
      tmpSurface:= doSurfaceConversion(tmpSurface);
 
923
      fpsTexture:= Surface2Tex(tmpSurface, false);
 
924
      SDL_FreeSurface(tmpSurface)
 
925
      end;
 
926
   if fpsTexture <> nil then
 
927
      DrawTexture((cScreenWidth shr 1) - 60 - offsetY, offsetX, fpsTexture);
 
928
   end;
 
929
 
 
930
if CountTicks >= 1000 then CountTicks:= 0;
 
931
 
 
932
// lag warning (?)
 
933
inc(SoundTimerTicks, Lag);
 
934
if SoundTimerTicks >= 50 then
 
935
   begin
 
936
   SoundTimerTicks:= 0;
 
937
   if cVolumeDelta <> 0 then
 
938
      begin
 
939
      str(ChangeVolume(cVolumeDelta), s);
 
940
      AddCaption(Format(trmsg[sidVolume], s), cWhiteColor, capgrpVolume)
 
941
      end
 
942
   end;
 
943
 
 
944
if GameState = gsConfirm then
 
945
    DrawCentered(0, (cScreenHeight shr 1), ConfirmTexture);
 
946
 
 
947
if ScreenFade <> sfNone then
 
948
    begin
 
949
    if not isFirstFrame then
 
950
        case ScreenFade of
 
951
            sfToBlack, sfToWhite:     if ScreenFadeValue + Lag * ScreenFadeSpeed < sfMax then
 
952
                                          inc(ScreenFadeValue, Lag * ScreenFadeSpeed)
 
953
                                      else
 
954
                                          ScreenFadeValue:= sfMax;
 
955
            sfFromBlack, sfFromWhite: if ScreenFadeValue - Lag * ScreenFadeSpeed > 0 then
 
956
                                          dec(ScreenFadeValue, Lag * ScreenFadeSpeed)
 
957
                                      else
 
958
                                          ScreenFadeValue:= 0;
 
959
            end;
 
960
    if ScreenFade <> sfNone then
 
961
        begin
 
962
        case ScreenFade of
 
963
            sfToBlack, sfFromBlack: Tint(0, 0, 0, ScreenFadeValue * 255 div 1000);
 
964
            sfToWhite, sfFromWhite: Tint($FF, $FF, $FF, ScreenFadeValue * 255 div 1000);
 
965
            end;
 
966
 
 
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;
 
975
 
 
976
        glDisable(GL_TEXTURE_2D);
 
977
 
 
978
        glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]);
 
979
        glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer));
 
980
 
 
981
        glEnable(GL_TEXTURE_2D);
 
982
        Tint($FF, $FF, $FF, $FF);
 
983
        if not isFirstFrame and ((ScreenFadeValue = 0) or (ScreenFadeValue = sfMax)) then ScreenFade:= sfNone
 
984
        end
 
985
    end;
 
986
 
 
987
SetScale(zoom);
 
988
 
 
989
// Cursor
 
990
if isCursorVisible then
 
991
   begin
 
992
   if not bShowAmmoMenu then
 
993
     begin
 
994
     with CurrentHedgehog^ do
 
995
       if (Gear <> nil) and ((Gear^.State and gstHHChooseTarget) <> 0) then
 
996
         begin
 
997
         i:= GetAmmoEntry(CurrentHedgehog^)^.Pos;
 
998
         with Ammoz[CurAmmoType] do
 
999
           if PosCount > 1 then
 
1000
             DrawSprite(PosSprite, CursorPoint.X - (SpritesData[PosSprite].Width shr 1), cScreenHeight - CursorPoint.Y - (SpritesData[PosSprite].Height shr 1),i);
 
1001
         end;
 
1002
     DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
 
1003
     end
 
1004
   end;
 
1005
isFirstFrame:= false
 
1006
end;
 
1007
 
 
1008
procedure AddCaption(s: shortstring; Color: Longword; Group: TCapGroup);
 
1009
begin
 
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;
 
1014
 
 
1015
    Captions[Group].Tex:= RenderStringTex(s, Color, fntBig);
 
1016
 
 
1017
    case Group of
 
1018
        capgrpGameState: Captions[Group].EndTime:= RealTicks + 2200
 
1019
    else
 
1020
        Captions[Group].EndTime:= RealTicks + 1400 + LongWord(Captions[Group].Tex^.w) * 3;
 
1021
    end;
 
1022
end;
 
1023
 
 
1024
procedure MoveCamera;
 
1025
var EdgesDist,  wdy: LongInt;
 
1026
    PrevSentPointTime: LongWord = 0;
 
1027
begin
 
1028
{$IFNDEF IPHONEOS}
 
1029
if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus then
 
1030
begin
 
1031
    SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
 
1032
    CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
 
1033
    CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
 
1034
end;
 
1035
{$ENDIF}
 
1036
 
 
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
 
1039
    begin
 
1040
        FollowGear:= nil;
 
1041
        prevPoint:= CursorPoint;
 
1042
        exit
 
1043
    end
 
1044
    else
 
1045
    begin
 
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;
 
1048
    end;
 
1049
 
 
1050
wdy:= trunc(cScreenHeight / cScaleFactor) + cScreenHeight div 2 - cWaterLine - cVisibleWater;
 
1051
if WorldDy < wdy then WorldDy:= wdy;
 
1052
 
 
1053
if ((CursorPoint.X = prevPoint.X) and (CursorPoint.Y = prevpoint.Y)) then exit;
 
1054
 
 
1055
if AMxShift < AMWidth then
 
1056
begin
 
1057
{$IFDEF IPHONEOS}
 
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;
 
1062
{$ELSE}
 
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;
 
1067
{$ENDIF}
 
1068
    prevPoint:= CursorPoint;
 
1069
    if cHasFocus then SDL_WarpMouse(CursorPoint.X + cScreenWidth div 2, cScreenHeight - CursorPoint.Y);
 
1070
    exit
 
1071
end;
 
1072
 
 
1073
if isCursorVisible then
 
1074
begin
 
1075
    if (not CurrentTeam^.ExtDriven) and (GameTicks >= PrevSentPointTime + cSendCursorPosTime) then
 
1076
    begin
 
1077
        SendIPCXY('P', CursorPoint.X - WorldDx, cScreenHeight - CursorPoint.Y - WorldDy);
 
1078
        PrevSentPointTime:= GameTicks
 
1079
    end;
 
1080
    EdgesDist:= cCursorEdgesDist
 
1081
end
 
1082
else
 
1083
    EdgesDist:= cGearScrEdgesDist;
 
1084
 
 
1085
// this generates the border around the screen that moves the camera when cursor is near it
 
1086
if isCursorVisible or (FollowGear <> nil) then
 
1087
begin
 
1088
    if CursorPoint.X < - cScreenWidth div 2 + EdgesDist then
 
1089
    begin
 
1090
        WorldDx:= WorldDx - CursorPoint.X - cScreenWidth div 2 + EdgesDist;
 
1091
        CursorPoint.X:= - cScreenWidth div 2 + EdgesDist
 
1092
    end
 
1093
    else
 
1094
        if CursorPoint.X > cScreenWidth div 2 - EdgesDist then
 
1095
        begin
 
1096
            WorldDx:= WorldDx - CursorPoint.X + cScreenWidth div 2 - EdgesDist;
 
1097
            CursorPoint.X:= cScreenWidth div 2 - EdgesDist
 
1098
        end;
 
1099
    if CursorPoint.Y < EdgesDist then
 
1100
    begin
 
1101
        WorldDy:= WorldDy + CursorPoint.Y - EdgesDist;
 
1102
        CursorPoint.Y:= EdgesDist
 
1103
    end
 
1104
    else
 
1105
        if CursorPoint.Y > cScreenHeight - EdgesDist then
 
1106
        begin
 
1107
           WorldDy:= WorldDy + CursorPoint.Y - cScreenHeight + EdgesDist;
 
1108
           CursorPoint.Y:= cScreenHeight - EdgesDist
 
1109
        end;
 
1110
end
 
1111
else
 
1112
    if cHasFocus then
 
1113
    begin
 
1114
        WorldDx:= WorldDx - CursorPoint.X + prevPoint.X;
 
1115
        WorldDy:= WorldDy + CursorPoint.Y - prevPoint.Y;
 
1116
        CursorPoint.X:= 0;
 
1117
        CursorPoint.Y:= cScreenHeight div 2;
 
1118
    end;
 
1119
 
 
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;
 
1127
end;
 
1128
 
 
1129
procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
 
1130
var r: TSDL_Rect;
 
1131
begin
 
1132
r.w:= 32;
 
1133
r.h:= 32;
 
1134
 
 
1135
if time = 0 then time:= 5000;
 
1136
missionTimer:= time;
 
1137
if missionTex <> nil then
 
1138
    FreeTexture(missionTex);
 
1139
missionTex:= nil;
 
1140
 
 
1141
if icon > -1 then
 
1142
    begin
 
1143
    r.x:= 0;
 
1144
    r.y:= icon * 32;
 
1145
    missionTex:= RenderHelpWindow(caption, subcaption, text, '', 0, MissionIcons, @r)
 
1146
    end
 
1147
else
 
1148
    begin
 
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)
 
1152
    end;
 
1153
end;
 
1154
 
 
1155
procedure HideMission;
 
1156
begin
 
1157
    missionTimer:= 0;
 
1158
    if missionTex <> nil then FreeTexture(missionTex);
 
1159
end;
 
1160
 
 
1161
procedure ShakeCamera(amount: LongWord);
 
1162
begin
 
1163
    amount:= max(1, amount);
 
1164
    WorldDx:= WorldDx - amount + LongInt(getRandom(1 + amount * 2));
 
1165
    WorldDy:= WorldDy - amount + LongInt(getRandom(1 + amount * 2));
 
1166
end;
 
1167
 
 
1168
procedure initModule;
 
1169
begin
 
1170
    fpsTexture:= nil;
 
1171
    FollowGear:= nil;
 
1172
    WindBarWidth:= 0;
 
1173
    bShowAmmoMenu:= false;
 
1174
    bSelected:= false;
 
1175
    bShowFinger:= false;
 
1176
    Frames:= 0;
 
1177
    WorldDx:= -512;
 
1178
    WorldDy:= -256;
 
1179
 
 
1180
    FPS:= 0;
 
1181
    CountTicks:= 0;
 
1182
    SoundTimerTicks:= 0;
 
1183
    prevPoint.X:= 0;
 
1184
    prevPoint.Y:= 0;
 
1185
    missionTimer:= 0;
 
1186
    missionTex:= nil;
 
1187
    cOffsetY:= 0;
 
1188
 
 
1189
    FillChar(Captions, sizeof(Captions), 0)
 
1190
end;
 
1191
 
 
1192
procedure freeModule;
 
1193
begin
 
1194
end;
 
1195
 
 
1196
end.