-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcallbacks.c
1709 lines (1500 loc) · 47.7 KB
/
callbacks.c
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
/*
* XFrisk - The classic board game for X
* Copyright (C) 1993-1999 Elan Feingold ([email protected])
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: callbacks.c,v 1.17 2000/01/17 21:53:06 tony Exp $
*
* Used by client/AI
* Notes:
* should not use X, so ai can be compiled on X-less box
* is included by riskgame.c, maybe fix there?
* or this be the X part, and move out other messages?
*/
#include <X11/X.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/List.h>
#include <X11/Xaw/Toggle.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "language.h"
#include "network.h"
#include "gui-vars.h"
#include "gui-func.h"
#include "utils.h"
#include "callbacks.h"
#include "version.h"
#include "riskgame.h"
#include "client.h"
#include "dice.h"
#include "cards.h"
#include "game.h"
#include "colormap.h"
#include "help.h"
#include "colorEdit.h"
#include "registerPlayers.h"
#include "debug.h"
#include "viewStats.h"
/* Game globals -- move elsewhere? -- make part of riskgame object state! */
static Flag fPlayingRemotely=FALSE;
static Flag fForceExchange=FALSE;
static Int32 iCountryToFortify=-1;
static Int32 piMsgDstPlayerID[MAX_PLAYERS+1];
static Flag fWaitMission = FALSE;
static Flag fHaveSeenFirstPlayer;
Int32 iIndexMD;
Int32 iActionState=ACTION_PLACE;
Int32 iReply;
CString pstrMsgDstCString[MAX_PLAYERS+1];
Int32 iFirstPlayer;
Int32 iState, iCurrentPlayer;
Flag fGameStarted=FALSE;
/************************************************************************
* FUNCTION: CBK_XIncomingMessage
* HISTORY:
* 03.17.94 ESF Created.
* 06.24.94 ESF Fixed memory leak bug.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_XIncomingMessage(XtPointer pClientData, int *iSource, XtInputId *id)
{
Int32 iMessType;
void *pvMess;
UNUSED(pClientData);
UNUSED(id);
(void)RISK_ReceiveMessage(*iSource, &iMessType, &pvMess);
CBK_IncomingMessage(iMessType, pvMess);
NET_DeleteMessage(iMessType, pvMess);
}
/************************************************************************
* FUNCTION: CBK_IncomingMessage
* HISTORY:
* 01.26.94 ESF Created.
* 01.27.94 ESF Coded MSG_MESSAGEPACKET case.
* 01.29.94 ESF Changed MSG_MESSAGEPACKET to scroll correctly.
* 02.05.94 ESF Added MSG_REGISTERPLAYER handling.
* 03.02.94 ESF Added more army placing glue.
* 03.04.94 ESF Factored out code, cleaned up.
* 03.05.94 ESF Added color-coded player turn indicator call.
* 03.06.94 ESF Fixed initialization of iCurrentPlayer bug.
* 03.16.94 ESF Added continent bonuses.
* 03.17.94 ESF Factored out X code so that this could be more general.
* 03.17.94 ESF Fixed bug, player indicator broken for remote case.
* 03.17.94 ESF Added fPlayingRemotely setting.
* 03.18.94 ESF Completed MSG_UPDATEARMIES code.
* 03.28.94 ESF Added code for MSG_ENDOFGAME and MSG_DEADPLAYER.
* 03.29.94 ESF Added code for MSG_CARDPACKET.
* 03.29.94 ESF Fixed bug in handling on MSG_UPDATEARMIES.
* 03.29.94 ESF Added handling for MSG_REPLYPACKET.
* 04.11.94 ESF Added handling for MSG_CARDPACKET.
* 05.12.94 ESF Added handling for MSG_DELETEMSGDST.
* 05.17.94 ESF Added handling for MSG_NETMESSAGE.
* 05.19.94 ESF Added verbose message when exit occurs.
* 08.28.94 ESF Added handling for MSG_POPUPREGISTERBOX.
* 09.01.94 ESF Added handling for MSG_NETPOPUP.
* 10.29.94 ESF Added handling for MSG_DICEROLL.
* 10.29.94 ESF Added handling for MSG_MOVENOTIFY.
* 10.29.94 ESF Added handling for MSG_ATTACKNOTIFY.
* 10.29.94 ESF Added handling for MSG_PLACEROLL.
* 01.15.95 ESF Removed handling for MSG_DELETEMSGDST.
* 24.08.95 JC Added handling for MSG_MISSION.
* 25.08.95 JC new game if MSG_ENDOFGAME and winner is -1.
* 25.08.95 JC Start the game only after a fortification.
* 28.08.95 JC Added handling for MSG_ENDOFMISSION, MSG_VICTORY.
* Now MSG_ENDOFGAME => new game
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_IncomingMessage(Int32 iMessType, void *pvMess)
{
switch(iMessType)
{
case MSG_NOMESSAGE:
/* NoOp */
break;
case MSG_NETMESSAGE:
UTIL_DisplayComment(((MsgNetMessage *)(pvMess))->strMessage);
break;
case MSG_PLACENOTIFY:
{
/* Copy the message, since we are using it for a while */
MsgPlaceNotify *msgMess =
(MsgPlaceNotify *)MEM_Alloc(sizeof(MsgPlaceNotify));
memcpy((void *)msgMess, (void *)pvMess, sizeof(MsgPlaceNotify));
/* Do the notification, and then add a timeout for erasing it */
UTIL_PlaceNotification((XtPointer)msgMess, NULL);
XtAppAddTimeOut(appContext, NOTIFY_TIME,
UTIL_PlaceNotification, msgMess);
}
break;
case MSG_MOVENOTIFY:
{
/* Copy the message, since we are using it for a while */
MsgMoveNotify *msgMess =
(MsgMoveNotify *)MEM_Alloc(sizeof(MsgMoveNotify));
memcpy((void *)msgMess, (void *)pvMess, sizeof(MsgMoveNotify));
/* Do the notification, and then add a timeout for erasing it */
UTIL_MoveNotification((XtPointer)msgMess, NULL);
XtAppAddTimeOut(appContext, NOTIFY_TIME,
UTIL_MoveNotification, msgMess);
}
break;
case MSG_ATTACKNOTIFY:
{
/* Copy the message, since we are using it for a while */
MsgAttackNotify *msgMess =
(MsgAttackNotify *)MEM_Alloc(sizeof(MsgAttackNotify));
memcpy((void *)msgMess, (void *)pvMess, sizeof(MsgAttackNotify));
/* Do the notification, and then add a timeout for erasing it */
UTIL_AttackNotification((XtPointer)msgMess, NULL);
XtAppAddTimeOut(appContext, NOTIFY_TIME,
UTIL_AttackNotification, msgMess);
}
break;
case MSG_DICEROLL:
{
MsgDiceRoll *pmsgDiceRoll = (MsgDiceRoll *)pvMess;
/* Set the dice colors to be the correct ones */
COLOR_CopyColor(COLOR_PlayerToColor(iCurrentPlayer),
COLOR_DieToColor(0));
COLOR_CopyColor(COLOR_PlayerToColor(pmsgDiceRoll->iDefendingPlayer),
COLOR_DieToColor(1));
/* Erase what was there, and then display the dice */
DICE_Hide();
DICE_DrawDice(pmsgDiceRoll->pAttackDice, pmsgDiceRoll->pDefendDice);
}
break;
case MSG_NETPOPUP:
{
#ifdef ENGLISH
(void)UTIL_PopupDialog("Message from Server",
((MsgNetPopup *)pvMess)->strMessage, 1,
"Ok", NULL, NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Message du Serveur",
((MsgNetPopup *)pvMess)->strMessage, 1,
"Oui", NULL, NULL);
#endif
}
break;
case MSG_POPUPREGISTERBOX:
{
/* Clear any text... */
UTIL_DisplayError("");
UTIL_DisplayComment("");
REG_PopupDialog();
}
break;
case MSG_FORCEEXCHANGECARDS:
{
if (iState != STATE_REGISTER)
{
if (((MsgForceExchangeCards *)pvMess)->iPlayer >= 0)
{
#ifdef ENGLISH
UTIL_DisplayComment("You have too many cards"
" and must exchange a set.");
#endif
#ifdef FRENCH
UTIL_DisplayComment("Vous avez trop de cartes"
" et devez échanger");
#endif
fForceExchange = fCanExchange = TRUE;
CBK_ShowCards((Widget)NULL, (XtPointer)NULL, (XtPointer)NULL);
iState = STATE_PLACE;
UTIL_ServerEnterState(iState);
}
}
}
break;
case MSG_REPLYPACKET:
iReply = ((MsgReplyPacket *)pvMess)->iReply;
break;
case MSG_ENDOFMISSION:
{
MsgEndOfMission *pmsgEndOfMission = (MsgEndOfMission *)pvMess;
Int32 iWinner = pmsgEndOfMission->iWinner;
D_Assert(iWinner >= 0 && iWinner < MAX_PLAYERS, "Bogus Winner!");
/* Print out a final message */
GAME_MissionAccomplied(iWinner, pmsgEndOfMission->iTyp,
pmsgEndOfMission->iNum1,
pmsgEndOfMission->iNum2);
}
break;
case MSG_VICTORY:
{
Int32 iWinner = ((MsgVictory *)pvMess)->iWinner;
D_Assert(iWinner >= 0 && iWinner < MAX_PLAYERS, "Bogus Winner!");
/* Print out a final message */
GAME_Victory(iWinner);
}
break;
case MSG_ENDOFGAME:
{
/* Set the cursor so that the client doesn't have
* the icon of the hourglass by any chance, because
* it doesn't really make sense.
*/
UTIL_SetCursorShape(CURSOR_PLAY);
/* Print out a final message */
fHaveSeenFirstPlayer = FALSE;
GAME_GameOverMan();
}
break;
case MSG_MESSAGEPACKET:
{
MsgMessagePacket *pMess = (MsgMessagePacket *)pvMess;
UTIL_DisplayMessage(pMess->iFrom, pMess->iTo, pMess->strMessage);
}
break;
case MSG_TURNNOTIFY:
{
#ifdef ASSERTIONS
Int32 i;
#endif
MsgTurnNotify *pTurn = (MsgTurnNotify *)pvMess;
iCurrentPlayer = pTurn->iPlayer;
if(!fHaveSeenFirstPlayer) {
fHaveSeenFirstPlayer = TRUE;
iFirstPlayer = iCurrentPlayer;
}
/* Set the color of the player color-coded indicator */
GUI_SetColorOfCurrentPlayer(COLOR_PlayerToColor(iCurrentPlayer));
if (pTurn->iClient == CLNT_GetThisClientID())
{
fPlayingRemotely = FALSE;
/* Set the cursor to indicate play */
UTIL_SetCursorShape(CURSOR_PLAY);
/* See if everyone has finished fortifying their territories.
* If they have not, then there is a serious problem.
*/
if (!fGameStarted && (iState == STATE_FORTIFY) &&
(RISK_GetNumArmiesOfPlayer(iCurrentPlayer) == 0))
{
fGameStarted = TRUE;
iCountryToFortify = -1;
#ifdef ASSERTIONS
/* Sanity check */
for (i=0;
i!=RISK_GetNumLivePlayers();
i++)
{
Int32 iPlayer = RISK_GetNthLivePlayer(i);
Int32 iFirstAttacker;
Int32 j;
D_Assert(RISK_GetNumArmiesOfPlayer(iPlayer)>=0,
"Bogus number of armies.");
D_Assert(RISK_GetNumArmiesOfPlayer(iPlayer) == 0,
"This player has armies and shouldn't!");
/* I not entirely sure this correct. But it's at least a
* little better than before. People who have already had
* their first turn are allowed to have cards. --Pac */
for(j=0;j!=RISK_GetNumLivePlayers();++j)
if(RISK_GetNthLivePlayer(j)==iFirstPlayer)
break;
D_Assert(j!=RISK_GetNumLivePlayers(),
"first player isn't alive?");
/* negative % positive = negative, unfortunately */
iFirstAttacker=j-NUM_COUNTRIES%RISK_GetNumLivePlayers();
while(iFirstAttacker<0)
iFirstAttacker+=RISK_GetNumLivePlayers();
iFirstAttacker=RISK_GetNthLivePlayer(iFirstAttacker);
D_Assert(iPlayer < iCurrentPlayer
|| iPlayer >= iFirstAttacker
|| RISK_GetNumCardsOfPlayer(iPlayer) == 0,
"This player has cards and shouldn't!");
}
#endif
}
if (fGameStarted)
{
/* Force the player to exchange if he or she possesses
* 5 cards or more.
*/
if (RISK_GetNumCardsOfPlayer(iCurrentPlayer) >= 5)
{
#ifdef ENGLISH
UTIL_DisplayComment("You have more than five cards"
" and must exchange a set.");
#endif
#ifdef FRENCH
UTIL_DisplayComment("Vous avez plus de cinq cartes"
" et devez échanger");
#endif
fForceExchange = TRUE;
CBK_ShowCards((Widget)NULL,
(XtPointer)NULL, (XtPointer)NULL);
}
/* Go into placing state, give the player as many armies as
* he or she deserves by dividing the total number of
* countries owned divided by 3, for a minimum of three
* armies.
*/
iState = STATE_PLACE;
UTIL_ServerEnterState(iState);
/* All of the armies should have been used up */
D_Assert(RISK_GetNumArmiesOfPlayer(iCurrentPlayer) == 0,
"Number of armies should be 0!");
GAME_SetTurnArmiesOfPlayer(iCurrentPlayer);
}
else if (iState == STATE_FORTIFY)
{
UTIL_ServerEnterState(iState);
if (iCountryToFortify != -1)
{
GAME_PlaceClick(iCountryToFortify, PLACE_ONE);
iCountryToFortify = -1;
UTIL_DisplayError("");
}
}
UTIL_DisplayActionCString(iState, iCurrentPlayer);
}
else
{
char buf[256];
fPlayingRemotely = TRUE;
/* Set the cursor to indicate waiting */
UTIL_SetCursorShape(CURSOR_WAIT);
#ifdef ENGLISH
snprintf(buf, sizeof(buf), "%s is playing remotely...",
#endif
#ifdef FRENCH
snprintf(buf, sizeof(buf), "%s joue à distance...",
#endif
RISK_GetNameOfPlayer(iCurrentPlayer));
UTIL_DisplayComment(buf);
}
}
break;
case MSG_EXIT:
/* Popup telling what happened */
#ifdef ENGLISH
(void)UTIL_PopupDialog("Exit Notification",
"Terminating game! Goodbye...",
1, "Ok", NULL, NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Notification d'abandon",
"Jeu terminé! Au revoir...",
1, "Ok", NULL, NULL);
#endif
close(CLNT_GetCommLinkOfClient(CLNT_GetThisClientID()));
CLNT_SetCommLinkOfClient(CLNT_GetThisClientID(), -1);
UTIL_ExitProgram(0);
break;
case MSG_MISSION:
{
Int32 iPlayer;
if (!fWaitMission)
{
if (UTIL_PlayerIsLocal(iCurrentPlayer))
iPlayer = iCurrentPlayer;
else if (UTIL_NumPlayersAtClient(CLNT_GetThisClientID()) == 1)
iPlayer = RISK_GetNthPlayerAtClient(CLNT_GetThisClientID(), 0);
else
iPlayer = -1;
if (iPlayer != -1)
{
GAME_ShowMission(iPlayer);
#ifdef ENGLISH
(void)UTIL_PopupDialog("Mission Notification",
"The mission is visible in the "
"message zone",
1, "Ok", NULL, NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Notification de mission",
"La mission est visible dans la "
"zone de message",
1, "Oui", NULL, NULL);
#endif
}
else
/* Popup telling what happened */
#ifdef ENGLISH
(void)UTIL_PopupDialog("Mission Notification",
"To view your mission, click on\n"
" mission's button",
1, "Ok", NULL, NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Notification de mission",
"Pour voir la mission, il faut \n"
"utiliser le bouton mission",
1, "Oui", NULL, NULL);
#endif
}
}
break;
default: {
char buf[256];
#ifdef ENGLISH
snprintf(buf, sizeof(buf), "CALLBACKS: Unhandled message (%d)",
iMessType);
(void)UTIL_PopupDialog("Fatal Error", buf, 1, "Ok", NULL, NULL);
#endif
#ifdef FRENCH
snprintf(buf, sizeof(buf), "CALLBACKS: message non géré(%d)",
iMessType);
(void)UTIL_PopupDialog("Erreur fatale", buf, 1, "Ok", NULL, NULL);
#endif
RISK_SendMessage(CLNT_GetCommLinkOfClient(CLNT_GetThisClientID()),
MSG_DEREGISTERCLIENT, NULL);
UTIL_ExitProgram(-1);
}
}
}
/************************************************************************
* FUNCTION: CBK_RefreshMap
* HISTORY:
* 01.27.94 ESF Created.
* 01.28.94 ESF Changed to work with pixmap.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_RefreshMap(Widget w, XtPointer pData, XtPointer pCalldata)
{
XExposeEvent *pExpose = (XExposeEvent *)pCalldata;
UNUSED(w);
UNUSED(pData);
XCopyArea(hDisplay, pixMapImage, hWindow, hGC,
pExpose->x, pExpose->y, pExpose->width, pExpose->height,
pExpose->x, pExpose->y);
}
#define DOUBLE_CLICK_TIME 300
/************************************************************************
* FUNCTION: CBK_MapClick
* HISTORY:
* 01.27.94 ESF Created
* 02.03.94 ESF Don't allocate colors in order, use mapping.
* 03.03.94 ESF Added some game glue.
* 03.07.94 ESF Made a lean, mean, fighting function. Look in game.c.
* 03.17.94 ESF Fixed remote case.
* 05.10.94 ESF Fixed to do nothing unless game has started.
* 10.02.94 ESF Added PLACE_ALL option.
* 06.09.95 JC Remember on click in fortify mode.
* 12.29.96 BPK Added multiple armies placement in fortification
* 01.17.00 ThH Now GAME_PlaceClick decides about number placed during fortify
* PURPOSE:
* NOTES: Handle click on map
************************************************************************/
void CBK_MapClick(Widget w, XEvent *pEvent, String *str, Cardinal *card)
{
Int32 x, y, iCountry;
char buf[256];
UNUSED(w);
UNUSED(str);
UNUSED(card);
if (iState == STATE_REGISTER)
return;
/* Find out the coordinates and time of the mouse click */
x = pEvent->xbutton.x;
y = pEvent->xbutton.y;
/* Find out what country was clicked on */
iCountry = COLOR_ColorToCountry(XGetPixel(pMapImage, x, y));
if (fPlayingRemotely)
{
if ( (UTIL_NumPlayersAtClient(CLNT_GetThisClientID()) == 1)
&& (iState == STATE_FORTIFY) && (iCountry < NUM_COUNTRIES))
{
if (iCountryToFortify == -1)
{
iCountryToFortify = iCountry;
snprintf(buf, sizeof(buf), "%s %s",
RISK_GetNameOfCountry(iCountryToFortify),
TXT_BE_FORTIFIED);
UTIL_DisplayError(buf);
return;
}
}
#ifdef ENGLISH
snprintf(buf, sizeof(buf), "Click as you may, it's %s's turn...",
#endif
#ifdef FRENCH
snprintf(buf, sizeof(buf), "Jouez avec le bouton, mais c'est le tour de %s...",
#endif
RISK_GetNameOfPlayer(iCurrentPlayer));
UTIL_DisplayError(buf);
return;
}
/* Erase previous errors */
UTIL_DisplayError("");
switch (iState)
{
case STATE_FORTIFY:
/*
* Changed so we can place multiple armies during fortification
* -- BPK
* -- TdH GAME_PlaceClick takes care of it now
* instead fall through */
case STATE_PLACE:
if (pEvent->xbutton.button == Button1)
GAME_PlaceClick(iCountry, PLACE_ONE);
else if (pEvent->xbutton.button == Button2)
GAME_PlaceClick(iCountry, PLACE_ALL);
else if (pEvent->xbutton.button == Button3)
GAME_PlaceClick(iCountry, PLACE_MULTIPLE);
break;
case STATE_ATTACK:
GAME_AttackClick(iCountry);
break;
case STATE_MOVE:
GAME_MoveClick(iCountry);
break;
default:
D_Assert(FALSE, "Shouldn't be here!");
}
}
/************************************************************************
* FUNCTION: CBK_Quit
* HISTORY:
* 01.29.94 ESF Created
* 04.02.94 ESF Added confirmation.
* 08.28.94 ESF Fixed to implement cleaner exit.
* 15.01.00 MSH Fixed to include Cancel button in English dialog
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_Quit(Widget w, XtPointer pData, XtPointer call_data)
{
Int32 rep;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
#ifdef ENGLISH
rep = UTIL_PopupDialog("Quit", "Quit Frisk or new game?", 3, "Quit", "New", "Cancel");
#endif
#ifdef FRENCH
rep = UTIL_PopupDialog("Quit", "Quitter Frisk ou nouvelle partie?", 3, "Quitter", "Nouvelle", "Annuler");
#endif
switch (rep)
{
case QUERY_YES:
{
UTIL_ExitProgram(0);
}
case QUERY_NO:
{
iState = STATE_REGISTER;
(void)RISK_SendMessage(CLNT_GetCommLinkOfClient(CLNT_GetThisClientID()),
MSG_ENDOFGAME, NULL);
}
}
}
/************************************************************************
* FUNCTION: CBK_ShowCards
* HISTORY:
* 02.19.94 ESF Created.
* 03.17.94 ESF Erase the error display.
* 05.04.94 ESF Fixed so that only the owner can see his or her cards.
* 05.10.94 ESF Fixed to do nothing unless game has started.
* 05.12.94 ESF Fixed to display correct cards.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_ShowCards(Widget w, XtPointer pData, XtPointer call_data)
{
Int32 i, iPlayer;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
#ifdef CARD_DEBUG
static Int32 j;
#endif
if (iState == STATE_REGISTER)
return;
UTIL_DisplayError("");
/* If the player clicking is the current player, show cards, otherwise,
* if there's more than one player at the client, issue an error, unless
* there's only one, in which case show his or her cards.
*/
if (UTIL_PlayerIsLocal(iCurrentPlayer))
iPlayer = iCurrentPlayer;
else if (UTIL_NumPlayersAtClient(CLNT_GetThisClientID()) == 1)
iPlayer = RISK_GetNthPlayerAtClient(CLNT_GetThisClientID(), 0);
else
{
iPlayer = -1;
#ifdef ENGLISH
(void)UTIL_PopupDialog("Error", "Wait until your turn!",
1, "Ok", "Cancel", NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Erreur", "Il faut attendre son tour!",
1, "Ok", "Annule", NULL);
#endif
}
/* If it's valid, display cards */
if (iPlayer >= 0)
{
XtPopup(wCardShell, XtGrabExclusive);
#ifdef CARD_DEBUG
for (i=0; i!=MAX_CARDS; i++)
{
CARD_RenderCard(j, i);
j = (++j) % NUM_CARDS;
}
#else
for (i=0; i!=RISK_GetNumCardsOfPlayer(iPlayer); i++)
CARDS_RenderCard(RISK_GetCardOfPlayer(iPlayer, i), i);
#endif
}
}
/************************************************************************
* FUNCTION: CBK_CancelCards
* HISTORY:
* 02.19.94 ESF Created.
* 03.17.94 ESF Added clearing of selections and unmappings.
* 04.01.94 ESF Fixed clearing of error when player cancels.
* 04.11.94 ESF Added not popping down the shell when !fForceExchange.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_CancelCards(Widget w, XtPointer pData, XtPointer call_data)
{
Int32 i;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
if (fForceExchange == TRUE)
#ifdef ENGLISH
(void)UTIL_PopupDialog("Error", "You must exchange cards!", 1,
"Ok", NULL, NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Erreur", "Il faut échanger des cartes!", 1,
"Ok", NULL, NULL);
#endif
else
{
UTIL_DisplayError("");
XtPopdown(wCardShell);
/* Unmap the cards and clear the selections */
for (i=0; i!=MAX_CARDS; i++)
{
XtUnmanageChild(wCardToggle[i]);
XtVaSetValues(wCardToggle[i], XtNstate, False, NULL);
}
}
}
/************************************************************************
* FUNCTION: CBK_ShowMission
* HISTORY:
* 16.08.95 JC Created.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_ShowMission(Widget w, XtPointer pData, XtPointer call_data)
{
Int32 iPlayer;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
if (iState == STATE_REGISTER)
return;
UTIL_DisplayError("");
/* If the player clicking is the current player, show cards, otherwise,
* if there's more than one player at the client, issue an error, unless
* there's only one, in which case show his or her cards.
*/
if (UTIL_PlayerIsLocal(iCurrentPlayer))
iPlayer = iCurrentPlayer;
else if (UTIL_NumPlayersAtClient(CLNT_GetThisClientID()) == 1)
iPlayer = RISK_GetNthPlayerAtClient(CLNT_GetThisClientID(), 0);
else
{
iPlayer = -1;
#ifdef ENGLISH
(void)UTIL_PopupDialog("Error", "Wait until your turn!",
1, "Ok", NULL, NULL);
#endif
#ifdef FRENCH
(void)UTIL_PopupDialog("Erreur", "Il faut attendre son tour!",
1, "Ok", NULL, NULL);
#endif
}
/* If it's valid, display mission */
if (iPlayer >= 0)
{
if (RISK_GetMissionTypeOfPlayer(iPlayer) == NO_MISSION)
{
#ifdef ENGLISH
if(UTIL_PopupDialog("Mission", "Play with a mission?",
2, "Ok", "Cancel", NULL) == QUERY_NO)
#endif
#ifdef FRENCH
if(UTIL_PopupDialog("Mission", "Jouer avec une mission?",
2, "Oui", "Annule", NULL) == QUERY_NO)
#endif
return;
fWaitMission = TRUE;
(void)RISK_SendSyncMessage(CLNT_GetCommLinkOfClient(CLNT_GetThisClientID()),
MSG_MISSION, NULL,
MSG_MISSION, CBK_IncomingMessage);
fWaitMission = FALSE;
}
GAME_ShowMission(iPlayer);
}
}
/************************************************************************
* FUNCTION: CBK_Attack
* HISTORY:
* 03.03.94 ESF Stubbed.
* 03.05.94 ESF Coded.
* 05.07.94 ESF Modified to work with Distributed RiskGame Object.
* 05.10.94 ESF Fixed to do nothing unless game has started.
* 05.19.94 ESF Fixed bug, not refering to DiceMode.
* 10.15.94 ESF Added flexibility.
* 01.17.95 ESF Free pItem.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_Attack(Widget w, XtPointer pData, XtPointer call_data)
{
XawListReturnStruct *pItem;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
if (iState == STATE_REGISTER)
return;
/* Don't do anything if current player is not local and there is not
* one player at this client.
*/
if (UTIL_PlayerIsLocal(iCurrentPlayer) == FALSE)
return;
/* I know this is silly, but hey... (We should get the data from pData?) */
pItem = XawListShowCurrent(wAttackList);
RISK_SetDiceModeOfPlayer(iCurrentPlayer, pItem->list_index);
/* Free up memory */
XtFree((void *)pItem);
}
/************************************************************************
* FUNCTION: CBK_Action
* HISTORY:
* 03.03.94 ESF Stubbed.
* 03.05.94 ESF Coded.
* 03.29.94 ESF Added player attack mode history.
* 05.07.94 ESF Modified to work with Distributed RiskGame Object.
* 05.10.94 ESF Fixed to do nothing unless game has started.
* 11.19.94 ESF Added a few UTIL_DisplayError("")'s, where needed.
* 01.17.95 ESF Free pItem.
* PURPOSE:
* NOTES:
************************************************************************/
void CBK_Action(Widget w, XtPointer pData, XtPointer call_data)
{
XawListReturnStruct *pItem;
UNUSED(w);
UNUSED(pData);
UNUSED(call_data);
if (iState == STATE_REGISTER)
return;
/* Don't do anything if current player is not local */
if (!UTIL_PlayerIsLocal(iCurrentPlayer))
return;
/* I know this is silly, but hey... (We should get the data from pData?) */
pItem = XawListShowCurrent(wActionList);
switch (pItem->list_index)
{
/*****************/
case ACTION_PLACE:
/*****************/
if (iState == STATE_PLACE || iState == STATE_FORTIFY)
{
UTIL_DisplayError("");
iActionState = pItem->list_index;
}
else /* Invalid */
{
#ifdef ENGLISH
UTIL_DisplayError("You've already placed your armies.");
#endif
#ifdef FRENCH
UTIL_DisplayError("Toutes vos armées sont déjà placée.");
#endif
XawListHighlight(wActionList, ACTION_ATTACK);
}
break;
/*******************/
case ACTION_ATTACK:
case ACTION_DOORDIE:
/*******************/
if (iState == STATE_ATTACK)
{
UTIL_DisplayError("");
iActionState = pItem->list_index;
/* Keep track of the type of attack selected */
RISK_SetAttackModeOfPlayer(iCurrentPlayer, pItem->list_index);
}
else if (iState == STATE_PLACE || iState == STATE_FORTIFY)
{
#ifdef ENGLISH
UTIL_DisplayError("You must finish placing your armies.");
#endif
#ifdef FRENCH
UTIL_DisplayError("Il faut finir de placer vos armées.");
#endif
XawListHighlight(wActionList, ACTION_PLACE);
}
else if (iState == STATE_MOVE) /* Must not have moved yet */
{
/* Keep track of the type of attack selected */
RISK_SetAttackModeOfPlayer(iCurrentPlayer, pItem->list_index);
iState = STATE_ATTACK;
UTIL_DisplayError("");
UTIL_ServerEnterState(iState);
UTIL_DisplayActionCString(iState, iCurrentPlayer);
}
break;
/****************/
case ACTION_MOVE:
/****************/
if (iState == STATE_MOVE)
{
UTIL_DisplayError("");
iActionState = pItem->list_index;
}
else if (iState == STATE_FORTIFY || iState == STATE_PLACE)
{