forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay3d.cpp
4354 lines (3779 loc) · 118 KB
/
display3d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Warzone 2100.
Copyright (C) 1999-2004 Eidos Interactive
Copyright (C) 2005-2012 Warzone 2100 Project
Warzone 2100 is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Warzone 2100 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file display3d.c
* Draws the 3D view.
* Originally by Alex McLean & Jeremy Sallis, Pumpkin Studios, EIDOS INTERACTIVE
*/
#include "lib/framework/frame.h"
#include "lib/framework/opengl.h"
#include "lib/framework/math_ext.h"
#include "lib/framework/stdio_ext.h"
/* Includes direct access to render library */
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/piedef.h"
#include "lib/ivis_opengl/tex.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/piepalette.h"
#include "lib/ivis_opengl/piematrix.h"
#include "lib/ivis_opengl/piemode.h"
#include "lib/framework/fixedpoint.h"
#include "lib/ivis_opengl/piefunc.h"
#include "lib/gamelib/gtime.h"
#include "lib/gamelib/animobj.h"
#include "lib/script/script.h"
#include "lib/sound/audio.h"
#include "lib/sound/audio_id.h"
#include "lib/netplay/netplay.h"
#include "e3demo.h"
#include "loop.h"
#include "atmos.h"
#include "levels.h"
#include "map.h"
#include "move.h"
#include "visibility.h"
#include "geometry.h"
#include "messagedef.h"
#include "miscimd.h"
#include "effects.h"
#include "edit3d.h"
#include "feature.h"
#include "hci.h"
#include "display.h"
#include "intdisplay.h"
#include "radar.h"
#include "display3d.h"
#include "lighting.h"
#include "console.h"
#include "projectile.h"
#include "bucket3d.h"
#include "intelmap.h"
#include "mapdisplay.h"
#include "message.h"
#include "component.h"
#include "warcam.h"
#include "scripttabs.h"
#include "scriptextern.h"
#include "scriptcb.h"
#include "keymap.h"
#include "drive.h"
#include "gateway.h"
#include "transporter.h"
#include "warzoneconfig.h"
#include "action.h"
#include "keybind.h"
#include "combat.h"
#include "order.h"
#include "scores.h"
#include "multiplay.h"
#include "advvis.h"
#include "texture.h"
#include "anim_id.h"
#include "cmddroid.h"
#include "terrain.h"
/******************** Prototypes ********************/
static UDWORD getTargettingGfx(void);
static void drawDroidGroupNumber(DROID *psDroid);
static void trackHeight(float desiredHeight);
static void renderSurroundings(void);
static void locateMouse(void);
static bool renderWallSection(STRUCTURE *psStructure);
static void drawDragBox(void);
static void calcFlagPosScreenCoords(SDWORD *pX, SDWORD *pY, SDWORD *pR);
static void displayTerrain(void);
static iIMDShape *flattenImd(iIMDShape *imd, UDWORD structX, UDWORD structY, UDWORD direction, bool allPoints = false);
static void drawTiles(iView *player);
static void display3DProjectiles(void);
static void drawDroidSelections(void);
static void drawStructureSelections(void);
static void displayAnimation(ANIM_OBJECT * psAnimObj, bool bHoldOnFirstFrame);
static void displayBlueprints(void);
static void processSensorTarget(void);
static void processDestinationTarget(void);
static bool eitherSelected(DROID *psDroid);
static void structureEffects(void);
static void showDroidSensorRanges(void);
static void showSensorRange2(BASE_OBJECT *psObj);
static void drawRangeAtPos(SDWORD centerX, SDWORD centerY, SDWORD radius);
static void addConstructionLine(DROID *psDroid, STRUCTURE *psStructure);
static void doConstructionLines(void);
static void drawDroidCmndNo(DROID *psDroid);
static void drawDroidRank(DROID *psDroid);
static void drawDroidSensorLock(DROID *psDroid);
static void calcAverageTerrainHeight(iView *player);
bool doWeDrawProximitys(void);
static PIELIGHT getBlueprintColour(STRUCT_STATES state);
static void NetworkDisplayPlainForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours);
static void NetworkDisplayImage(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours);
void NotifyUserOfError(char *msg);
extern bool writeGameInfo(const char *pFileName); // Used to help debug issues when we have fatal errors & crash handler testing.
/******************** Variables ********************/
// Should be cleaned up properly and be put in structures.
// Initialised at start of drawTiles().
// In model coordinates where x is east, y is up and z is north, rather than world coordinates where x is east, y is south and z is up.
// To get the real camera position, still need to add Vector3i(player.p.x, 0, player.p.z).
static Vector3i actualCameraPosition;
bool bRender3DOnly;
static bool bRangeDisplay = false;
static SDWORD rangeCenterX,rangeCenterY,rangeRadius;
static bool bDrawProximitys = true;
bool godMode;
bool showGateways = false;
bool showPath = false;
/// The name of the texture page used to draw the skybox
static char skyboxPageName[PATH_MAX] = "page-25";
/// When to display HP bars
UWORD barMode;
/// Have we made a selection by clicking the mouse? - used for dragging etc
bool selectAttempt = false;
/// Vectors that hold the player and camera directions and positions
iView player;
/// Temporary rotation vectors to store rotations for droids etc
static Vector3i imdRot,imdRot2;
/// How far away are we from the terrain
static UDWORD distance;
/// Stores the screen coordinates of the transformed terrain tiles
static Vector3i tileScreenInfo[VISIBLE_YTILES+1][VISIBLE_XTILES+1];
/// Records the present X and Y values for the current mouse tile (in tiles)
SDWORD mouseTileX, mouseTileY;
Vector2i mousePos(0, 0);
/// Do we want the radar to be rendered
bool radarOnScreen = true;
bool radarPermitted = true;
/// Show unit/building gun/sensor range
bool rangeOnScreen = false; // For now, most likely will change later! -Q 5-10-05 A very nice effect - Per
/// Tactical UI: show/hide target origin icon
bool tuiTargetOrigin = false;
/// Temporary values for the terrain render - center of grid to be rendered
static int playerXTile, playerZTile;
/// Have we located the mouse?
static bool mouseLocated = true;
/// The cached value of frameGetFrameNumber()
static UDWORD currentGameFrame;
/// The box used for multiple selection - present screen coordinates
static QUAD dragQuad;
/// temporary buffer used for flattening IMDs
#define iV_IMD_MAX_POINTS 500
static Vector3f alteredPoints[iV_IMD_MAX_POINTS];
/** Number of tiles visible
* \todo This should become dynamic! (A function of resolution, angle and zoom maybe.)
*/
Vector2i visibleTiles(VISIBLE_XTILES, VISIBLE_YTILES);
/// The tile we use for drawing the bottom of a body of water
static unsigned int underwaterTile = WATER_TILE;
/** The tile we use for drawing rubble
* \note Unused.
*/
static unsigned int rubbleTile = BLOCKING_RUBBLE_TILE;
/** Show how many frames we are rendering per second
* default OFF, turn ON via console command 'showfps'
*/
bool showFPS = false; //
/** Show how many samples we are rendering per second
* default OFF, turn ON via console command 'showsamples'
*/
bool showSAMPLES = false;
/** Show the current selected units order / action
* default OFF, turn ON via console command 'showorders'
*/
bool showORDERS = false;
/** Show the current level name on the screen, toggle via the 'showlevelname'
* console command
*/
bool showLevelName = true;
/** When we have a connection issue, we will flash a message on screen
*/
static bool errorWaiting = false;
static char errorMessage[512];
static uint32_t lastErrorTime = 0;
#define NETWORK_FORM_ID 0xFAAA
#define NETWORK_BUT_ID 0xFAAB
/** When enabled, this causes a segfault in the game, to test out the crash handler */
bool CauseCrash = false;
/** tells us in realtime, what droid is doing (order / action)
*/
char DROIDDOING[512];
/// Geometric offset which will be passed to pie_SetGeometricOffset
static const int geoOffset = 192;
/// The average terrain height for the center of the area the camera is looking at
static int averageCentreTerrainHeight;
/** The time at which a sensor target was last asssigned
* Used to draw a visual effect.
*/
static UDWORD lastTargetAssignation = 0;
/** The time at which an order concerning a destination was last given
* Used to draw a visual effect.
*/
static UDWORD lastDestAssignation = 0;
static bool bSensorTargetting = false;
static bool bDestTargetting = false;
static BASE_OBJECT *psSensorObj = NULL;
static UDWORD destTargetX,destTargetY;
static UDWORD destTileX=0,destTileY=0;
struct Blueprint
{
Blueprint(STRUCTURE_STATS const *stats, Vector2i pos, uint16_t dir, uint32_t index, STRUCT_STATES state)
: stats(stats)
, pos(pos)
, dir(dir)
, index(index)
, state(state)
{}
int compare(Blueprint const &b) const
{
if (stats->ref != b.stats->ref) return stats->ref < b.stats->ref? -1 : 1;
if (pos.x != b.pos.x) return pos.x < b.pos.x? -1 : 1;
if (pos.y != b.pos.y) return pos.y < b.pos.y? -1 : 1;
if (dir != b.dir) return dir < b.dir? -1 : 1;
if (index != b.index) return index < b.index? -1 : 1;
if (state != b.state) return state < b.state? -1 : 1;
return 0;
}
bool operator <(Blueprint const &b) const { return compare(b) < 0; }
bool operator ==(Blueprint const &b) const { return compare(b) == 0; }
STRUCTURE *buildBlueprint() const ///< Must delete after use.
{
return ::buildBlueprint(stats, pos, dir, index, state);
}
void renderBlueprint() const
{
if (clipXY(pos.x, pos.y))
{
STRUCTURE *psStruct = buildBlueprint();
renderStructure(psStruct);
delete psStruct;
}
}
STRUCTURE_STATS const *stats;
Vector2i pos;
uint16_t dir;
uint32_t index;
STRUCT_STATES state;
};
static std::vector<Blueprint> blueprints;
#define TARGET_TO_SENSOR_TIME ((4*(GAME_TICKS_PER_SEC))/5)
#define DEST_TARGET_TIME (GAME_TICKS_PER_SEC/4)
/// The distance the selection box will pulse
#define BOX_PULSE_SIZE 10
/// the opacity at which building blueprints will be drawn
static const int BLUEPRINT_OPACITY=120;
/******************** Functions ********************/
static inline void rotateSomething(int &x, int &y, uint16_t angle)
{
int64_t cra = iCos(angle), sra = iSin(angle);
int newX = (x*cra - y*sra)>>16;
int newY = (x*sra + y*cra)>>16;
x = newX;
y = newY;
}
void NotifyUserOfError(char *msg)
{
errorWaiting = true;
ssprintf(errorMessage, "%s", msg);
lastErrorTime = gameTime2;
}
static Blueprint getTileBlueprint(int mapX, int mapY)
{
Vector2i mouse(world_coord(mapX) + TILE_UNITS/2, world_coord(mapY) + TILE_UNITS/2);
for (std::vector<Blueprint>::const_iterator blueprint = blueprints.begin(); blueprint != blueprints.end(); ++blueprint)
{
Vector2i size = getStructureStatsSize(blueprint->stats, blueprint->dir)*TILE_UNITS;
if (abs(mouse.x - blueprint->pos.x) < size.x/2 && abs(mouse.y - blueprint->pos.y) < size.y/2)
{
return *blueprint;
}
}
return Blueprint(NULL, Vector2i(), 0, 0, SS_BEING_BUILT);
}
STRUCTURE *getTileBlueprintStructure(int mapX, int mapY)
{
static STRUCTURE *psStruct = NULL;
Blueprint blueprint = getTileBlueprint(mapX, mapY);
if (blueprint.state == SS_BLUEPRINT_PLANNED)
{
delete psStruct; // Delete previously returned structure, if any.
psStruct = blueprint.buildBlueprint();
return psStruct; // This blueprint was clicked on.
}
return NULL;
}
STRUCTURE_STATS const *getTileBlueprintStats(int mapX, int mapY)
{
return getTileBlueprint(mapX, mapY).stats;
}
bool anyBlueprintTooClose(STRUCTURE_STATS const *stats, Vector2i pos, uint16_t dir)
{
for (std::vector<Blueprint>::const_iterator blueprint = blueprints.begin(); blueprint != blueprints.end(); ++blueprint)
{
if ((blueprint->state == SS_BLUEPRINT_PLANNED || blueprint->state == SS_BLUEPRINT_PLANNED_BY_ALLY)
&& isBlueprintTooClose(stats, pos, dir, blueprint->stats, blueprint->pos, blueprint->dir))
{
return true;
}
}
return false;
}
void clearBlueprints()
{
blueprints.clear();
}
static PIELIGHT structureBrightness(STRUCTURE *psStructure)
{
PIELIGHT buildingBrightness;
if (structureIsBlueprint(psStructure))
{
buildingBrightness = getBlueprintColour(psStructure->status);
}
else
{
buildingBrightness = pal_SetBrightness(200 - 100/65536.f * getStructureDamage(psStructure));
/* If it's selected, then it's brighter */
if (psStructure->selected)
{
SDWORD brightVar;
if (!gamePaused())
{
brightVar = getModularScaledGraphicsTime(990, 110);
if (brightVar > 55)
{
brightVar = 110 - brightVar;
}
}
else
{
brightVar = 55;
}
buildingBrightness = pal_SetBrightness(200 + brightVar);
}
if (!demoGetStatus() && !getRevealStatus())
{
buildingBrightness = pal_SetBrightness(avGetObjLightLevel((BASE_OBJECT*)psStructure, buildingBrightness.byte.r));
}
if (!hasSensorOnTile(mapTile(map_coord(psStructure->pos.x), map_coord(psStructure->pos.y)), selectedPlayer))
{
buildingBrightness.byte.r /= 2;
buildingBrightness.byte.g /= 2;
buildingBrightness.byte.b /= 2;
}
}
return buildingBrightness;
}
/// Display the multiplayer chat box
static void displayMultiChat(void)
{
iV_SetFont(font_regular);
UDWORD pixelLength;
UDWORD pixelHeight;
pixelLength = iV_GetTextWidth(sTextToSend);
pixelHeight = iV_GetTextLineSize();
if((realTime % 500) < 250)
{
// implement blinking cursor in multiplayer chat
pie_BoxFill(RET_X + pixelLength + 3, 474 + E_H - (pixelHeight/4), RET_X + pixelLength + 10, 473 + E_H, WZCOL_CURSOR);
}
/* FIXME: GET RID OF THE MAGIC NUMBERS BELOW */
iV_TransBoxFill(RET_X + 1, 474 + E_H - pixelHeight, RET_X + 1 + pixelLength + 2, 473 + E_H);
iV_DrawText(sTextToSend, RET_X + 3, 469 + E_H);
}
/// Cached values
static SDWORD gridCentreX,gridCentreZ,gridVarCalls;
/// Get the cached value for the X center of the grid
SDWORD getCentreX( void )
{
gridVarCalls++;
return(gridCentreX);
}
/// Get the cached value for the Z center of the grid
SDWORD getCentreZ( void )
{
return(gridCentreZ);
}
/// Show all droid movement parts by displaying an explosion at every step
static void showDroidPaths(void)
{
DROID *psDroid;
if ((graphicsTime / 250 % 2) != 0)
{
return;
}
for (psDroid = apsDroidLists[selectedPlayer]; psDroid; psDroid=psDroid->psNext)
{
if (psDroid->selected && psDroid->sMove.Status != MOVEINACTIVE)
{
int len = psDroid->sMove.numPoints;
int i = std::max(psDroid->sMove.pathIndex - 1, 0);
for (; i < len; i++)
{
Vector3i pos;
ASSERT(worldOnMap(psDroid->sMove.asPath[i].x, psDroid->sMove.asPath[i].y), "Path off map!");
pos.x = psDroid->sMove.asPath[i].x;
pos.z = psDroid->sMove.asPath[i].y;
pos.y = map_Height(pos.x, pos.z) + 16;
effectGiveAuxVar(80);
addEffect(&pos, EFFECT_EXPLOSION, EXPLOSION_TYPE_LASER, false, NULL, 0);
}
}
}
}
/// Renders the Network Issue form
static void NetworkDisplayPlainForm(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
{
W_TABFORM *Form = (W_TABFORM*)psWidget;
UDWORD x0,y0,x1,y1;
x0 = xOffset+Form->x;
y0 = yOffset+Form->y;
x1 = x0 + Form->width;
y1 = y0 + Form->height;
// Don't draw anything, a rectangle behind the icon just looks strange, if you notice it.
//RenderWindowFrame(FRAME_NORMAL, x0, y0, x1 - x0, y1 - y0);
(void)x0;
(void)y0;
(void)x1;
(void)y1;
}
/// Displays an image for the Network Issue button
static void NetworkDisplayImage(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours)
{
UDWORD x = xOffset+psWidget->x;
UDWORD y = yOffset+psWidget->y;
UWORD ImageID;
CONNECTION_STATUS status = (CONNECTION_STATUS)UNPACKDWORD_TRI_A(psWidget->UserData);
ASSERT( psWidget->type == WIDG_BUTTON,"Not a button" );
// cheap way to do a button flash
if ( (gameTime2/250) % 2 == 0 )
{
ImageID = UNPACKDWORD_TRI_B(psWidget->UserData);
}
else
{
ImageID = UNPACKDWORD_TRI_C(psWidget->UserData);
}
if (NETcheckPlayerConnectionStatus(status, NET_ALL_PLAYERS))
{
unsigned width, height;
unsigned n, c = 0;
char players[MAX_PLAYERS + 1];
PlayerMask playerMaskMapped = 0;
for (n = 0; n < MAX_PLAYERS; ++n)
{
if (NETcheckPlayerConnectionStatus(status, n))
{
playerMaskMapped |= 1<<NetPlay.players[n].position;
}
}
for (n = 0; n < MAX_PLAYERS; ++n)
{
if ((playerMaskMapped & 1<<n) != 0)
{
STATIC_ASSERT(MAX_PLAYERS <= 32); // If increasing MAX_PLAYERS, check all the 1<<playerNumber shifts, since the 1 is usually a 32-bit type.
players[c++] = "0123456789ABCDEFGHIJKLMNOPQRSTUV"[n];
}
}
players[c] = '\0';
width = iV_GetTextWidth(players) + 10;
height = iV_GetTextHeight(players) + 10;
iV_DrawText(players, x - width, y + height);
}
iV_DrawImage(IntImages,ImageID,x,y);
}
static void setupConnectionStatusForm(void)
{
static unsigned prevStatusMask = 0;
const int separation = 3;
unsigned statusMask = 0;
unsigned total = 0;
unsigned i;
for (i = 0; i < CONNECTIONSTATUS_NORMAL; ++i)
{
if (NETcheckPlayerConnectionStatus((CONNECTION_STATUS)i, NET_ALL_PLAYERS))
{
statusMask |= 1<<i;
++total;
}
}
if (prevStatusMask != 0 && statusMask != prevStatusMask)
{
// Remove the icons.
for (i = 0; i < CONNECTIONSTATUS_NORMAL; ++i)
{
if ((statusMask & 1<<i) != 0)
{
widgDelete(psWScreen, NETWORK_BUT_ID + i); // kill button
}
}
widgDelete(psWScreen, NETWORK_FORM_ID); // kill form
prevStatusMask = 0;
}
if (prevStatusMask == 0 && statusMask != 0)
{
unsigned n = 0;
// Create the basic form
W_FORMINIT sFormInit;
sFormInit.formID = 0;
sFormInit.id = NETWORK_FORM_ID;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = (int)(pie_GetVideoBufferWidth() - 52);
sFormInit.y = 80;
sFormInit.width = 36;
sFormInit.height = (24 + separation)*total - separation;
sFormInit.pDisplay = NetworkDisplayPlainForm; // NetworkDisplayPlainForm used to do something, but it looks ugly.
if (!widgAddForm(psWScreen, &sFormInit))
{
//return false;
}
/* Now add the buttons */
for (i = 0; i < CONNECTIONSTATUS_NORMAL; ++i)
{
if ((statusMask & 1<<i) == 0)
{
continue;
}
//set up default button data
W_BUTINIT sButInit;
sButInit.formID = NETWORK_FORM_ID;
sButInit.id = NETWORK_BUT_ID + i;
sButInit.width = 36;
sButInit.height = 24;
//add button
sButInit.style = WBUT_PLAIN;
sButInit.x = 0;
sButInit.y = (24 + separation)*n;
sButInit.pDisplay = NetworkDisplayImage;
// Note we would set the image to be different based on which issue it is.
switch (i)
{
default:
ASSERT(false, "Bad connection status value.");
sButInit.pTip = "Bug";
sButInit.UserData = PACKDWORD_TRI(0, IMAGE_DESYNC_HI, IMAGE_PLAYER_LEFT_LO);
break;
case CONNECTIONSTATUS_PLAYER_LEAVING:
sButInit.pTip = _("Player left");
sButInit.UserData = PACKDWORD_TRI(i, IMAGE_PLAYER_LEFT_HI, IMAGE_PLAYER_LEFT_LO);
break;
case CONNECTIONSTATUS_PLAYER_DROPPED:
sButInit.pTip = _("Player dropped");
sButInit.UserData = PACKDWORD_TRI(i, IMAGE_DISCONNECT_LO, IMAGE_DISCONNECT_HI);
break;
case CONNECTIONSTATUS_WAITING_FOR_PLAYER:
sButInit.pTip = _("Waiting for other players");
sButInit.UserData = PACKDWORD_TRI(i, IMAGE_WAITING_HI, IMAGE_WAITING_LO);
break;
case CONNECTIONSTATUS_DESYNC:
sButInit.pTip = _("Out of sync");
sButInit.UserData = PACKDWORD_TRI(i, IMAGE_DESYNC_HI, IMAGE_DESYNC_LO);
break;
}
if (!widgAddButton(psWScreen, &sButInit))
{
//return false;
}
++n;
}
prevStatusMask = statusMask;
}
}
/// Render the 3D world
void draw3DScene( void )
{
// the world centre - used for decaying lighting etc
gridCentreX = player.p.x;
gridCentreZ = player.p.z;
/* What frame number are we on? */
currentGameFrame = frameGetFrameNumber();
// Tell shader system what the time is
pie_SetShaderTime(graphicsTime);
/* Build the drag quad */
if(dragBox3D.status == DRAG_RELEASED)
{
dragQuad.coords[0].x = dragBox3D.x1; // TOP LEFT
dragQuad.coords[0].y = dragBox3D.y1;
dragQuad.coords[1].x = dragBox3D.x2; // TOP RIGHT
dragQuad.coords[1].y = dragBox3D.y1;
dragQuad.coords[2].x = dragBox3D.x2; // BOTTOM RIGHT
dragQuad.coords[2].y = dragBox3D.y2;
dragQuad.coords[3].x = dragBox3D.x1; // BOTTOM LEFT
dragQuad.coords[3].y = dragBox3D.y2;
}
pie_Begin3DScene();
/* Set 3D world origins */
pie_SetGeometricOffset(rendSurface.width / 2, geoOffset);
// draw terrain
displayTerrain();
pie_BeginInterface();
drawDroidSelections();
drawStructureSelections();
if (radarOnScreen && radarPermitted)
{
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
pie_SetFogStatus(false);
if (getWidgetsStatus())
{
drawRadar();
}
pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
pie_SetFogStatus(true);
}
if (!bRender3DOnly)
{
/* Ensure that any text messages are displayed at bottom of screen */
pie_SetFogStatus(false);
displayConsoleMessages();
}
pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_OFF);
pie_SetFogStatus(false);
iV_SetTextColour(WZCOL_TEXT_BRIGHT);
/* Dont remove this folks!!!! */
if(!bAllowOtherKeyPresses)
{
displayMultiChat();
}
if (errorWaiting)
{
if (lastErrorTime + (60 * GAME_TICKS_PER_SEC) < gameTime2)
{
char trimMsg[255];
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
ssprintf(trimMsg, "Error! (Check your logs!): %.78s", errorMessage);
addConsoleMessage(trimMsg, DEFAULT_JUSTIFY, NOTIFY_MESSAGE);
errorWaiting = false;
}
}
if (showSAMPLES) //Displays the number of sound samples we currently have
{
iV_SetFont(font_regular);
unsigned int width, height;
const char *Qbuf, *Lbuf, *Abuf;
sasprintf((char**)&Qbuf,"Que: %04u",audio_GetSampleQueueCount());
sasprintf((char**)&Lbuf,"Lst: %04u",audio_GetSampleListCount());
sasprintf((char**)&Abuf,"Act: %04u",sound_GetActiveSamplesCount());
width = iV_GetTextWidth(Qbuf) + 11;
height = iV_GetTextHeight(Qbuf);
iV_DrawText(Qbuf, pie_GetVideoBufferWidth() - width, height + 2);
iV_DrawText(Lbuf, pie_GetVideoBufferWidth() - width, height + 48);
iV_DrawText(Abuf, pie_GetVideoBufferWidth() - width, height + 59);
}
if (showFPS)
{
iV_SetFont(font_regular);
unsigned int width, height;
const char* fps;
sasprintf((char**)&fps, "FPS: %d", frameRate());
width = iV_GetTextWidth(fps) + 10;
height = iV_GetTextHeight(fps);
iV_DrawText(fps, pie_GetVideoBufferWidth() - width, pie_GetVideoBufferHeight() - height);
}
if (showORDERS)
{
iV_SetFont(font_regular);
unsigned int height;
height = iV_GetTextHeight(DROIDDOING);
iV_DrawText(DROIDDOING, 0, pie_GetVideoBufferHeight()- height);
}
setupConnectionStatusForm();
if (getWidgetsStatus() && !gamePaused())
{
char buildInfo[255];
if (showLevelName)
{
iV_SetFont(font_small);
iV_SetTextColour(WZCOL_TEXT_MEDIUM);
iV_DrawText( getLevelName(), RET_X + 134, 410 + E_H );
}
getAsciiTime(buildInfo, graphicsTime);
iV_DrawText( buildInfo, RET_X + 134, 422 + E_H );
if (getDebugMappingStatus() && !demoGetStatus())
{
iV_DrawText( "DEBUG ", RET_X + 134, 436 + E_H );
}
}
while(player.r.y>DEG(360))
{
player.r.y-=DEG(360);
}
/* If we don't have an active camera track, then track terrain height! */
if(!getWarCamStatus())
{
/* Move the autonomous camera if necessary */
calcAverageTerrainHeight(&player);
trackHeight(averageCentreTerrainHeight+CAMERA_PIVOT_HEIGHT);
}
else
{
processWarCam();
}
if(demoGetStatus())
{
flushConsoleMessages();
setConsolePermanence(true, true);
permitNewConsoleMessages(true);
addConsoleMessage("Warzone 2100 : Pumpkin Studios ", RIGHT_JUSTIFY,SYSTEM_MESSAGE);
permitNewConsoleMessages(false);
}
processDemoCam();
processSensorTarget();
processDestinationTarget();
structureEffects(); // add fancy effects to structures
showDroidSensorRanges(); //shows sensor data for units/droids/whatever...-Q 5-10-05
if (CauseCrash)
{
char *crash = 0;
#ifdef DEBUG
ASSERT(false, "Yes, this is a assert. This should not happen on release builds! Use --noassert to bypass in debug builds.");
debug(LOG_WARNING, " *** Warning! You have compiled in debug mode! ***");
#endif
writeGameInfo("WZdebuginfo.txt"); //also test writing out this file.
debug(LOG_FATAL, "Forcing a segfault! (crash handler test)");
// and here comes the crash
*crash = 0x3;
exit(-1); // will never reach this, but just in case...
}
//visualize radius if needed
if (bRangeDisplay)
{
drawRangeAtPos(rangeCenterX,rangeCenterY,rangeRadius);
}
if (showPath)
{
showDroidPaths();
}
}
/// Draws the 3D textured terrain
static void displayTerrain(void)
{
/* We haven't yet located which tile mouse is over */
mouseLocated = false;
pie_PerspectiveBegin();
/* Now, draw the terrain */
drawTiles(&player);
pie_PerspectiveEnd();
/* Show the drag Box if necessary */
drawDragBox();
/* Have we released the drag box? */
if(dragBox3D.status == DRAG_RELEASED)
{
dragBox3D.status = DRAG_INACTIVE;
}
}
/***************************************************************************/
bool doWeDrawProximitys( void )
{
return(bDrawProximitys);
}
/***************************************************************************/
void setProximityDraw(bool val)
{
bDrawProximitys = val;
}
/***************************************************************************/
/// Calculate the average terrain height for the area directly below the player
static void calcAverageTerrainHeight(iView *player)
{
int numTilesAveraged = 0, i, j;
/* We track the height here - so make sure we get the average heights
of the tiles directly underneath us
*/
averageCentreTerrainHeight = 0;
for (i = -4; i <= 4; i++)
{
for (j = -4; j <= 4; j++)
{
if (tileOnMap(playerXTile + j, playerZTile + i))
{
/* Get a pointer to the tile at this location */
MAPTILE *psTile = mapTile(playerXTile + j, playerZTile + i);
averageCentreTerrainHeight += psTile->height;
numTilesAveraged++;
}
}
}
/* Work out the average height. We use this information to keep the player camera
* above the terrain. */
if (numTilesAveraged) // might not be if off map
{
MAPTILE *psTile = mapTile(playerXTile, playerZTile);
averageCentreTerrainHeight /= numTilesAveraged;
if (averageCentreTerrainHeight < psTile->height)
{
averageCentreTerrainHeight = psTile->height;
}
}
else
{
averageCentreTerrainHeight = ELEVATION_SCALE * TILE_UNITS;
}
}
/// Draw the terrain and all droids, missiles and other objects on it
static void drawTiles(iView *player)
{
int i, j;
int idx, jdx;
Vector3f theSun;
/* ---------------------------------------------------------------- */
/* Do boundary and extent checking */
/* ---------------------------------------------------------------- */
/* Find our position in tile coordinates */
playerXTile = map_coord(player->p.x);
playerZTile = map_coord(player->p.z);
/* ---------------------------------------------------------------- */
/* Set up the geometry */
/* ---------------------------------------------------------------- */
/* ---------------------------------------------------------------- */
/* Push identity matrix onto stack */
pie_MatBegin();
actualCameraPosition = Vector3i(0, 0, 0);
/* Set the camera position */
pie_TRANSLATE(0, 0, distance);
actualCameraPosition.z -= distance;
// Now, scale the world according to what resolution we're running in
pie_MatScale(pie_GetResScalingFactor() / 100.f);
actualCameraPosition.z /= pie_GetResScalingFactor() / 100.f;
/* Rotate for the player */
pie_MatRotZ(player->r.z);
pie_MatRotX(player->r.x);
pie_MatRotY(player->r.y);
rotateSomething(actualCameraPosition.x, actualCameraPosition.y, -player->r.z);
rotateSomething(actualCameraPosition.y, actualCameraPosition.z, -player->r.x);
rotateSomething(actualCameraPosition.z, actualCameraPosition.x, -player->r.y);
/* Translate */
pie_TRANSLATE(0, -player->p.y, 0);