forked from Warzone2100/warzone2100
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiint.cpp
4518 lines (3929 loc) · 128 KB
/
multiint.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
*/
/*
* MultiInt.c
*
* Alex Lee, 98. Pumpkin Studios, Bath.
* Functions to display and handle the multiplayer interface screens,
* along with connection and game options.
*/
#include "lib/framework/wzapp.h"
#include "lib/framework/wzconfig.h"
#include <time.h>
#include "lib/framework/frameresource.h"
#include "lib/framework/frameint.h"
#include "lib/framework/file.h"
#include "lib/framework/stdio_ext.h"
/* Includes direct access to render library */
#include "lib/ivis_opengl/bitimage.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/piedef.h"
#include "lib/ivis_opengl/piestate.h"
#include "lib/ivis_opengl/pieclip.h"
#include "lib/ivis_opengl/piemode.h"
#include "lib/ivis_opengl/piepalette.h"
#include "lib/ivis_opengl/piematrix.h" // for setgeometricoffset
#include "lib/ivis_opengl/screen.h"
#include "lib/gamelib/gtime.h"
#include "lib/netplay/netplay.h"
#include "lib/script/script.h"
#include "lib/widget/editbox.h"
#include "lib/widget/button.h"
#include "lib/widget/widget.h"
#include "lib/widget/widgint.h"
#include "lib/widget/label.h"
#include "challenge.h"
#include "main.h"
#include "objects.h"
#include "display.h"// pal stuff
#include "display3d.h"
#include "objmem.h"
#include "gateway.h"
#include "configuration.h"
#include "intdisplay.h"
#include "design.h"
#include "hci.h"
#include "power.h"
#include "loadsave.h" // for blueboxes.
#include "component.h"
#include "map.h"
#include "console.h" // chat box stuff
#include "frend.h"
#include "advvis.h"
#include "frontend.h"
#include "data.h"
#include "keymap.h"
#include "game.h"
#include "warzoneconfig.h"
#include "modding.h"
#include "qtscript.h"
#include "random.h"
#include "multiplay.h"
#include "multiint.h"
#include "multijoin.h"
#include "multistat.h"
#include "multirecv.h"
#include "multimenu.h"
#include "multilimit.h"
#include "multigifts.h"
#include "warzoneconfig.h"
#include "init.h"
#include "levels.h"
#include "wrappers.h"
#define MAP_PREVIEW_DISPLAY_TIME 2500 // number of milliseconds to show map in preview
// ////////////////////////////////////////////////////////////////////////////
// tertile dependant colors for map preview
// C1 - Arizona type
#define WZCOL_TERC1_CLIFF_LOW pal_Colour(0x68, 0x3C, 0x24)
#define WZCOL_TERC1_CLIFF_HIGH pal_Colour(0xE8, 0x84, 0x5C)
#define WZCOL_TERC1_WATER pal_Colour(0x3F, 0x68, 0x9A)
#define WZCOL_TERC1_ROAD_LOW pal_Colour(0x24, 0x1F, 0x16)
#define WZCOL_TERC1_ROAD_HIGH pal_Colour(0xB2, 0x9A, 0x66)
#define WZCOL_TERC1_GROUND_LOW pal_Colour(0x24, 0x1F, 0x16)
#define WZCOL_TERC1_GROUND_HIGH pal_Colour(0xCC, 0xB2, 0x80)
// C2 - Urban type
#define WZCOL_TERC2_CLIFF_LOW pal_Colour(0x3C, 0x3C, 0x3C)
#define WZCOL_TERC2_CLIFF_HIGH pal_Colour(0x84, 0x84, 0x84)
#define WZCOL_TERC2_WATER WZCOL_TERC1_WATER
#define WZCOL_TERC2_ROAD_LOW pal_Colour(0x00, 0x00, 0x00)
#define WZCOL_TERC2_ROAD_HIGH pal_Colour(0x24, 0x1F, 0x16)
#define WZCOL_TERC2_GROUND_LOW pal_Colour(0x1F, 0x1F, 0x1F)
#define WZCOL_TERC2_GROUND_HIGH pal_Colour(0xB2, 0xB2, 0xB2)
// C3 - Rockies type
#define WZCOL_TERC3_CLIFF_LOW pal_Colour(0x3C, 0x3C, 0x3C)
#define WZCOL_TERC3_CLIFF_HIGH pal_Colour(0xFF, 0xFF, 0xFF)
#define WZCOL_TERC3_WATER WZCOL_TERC1_WATER
#define WZCOL_TERC3_ROAD_LOW pal_Colour(0x24, 0x1F, 0x16)
#define WZCOL_TERC3_ROAD_HIGH pal_Colour(0x3D, 0x21, 0x0A)
#define WZCOL_TERC3_GROUND_LOW pal_Colour(0x00, 0x1C, 0x0E)
#define WZCOL_TERC3_GROUND_HIGH WZCOL_TERC3_CLIFF_HIGH
static const unsigned gnImage[] = {IMAGE_GN_0, IMAGE_GN_1, IMAGE_GN_2, IMAGE_GN_3, IMAGE_GN_4, IMAGE_GN_5, IMAGE_GN_6, IMAGE_GN_7, IMAGE_GN_8, IMAGE_GN_9, IMAGE_GN_10, IMAGE_GN_11, IMAGE_GN_12, IMAGE_GN_13, IMAGE_GN_14, IMAGE_GN_15};
// ////////////////////////////////////////////////////////////////////////////
// vars
extern char MultiCustomMapsPath[PATH_MAX];
extern char MultiPlayersPath[PATH_MAX];
extern bool bSendingMap; // used to indicate we are sending a map
bool bHosted = false; //we have set up a game
char sPlayer[128]; // player name (to be used)
static int colourChooserUp = -1;
static int teamChooserUp = -1;
static int aiChooserUp = -1;
static int difficultyChooserUp = -1;
static int positionChooserUp = -1;
static bool SettingsUp = false;
static UBYTE InitialProto = 0;
static W_SCREEN *psConScreen;
static SDWORD dwSelectedGame =0; //player[] and games[] indexes
static UDWORD gameNumber; // index to games icons
static bool safeSearch = false; // allow auto game finding.
static bool disableLobbyRefresh = false; // if we allow lobby to be refreshed or not.
static UDWORD hideTime=0;
static bool EnablePasswordPrompt = false; // if we need the password prompt
LOBBY_ERROR_TYPES LobbyError = ERROR_NOERROR;
static bool allowChangePosition = true;
static char tooltipbuffer[MaxGames][256] = {{'\0'}};
/// end of globals.
// ////////////////////////////////////////////////////////////////////////////
// Function protos
// widget functions
static bool addMultiEditBox(UDWORD formid, UDWORD id, UDWORD x, UDWORD y, char const *tip, char const *tipres, UDWORD icon, UDWORD iconhi, UDWORD iconid);
static void addBlueForm (UDWORD parent,UDWORD id, const char *txt,UDWORD x,UDWORD y,UDWORD w,UDWORD h);
static void drawReadyButton(UDWORD player);
static void displayPasswordEditBox(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, WZ_DECL_UNUSED PIELIGHT *pColours);
// Drawing Functions
static void displayChatEdit (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayMultiBut (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void intDisplayFeBox (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayRemoteGame (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayPlayer (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayPosition (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayColour (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayTeamChooser (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayAi (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayDifficulty (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void displayMultiEditBox (WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset, PIELIGHT *pColours);
static void setLockedTeamsMode (void);
// find games
static void addGames (void);
static void removeGames (void);
// password form functions
static void hidePasswordForm(void);
static void showPasswordForm(void);
// Game option functions
static void addGameOptions();
static void addChatBox (void);
static void addConsoleBox(void);
static void disableMultiButs (void);
static void processMultiopWidgets(UDWORD);
static void SendFireUp (void);
static void decideWRF (void);
static void closeColourChooser (void);
static void closeTeamChooser (void);
static void closePositionChooser (void);
static void closeAiChooser (void);
static void closeDifficultyChooser (void);
static bool SendColourRequest (UBYTE player, UBYTE col);
static bool SendPositionRequest (UBYTE player, UBYTE chosenPlayer);
static bool safeToUseColour (UDWORD player,UDWORD col);
static bool changeReadyStatus (UBYTE player, bool bReady);
static void stopJoining(void);
static int difficultyIcon(int difficulty);
// ////////////////////////////////////////////////////////////////////////////
// map previews..
static const char *difficultyList[] = { N_("Easy"), N_("Medium"), N_("Hard"), N_("Insane") };
static const int difficultyValue[] = { 1, 10, 15, 20 };
struct AIDATA
{
char name[MAX_LEN_AI_NAME];
char slo[MAX_LEN_AI_NAME];
char vlo[MAX_LEN_AI_NAME];
char js[MAX_LEN_AI_NAME];
char tip[255];
int assigned; ///< How many AIs have we assigned of this type
};
static std::vector<AIDATA> aidata;
/// Player name overrides
static char nameOverrides[MAX_PLAYERS][MAX_LEN_AI_NAME];
const char *getAIName(int player)
{
if (NetPlay.players[player].ai >= 0)
{
return aidata[NetPlay.players[player].ai].name;
}
else
{
return "";
}
}
int getNextAIAssignment(const char *name)
{
int ai = matchAIbyName(name);
int match = aidata[ai].assigned;
for (int i = 0; i < game.maxPlayers; i++)
{
if (ai == NetPlay.players[i].ai)
{
if (match == 0)
{
aidata[ai].assigned++;
debug(LOG_SAVE, "wzscript assigned to player %d", i);
return i; // found right player
}
match--; // find next of this type
}
}
return AI_NOT_FOUND;
}
void loadMultiScripts()
{
bool defaultRules = true;
// Reset assigned counter
std::vector<AIDATA>::iterator it;
for (it = aidata.begin(); it < aidata.end(); it++)
{
(*it).assigned = 0;
}
// Load extra script for challenges
if (challengeActive)
{
debug(LOG_SAVE, "Loading challenge scripts");
WzConfig challenge(sRequestResult);
challenge.beginGroup("scripts");
if (challenge.contains("extra"))
{
loadGlobalScript("challenges/" + challenge.value("extra").toString());
}
if (challenge.contains("rules"))
{
loadGlobalScript("challenges/" + challenge.value("rules").toString());
defaultRules = false;
}
challenge.endGroup();
}
// Load multiplayer rules
resForceBaseDir("messages/");
resLoadFile("SMSG", "multiplay.txt");
if (defaultRules)
{
debug(LOG_SAVE, "Loading default rules");
loadGlobalScript("multiplay/skirmish/rules.js");
}
// Backup data hashes, since AI and scavenger scripts aren't run on all clients.
uint32_t oldHash1 = DataHash[DATA_SCRIPT];
uint32_t oldHash2 = DataHash[DATA_SCRIPTVAL];
// Load AI players
resForceBaseDir("multiplay/skirmish/");
for (int i = 0; i < game.maxPlayers; i++)
{
if (NetPlay.players[i].ai < 0 && i == selectedPlayer)
{
NetPlay.players[i].ai = 0; // For autogames.
}
// The i == selectedPlayer hack is to enable autogames
if (bMultiPlayer && game.type == SKIRMISH && (!NetPlay.players[i].allocated || i == selectedPlayer)
&& NetPlay.players[i].ai >= 0 && myResponsibility(i))
{
if (challengeActive) // challenge file may override
{
WzConfig challenge(sRequestResult); // so inefficient, but no other way
challenge.beginGroup("player_" + QString::number(i + 1));
if (challenge.contains("ai"))
{
QString val = challenge.value("ai").toString();
challenge.endGroup();
if (val.compare("null") == 0)
{
continue; // no AI
}
loadPlayerScript(val, i, NetPlay.players[i].difficulty);
NetPlay.players[i].ai = AI_CUSTOM;
continue;
}
challenge.endGroup();
}
if (aidata[NetPlay.players[i].ai].slo[0] != '\0')
{
debug(LOG_SAVE, "Loading wzscript AI for player %d", i);
resLoadFile("SCRIPT", aidata[NetPlay.players[i].ai].slo);
resLoadFile("SCRIPTVAL", aidata[NetPlay.players[i].ai].vlo);
}
// autogames are to be implemented differently for qtscript, do not start for human players yet
if (!NetPlay.players[i].allocated && aidata[NetPlay.players[i].ai].js[0] != '\0')
{
debug(LOG_SAVE, "Loading javascript AI for player %d", i);
loadPlayerScript(QString("multiplay/skirmish/") + aidata[NetPlay.players[i].ai].js, i, NetPlay.players[i].difficulty);
}
}
}
// Load scavengers
if (game.scavengers && myResponsibility(scavengerPlayer()))
{
debug(LOG_SAVE, "Loading scavenger AI for player %d", scavengerPlayer());
loadPlayerScript("multiplay/script/scavfact.js", scavengerPlayer(), DIFFICULTY_EASY);
}
// Restore data hashes, since AI and scavenger scripts aren't run on all clients.
DataHash[DATA_SCRIPT] = oldHash1; // Not all players load the same AI scripts.
DataHash[DATA_SCRIPTVAL] = oldHash2;
// Reset resource path, otherwise things break down the line
resForceBaseDir("");
}
static int guessMapTilesetType(LEVEL_DATASET *psLevel)
{
unsigned t = 0, c = 0;
if (psLevel->psBaseData && psLevel->psBaseData->pName)
{
if (sscanf(psLevel->psBaseData->pName, "MULTI_CAM_%u", &c) != 1)
{
sscanf(psLevel->psBaseData->pName, "MULTI_T%u_C%u", &t, &c);
}
}
switch (c)
{
case 1:
return TILESET_ARIZONA;
break;
case 2:
return TILESET_URBAN;
break;
case 3:
return TILESET_ROCKIES;
break;
}
debug(LOG_MAP, "Could not guess map tileset, using ARIZONA.");
return TILESET_ARIZONA;
}
static void loadEmptyMapPreview()
{
// No map is available to preview, so improvise.
char *imageData = (char *)malloc(BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT * 3);
memset(imageData, 0, BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT * 3); //dunno about background color
int const ex = 100, ey = 100, bx = 5, by = 8;
for (unsigned n = 0; n < 125; ++n)
{
int sx = rand()%(ex - bx), sy = rand()%(ey - by);
char col[3] = {char(rand()%256), char(rand()%256), char(rand()%256)};
for (unsigned y = 0; y < by; ++y)
for (unsigned x = 0; x < bx; ++x)
if (("\2\1\261\11\6"[x]>>y & 1) == 1) // ?
memcpy(imageData + 3*(sx + x + BACKDROP_HACK_WIDTH*(sy + y)), col, 3);
}
// Slight hack to init array with a special value used to determine how many players on map
Vector2i playerpos[MAX_PLAYERS];
memset(playerpos, 0x77, sizeof(playerpos));
screen_enableMapPreview((char *)"This string is written somewhere and then ignored.", ex, ey, playerpos);
screen_Upload(imageData, true);
free(imageData);
}
/// Loads the entire map just to show a picture of it
void loadMapPreview(bool hideInterface)
{
static char aFileName[256];
UDWORD fileSize;
char *pFileData = NULL;
LEVEL_DATASET *psLevel = NULL;
PIELIGHT plCliffL, plCliffH, plWater, plRoadL, plRoadH, plGroundL, plGroundH;
UDWORD x, y, height;
UBYTE col;
MAPTILE *psTile,*WTile;
UDWORD oursize;
Vector2i playerpos[MAX_PLAYERS]; // Will hold player positions
char *ptr = NULL, *imageData = NULL;
// absurd hack, since there is a problem with updating this crap piece of info, we're setting it to
// true by default for now, like it used to be
game.mapHasScavengers = true; // this is really the wrong place for it, but this is where it has to be
if(psMapTiles)
{
mapShutdown();
}
// load the terrain types
psLevel = levFindDataSet(game.map, &game.hash);
if (psLevel == NULL)
{
debug(LOG_INFO, "Could not find level dataset \"%s\" %s. Probably waiting for download.", game.map, game.hash.toString().c_str());
loadEmptyMapPreview();
return;
}
setCurrentMap(psLevel->realFileName, psLevel->players);
if (psLevel->realFileName == NULL)
{
debug(LOG_WZ, "Loading map preview: \"%s\" builtin t%d", psLevel->pName, psLevel->dataDir);
}
else
{
debug(LOG_WZ, "Loading map preview: \"%s\" in \"%s\" %s t%d", psLevel->pName, psLevel->realFileName, psLevel->realFileHash.toString().c_str(), psLevel->dataDir);
}
rebuildSearchPath(psLevel->dataDir, false);
sstrcpy(aFileName,psLevel->apDataFiles[0]);
aFileName[strlen(aFileName)-4] = '\0';
sstrcat(aFileName, "/ttypes.ttp");
pFileData = fileLoadBuffer;
if (!loadFileToBuffer(aFileName, pFileData, FILE_LOAD_BUFFER_SIZE, &fileSize))
{
debug(LOG_ERROR, "Failed to load terrain types file");
return;
}
if (pFileData)
{
if (!loadTerrainTypeMap(pFileData, fileSize))
{
debug(LOG_ERROR, "Failed to load terrain types");
return;
}
}
// load the map data
ptr = strrchr(aFileName, '/');
ASSERT_OR_RETURN(, ptr, "this string was supposed to contain a /");
strcpy(ptr, "/game.map");
if (!mapLoad(aFileName, true))
{
debug(LOG_ERROR, "Failed to load map");
return;
}
gwShutDown();
// set tileset colors
switch (guessMapTilesetType(psLevel))
{
case TILESET_ARIZONA:
plCliffL = WZCOL_TERC1_CLIFF_LOW;
plCliffH = WZCOL_TERC1_CLIFF_HIGH;
plWater = WZCOL_TERC1_WATER;
plRoadL = WZCOL_TERC1_ROAD_LOW;
plRoadH = WZCOL_TERC1_ROAD_HIGH;
plGroundL = WZCOL_TERC1_GROUND_LOW;
plGroundH = WZCOL_TERC1_GROUND_HIGH;
break;
case TILESET_URBAN:
plCliffL = WZCOL_TERC2_CLIFF_LOW;
plCliffH = WZCOL_TERC2_CLIFF_HIGH;
plWater = WZCOL_TERC2_WATER;
plRoadL = WZCOL_TERC2_ROAD_LOW;
plRoadH = WZCOL_TERC2_ROAD_HIGH;
plGroundL = WZCOL_TERC2_GROUND_LOW;
plGroundH = WZCOL_TERC2_GROUND_HIGH;
break;
case TILESET_ROCKIES:
plCliffL = WZCOL_TERC3_CLIFF_LOW;
plCliffH = WZCOL_TERC3_CLIFF_HIGH;
plWater = WZCOL_TERC3_WATER;
plRoadL = WZCOL_TERC3_ROAD_LOW;
plRoadH = WZCOL_TERC3_ROAD_HIGH;
plGroundL = WZCOL_TERC3_GROUND_LOW;
plGroundH = WZCOL_TERC3_GROUND_HIGH;
break;
}
oursize = sizeof(char) * BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT;
imageData = (char*)malloc(oursize * 3); // used for the texture
if( !imageData )
{
debug(LOG_FATAL,"Out of memory for texture!");
abort(); // should be a fatal error ?
return;
}
ptr = imageData;
memset(ptr, 0, sizeof(char) * BACKDROP_HACK_WIDTH * BACKDROP_HACK_HEIGHT * 3); //dunno about background color
psTile = psMapTiles;
for (y = 0; y < mapHeight; y++)
{
WTile = psTile;
for (x = 0; x < mapWidth; x++)
{
char * const p = imageData + (3 * (y * BACKDROP_HACK_WIDTH + x));
height = WTile->height / ELEVATION_SCALE;
col = height;
switch (terrainType(WTile))
{
case TER_CLIFFFACE:
p[0] = plCliffL.byte.r + (plCliffH.byte.r-plCliffL.byte.r) * col / 256;
p[1] = plCliffL.byte.g + (plCliffH.byte.g-plCliffL.byte.g) * col / 256;
p[2] = plCliffL.byte.b + (plCliffH.byte.b-plCliffL.byte.b) * col / 256;
break;
case TER_WATER:
p[0] = plWater.byte.r;
p[1] = plWater.byte.g;
p[2] = plWater.byte.b;
break;
case TER_ROAD:
p[0] = plRoadL.byte.r + (plRoadH.byte.r-plRoadL.byte.r) * col / 256;
p[1] = plRoadL.byte.g + (plRoadH.byte.g-plRoadL.byte.g) * col / 256;
p[2] = plRoadL.byte.b + (plRoadH.byte.b-plRoadL.byte.b) * col / 256;
break;
default:
p[0] = plGroundL.byte.r + (plGroundH.byte.r-plGroundL.byte.r) * col / 256;
p[1] = plGroundL.byte.g + (plGroundH.byte.g-plGroundL.byte.g) * col / 256;
p[2] = plGroundL.byte.b + (plGroundH.byte.b-plGroundL.byte.b) * col / 256;
break;
}
WTile += 1;
}
psTile += mapWidth;
}
// Slight hack to init array with a special value used to determine how many players on map
memset(playerpos,0x77,sizeof(playerpos));
// color our texture with clancolors @ correct position
plotStructurePreview16(imageData, playerpos);
screen_enableMapPreview(aFileName, mapWidth, mapHeight, playerpos);
screen_Upload(imageData, true);
free(imageData);
if (hideInterface)
{
hideTime = gameTime;
}
mapShutdown();
}
// ////////////////////////////////////////////////////////////////////////////
// helper func
int matchAIbyName(const char *name)
{
std::vector<AIDATA>::iterator it;
int i = 0;
if (name[0] == '\0')
{
return AI_CLOSED;
}
for (it = aidata.begin(); it < aidata.end(); it++, i++)
{
if (strncasecmp(name, (*it).name, MAX_LEN_AI_NAME) == 0)
{
return i;
}
}
return AI_NOT_FOUND;
}
void readAIs()
{
char basepath[PATH_MAX];
const char *sSearchPath = "multiplay/skirmish/";
char **i, **files;
aidata.clear();
strcpy(basepath, sSearchPath);
files = PHYSFS_enumerateFiles(basepath);
for (i = files; *i != NULL; ++i)
{
char path[PATH_MAX];
// See if this filename contains the extension we're looking for
if (!strstr(*i, ".ai"))
{
continue;
}
sstrcpy(path, basepath);
sstrcat(path, *i);
WzConfig aiconf(path);
if (aiconf.status() != QSettings::NoError)
{
debug(LOG_ERROR, "Failed to open AI %s", path);
continue;
}
AIDATA ai;
aiconf.beginGroup("AI");
sstrcpy(ai.name, aiconf.value("name", "error").toString().toAscii().constData());
sstrcpy(ai.slo, aiconf.value("slo", "").toString().toAscii().constData());
sstrcpy(ai.vlo, aiconf.value("vlo", "").toString().toAscii().constData());
sstrcpy(ai.js, aiconf.value("js", "").toString().toAscii().constData());
sstrcpy(ai.tip, aiconf.value("tip", "Click to choose this AI").toString().toAscii().constData());
if (strcmp(ai.name, "Nexus") == 0)
{
std::vector<AIDATA>::iterator it;
it = aidata.begin();
aidata.insert(it, ai);
}
else
{
aidata.push_back(ai);
}
}
PHYSFS_freeList(files);
}
//sets sWRFILE form game.map
static void decideWRF(void)
{
// try and load it from the maps directory first,
sstrcpy(aLevelName, MultiCustomMapsPath);
sstrcat(aLevelName, game.map);
sstrcat(aLevelName, ".wrf");
debug(LOG_WZ, "decideWRF: %s", aLevelName);
//if the file exists in the downloaded maps dir then use that one instead.
// FIXME: Try to incorporate this into physfs setup somehow for sane paths
if ( !PHYSFS_exists(aLevelName) )
{
sstrcpy(aLevelName, game.map); // doesn't exist, must be a predefined one.
}
}
// ////////////////////////////////////////////////////////////////////////////
// Connection Options Screen.
static bool OptionsInet(void) //internet options
{
psConScreen = widgCreateScreen();
widgSetTipFont(psConScreen,font_regular);
W_FORMINIT sFormInit; //Connection Settings
sFormInit.formID = 0;
sFormInit.id = CON_SETTINGS;
sFormInit.style = WFORM_PLAIN;
sFormInit.x = CON_SETTINGSX;
sFormInit.y = CON_SETTINGSY;
sFormInit.width = CON_SETTINGSWIDTH;
sFormInit.height = CON_SETTINGSHEIGHT;
sFormInit.pDisplay = intDisplayFeBox;
widgAddForm(psConScreen, &sFormInit);
addMultiBut(psConScreen, CON_SETTINGS,CON_OK,CON_OKX,CON_OKY,MULTIOP_OKW,MULTIOP_OKH,
_("Accept Settings"),IMAGE_OK,IMAGE_OK,true);
addMultiBut(psConScreen, CON_SETTINGS,CON_IP_CANCEL,CON_OKX+MULTIOP_OKW+10,CON_OKY,MULTIOP_OKW,MULTIOP_OKH,
_("Cancel"),IMAGE_NO,IMAGE_NO,true);
//label.
W_LABINIT sLabInit;
sLabInit.formID = CON_SETTINGS;
sLabInit.id = CON_SETTINGS_LABEL;
sLabInit.style = WLAB_ALIGNCENTRE;
sLabInit.x = 0;
sLabInit.y = 10;
sLabInit.width = CON_SETTINGSWIDTH;
sLabInit.height = 20;
sLabInit.pText = _("IP Address or Machine Name");
widgAddLabel(psConScreen, &sLabInit);
W_EDBINIT sEdInit; // address
sEdInit.formID = CON_SETTINGS;
sEdInit.id = CON_IP;
sEdInit.x = CON_IPX;
sEdInit.y = CON_IPY;
sEdInit.width = CON_NAMEBOXWIDTH;
sEdInit.height = CON_NAMEBOXHEIGHT;
sEdInit.pText = ""; //_("IP Address or Machine Name");
sEdInit.pBoxDisplay = intDisplayEditBox;
if (!widgAddEditBox(psConScreen, &sEdInit))
{
return false;
}
// auto click in the text box
W_CONTEXT sContext;
sContext.psScreen = psConScreen;
sContext.psForm = (W_FORM *)psConScreen->psForm;
sContext.xOffset = 0;
sContext.yOffset = 0;
sContext.mx = 0;
sContext.my = 0;
widgGetFromID(psConScreen, CON_IP)->clicked(&sContext);
SettingsUp = true;
return true;
}
// ////////////////////////////////////////////////////////////////////////////
// Draw the connections screen.
bool startConnectionScreen(void)
{
addBackdrop(); //background
addTopForm(); // logo
addBottomForm();
SettingsUp = false;
InitialProto = 0;
safeSearch = false;
// don't pretend we are running a network game. Really do it!
NetPlay.bComms = true; // use network = true
addSideText(FRONTEND_SIDETEXT, FRONTEND_SIDEX, FRONTEND_SIDEY,_("CONNECTION"));
addMultiBut(psWScreen,FRONTEND_BOTFORM,CON_CANCEL,10,10,MULTIOP_OKW,MULTIOP_OKH,
_("Return To Previous Screen"), IMAGE_RETURN, IMAGE_RETURN_HI, IMAGE_RETURN_HI); // goback buttpn levels
addTextButton(CON_TYPESID_START+0,FRONTEND_POS2X,FRONTEND_POS2Y, _("Lobby"), WBUT_TXTCENTRE);
addTextButton(CON_TYPESID_START+1,FRONTEND_POS3X,FRONTEND_POS3Y, _("IP"), WBUT_TXTCENTRE);
return true;
}
void runConnectionScreen(void)
{
UDWORD id;
static char addr[128];
if(SettingsUp == true)
{
id = widgRunScreen(psConScreen); // Run the current set of widgets
}
else
{
id = widgRunScreen(psWScreen); // Run the current set of widgets
}
switch(id)
{
case CON_CANCEL: //cancel
changeTitleMode(MULTI);
bMultiPlayer = false;
bMultiMessages = false;
break;
case CON_TYPESID_START+0: // Lobby button
if (LobbyError != ERROR_INVALID)
{
setLobbyError(ERROR_NOERROR);
}
changeTitleMode(GAMEFIND);
break;
case CON_TYPESID_START+1: // IP button
OptionsInet();
break;
case CON_OK:
sstrcpy(addr, widgGetString(psConScreen, CON_IP));
if (addr[0] == '\0')
{
sstrcpy(addr, "127.0.0.1"); // Default to localhost.
}
if(SettingsUp == true)
{
widgReleaseScreen(psConScreen);
SettingsUp = false;
}
joinGame(addr, 0);
break;
case CON_IP_CANCEL:
if (SettingsUp == true)
{
widgReleaseScreen(psConScreen);
SettingsUp = false;
}
break;
}
widgDisplayScreen(psWScreen); // show the widgets currently running
if(SettingsUp == true)
{
widgDisplayScreen(psConScreen); // show the widgets currently running
}
if (CancelPressed())
{
changeTitleMode(MULTI);
}
}
// ////////////////////////////////////////////////////////////////////////
// Lobby error reading
LOBBY_ERROR_TYPES getLobbyError(void)
{
return LobbyError;
}
void setLobbyError (LOBBY_ERROR_TYPES error_type)
{
LobbyError = error_type;
if (LobbyError <= ERROR_FULL)
{
disableLobbyRefresh = false;
}
else
{
disableLobbyRefresh = true;
}
}
/**
* Try connecting to the given host, show
* the multiplayer screen or a error.
*/
bool joinGame(const char* host, uint32_t port)
{
PLAYERSTATS playerStats;
if(ingame.localJoiningInProgress)
{
return false;
}
if (!NETjoinGame(host, port, (char*)sPlayer)) // join
{
switch (getLobbyError())
{
case ERROR_HOSTDROPPED:
setLobbyError(ERROR_NOERROR);
break;
case ERROR_WRONGPASSWORD:
// Change to GAMEFIND, screen with a password dialog.
changeTitleMode(GAMEFIND);
showPasswordForm();
if (widgRunScreen(psWScreen) != CON_PASSWORD) // Run the current set of widgets
{
return false;
}
NETsetGamePassword(widgGetString(psWScreen, CON_PASSWORD));
break;
default:
break;
}
// Hide a (maybe shown) password form.
hidePasswordForm();
// Change to GAMEFIND, screen.
changeTitleMode(GAMEFIND);
// Shows the lobby error.
addGames();
addConsoleBox();
return false;
}
ingame.localJoiningInProgress = true;
loadMultiStats(sPlayer,&playerStats);
setMultiStats(selectedPlayer, playerStats, false);
setMultiStats(selectedPlayer, playerStats, true);
changeTitleMode(MULTIOPTION);
if (war_getMPcolour() >= 0)
{
SendColourRequest(selectedPlayer, war_getMPcolour());
}
return true;
}
// ////////////////////////////////////////////////////////////////////////////
// Game Chooser Screen.
static void addGames(void)
{
UDWORD i,gcount=0;
static const char *wrongVersionTip = "Your version of Warzone is incompatible with this game.";
static const char *badModTip = "Your loaded mods are incompatible with this game. (Check mods/autoload/?)";
//count games to see if need two columns.
for(i=0;i<MaxGames;i++) // draw games
{
if( NetPlay.games[i].desc.dwSize !=0)
{
gcount++;
}
}
W_BUTINIT sButInit;
sButInit.formID = FRONTEND_BOTFORM;
sButInit.width = GAMES_GAMEWIDTH;
sButInit.height = GAMES_GAMEHEIGHT;
sButInit.pDisplay = displayRemoteGame;
// we want the old games deleted, and only list games when we should
if (getLobbyError() || !gcount)
{
for(i = 0; i<MaxGames; i++)
{
widgDelete(psWScreen, GAMES_GAMESTART+i); // remove old widget
}
gcount = 0;
}
// in case they refresh, and a game becomes available.
widgDelete(psWScreen, FRONTEND_NOGAMESAVAILABLE);
// only have to do this if we have any games available.
if (!getLobbyError() && gcount)
{
for (i=0; i<MaxGames; i++) // draw games
{
widgDelete(psWScreen, GAMES_GAMESTART+i); // remove old icon.
if (NetPlay.games[i].desc.dwSize !=0)
{
sButInit.id = GAMES_GAMESTART+i;
sButInit.x = 20;
sButInit.y = (UWORD)(45+((5+GAMES_GAMEHEIGHT)*i) );
// display the correct tooltip message.
if (!NETisCorrectVersion(NetPlay.games[i].game_version_major, NetPlay.games[i].game_version_minor))
{
sButInit.pTip = wrongVersionTip;
}
else if (strcmp(NetPlay.games[i].modlist,getModList()) != 0)
{
sButInit.pTip = badModTip;
}
else
{
std::string flags;
if (NetPlay.games[i].privateGame)
{
flags += " "; flags += _("[Password required]");
}
if (NetPlay.games[i].limits & NO_TANKS)
{
flags += " "; flags += _("[No Tanks]");
}
if (NetPlay.games[i].limits & NO_BORGS)
{
flags += " "; flags += _("[No Cyborgs]");
}
if (NetPlay.games[i].limits & NO_VTOLS)
{
flags += " "; flags += _("[No VTOLs]");
}
if (flags.empty())
{
ssprintf(tooltipbuffer[i], _("Hosted by %s"), NetPlay.games[i].hostname);
}
else
{
ssprintf(tooltipbuffer[i], _("Hosted by %s —%s"), NetPlay.games[i].hostname, flags.c_str());