/
puerto.c
1888 lines (1534 loc) · 46.2 KB
/
puerto.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
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#if defined(WIN32)
#include <Winsock2.h>
#else
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
static const size_t INVALID_SOCKET = static_cast<size_t> (-1);
static const size_t SOCKET_ERROR = static_cast<size_t> (-1);
#endif
#include "merc.h"
#include "gameserv.h"
// #define CBUF_LEN 512
// #define CMD_LEN 256
// #define NAME_LEN 25
// #define CMD_GREETING 3
// #define CMD_DATA_PLIST 5
#define PR_CMD_CREATE_GAME 6
#define PR_CMD_LIST_GAMES 7
#define PR_CMD_DATA_GLIST 8
#define PR_CMD_JOIN_GAME 9
#define PR_CMD_VIEW_SELF 10
#define PR_CMD_SELF_VIEW 11
#define PR_CMD_VIEW_OTHER 12
#define PR_CMD_OTHER_VIEW 13
#define PR_CMD_VIEW_BUILDS 14
#define PR_CMD_BUILDS_VIEW 15
#define PR_CMD_VIEW_GAME 16
#define PR_CMD_GAME_VIEW 17
#define PR_CMD_CHOOSE_ROLE 18
#define PR_CMD_SELECT_PLANT 19
#define PR_CMD_PASS 20
#define PR_CMD_MOVE_COL 21
#define PR_CMD_REMOVE_COL 22
#define PR_CMD_BUILD 23
#define PR_CMD_CRAFT 24
#define PR_CMD_TRADE 25
#define PR_CMD_SHIP 26
#define PR_CMD_DISCARD 27
#define PR_CMD_VIEW_PLIST 28
#define PR_CMD_PLIST_VIEW 29
#define PR_CMD_SPECTATE 30
#define PR_MSG_GAME_CREATED 1
#define PR_MSG_HAS_JOINED 2
#define PR_MSG_JOIN 3
#define PR_MSG_GAME_START 4
#define PR_MSG_ROLE_CHOSEN 5
#define PR_MSG_PLANT_CHOSEN 6
#define PR_MSG_NEXT_PHASE 7
#define PR_MSG_NEXT_TURN 8
#define PR_MSG_PASS 9
#define PR_MSG_NEXT_GOV 10
#define PR_MSG_GAMEEND_COL 11
#define PR_MSG_GAMEEND_VPS 12
#define PR_MSG_GAMEEND_BUILD 13
#define PR_MSG_GET_COLS 14
#define PR_MSG_MOVE 15
#define PR_MSG_REMOVE 16
#define PR_MSG_BUILD 17
#define PR_MSG_CRAFTS 18
#define PR_MSG_CRAFT_ADD 19
#define PR_MSG_TRADE 20
#define PR_MSG_TRADE_CLEAR 21
#define PR_MSG_SHIP 22
#define PR_MSG_DISCARD 23
#define PR_MSG_FACTORY 24
#define PR_MSG_PROSPECT 25
#define PR_MSG_PHASE_DISCARD 26
#define PR_MSG_GAME_OVER 27
#define PR_MSG_POINTS 28
#define PR_MSG_GAME_WINNER 29
#define PR_MSG_GAME_TIED 30
#define PR_MSG_SPECTATE 31
#define PR_MSG_NOSPEC 32
#define PR_ERR_JOIN 1
#define PR_ERR_VIEW 2
#define PR_ERR_GAME_NOT_FOUND 3
#define PR_ERR_NOT_YOUR_TURN 4
#define PR_ERR_INVALID_ROLE 5
#define PR_ERR_ROLE_PICKED 6
#define PR_ERR_NOT_PLAYER 7
#define PR_ERR_WRONG_PHASE 8
#define PR_ERR_PLANTS_FULL 9
#define PR_ERR_PLANT_UNAVAIL 10
#define PR_ERR_CANT_QUARRY 11
#define PR_ERR_NO_QUARRY 12
#define PR_ERR_INVALID_MOVE 13
#define PR_ERR_FREE_SPACES 14
#define PR_ERR_BUILD_GONE 15
#define PR_ERR_BUILD_NOSPACE 16
#define PR_ERR_BUILD_COST 17
#define PR_ERR_CRAFT_INVALID 18
#define PR_ERR_CRAFT_NONE 19
#define PR_ERR_TRADE_NONE 20
#define PR_ERR_TRADE_SAME 21
#define PR_ERR_SHIP_DISCARD 22
#define PR_ERR_SHIP_NONE 23
#define PR_ERR_SHIP_FULL 24
#define PR_ERR_NO_WHARF 25
#define PR_ERR_CANT_WHARF 26
#define PR_ERR_BOAT_TAKEN 27
#define PR_ERR_MUST_SHIP 28
#define PR_ERR_MUST_DISCARD 29
#define PR_ERR_SHIP_MAIN 30
#define PR_ERR_DISCARD_NONE 31
#define PR_ERR_CHOOSE_ROLE 32
#define PR_ERR_CANT_SPEC 33
#define PR_ERR_BUILD_DUPLICATE 34
#define ROLE_SETTLER 0
#define ROLE_MAYOR 1
#define ROLE_BUILDER 2
#define ROLE_CRAFTSMAN 3
#define ROLE_TRADER 4
#define ROLE_CAPTAIN 5
#define ROLE_PROSPECTOR1 6
#define ROLE_PRESPECTOR2 7
const char * role_names[8] = { "Settler", "Mayor", "Builder", "Craftsman",
"Trader", "Captain", "Prospector", "Prospector" };
#define PLANT_CORN 0
#define PLANT_INDIGO 1
#define PLANT_SUGAR 2
#define PLANT_TOBACCO 3
#define PLANT_COFFEE 4
#define PLANT_QUARRY 5
const char * good_names[5] = { "corn", "indigo", "sugar", "tobacco", "coffee" };
const char * cgood_names[5] = { "{Ycorn{w", "{Bindigo{w", "{Wsugar{w", "{Rtobacco{w", "{ycoffee{w" };
struct player_data
{
char pname[NAME_LEN];
char buildings[12];
unsigned char plants[6];
unsigned char doubloons;
unsigned char goods[5];
unsigned char col_buildings[12];
unsigned char col_plants[6];
unsigned char col_SanJuan;
unsigned char col_unassigned;
unsigned char vps;
};
struct game_data
{
unsigned short gid;
char num_players;
char turn;
char num_turns;
unsigned char vps;
unsigned char quarries;
char col_supply;
unsigned char col_ship;
char roles[8];
char role_taken[8][NAME_LEN];
unsigned char goods[5];
char boat_goods[3];
char boat_types[3];
char thouse[4];
char plants_display[6];
char action;
};
struct building_data
{
char * name;
char * short_form;
char spaces;
char cost;
};
const struct building_data buildings[23] =
{
{ "Small Indigo Plant", "{BSml Indigo{x", 1, 1 },
{ "Small Sugar Mill", "{WSml Sugar{x", 1, 2 },
{ "Small Market", "{mSml Market{x", 1, 2 },
{ "Hacienda", "{mHacienda{x", 1, 2 },
{ "Construction Hut", "{mConstr Hut{x", 1, 2 },
{ "Small Warehouse", "{mSml Wareh{x", 1, 3 },
{ "Indigo Plant", "{BIndigo Pla{x", 3, 3 },
{ "Sugar Mill", "{WSugar Mill{x", 3, 4 },
{ "Hospice", "{mHospice{x", 1, 4 },
{ "Office", "{mOffice{x", 1, 5 },
{ "Large Market", "{mLrg Market{x", 1, 5 },
{ "Large Warehouse", "{mLrg Wareh{x", 1, 6 },
{ "Tobacco Storage", "{RTobacco St{x", 3, 5 },
{ "Coffee Roaster", "{yCoffee Rst{x", 2, 6 },
{ "Factory", "{mFactory{x", 1, 7 },
{ "University", "{mUniversity{x", 1, 8 },
{ "Harbor", "{mHarbor{x", 1, 8 },
{ "Wharf", "{mWharf{x", 1, 9 },
{ "Guild Hall", "{MGuild Hall{x", 1, 10 },
{ "Residence", "{MResidence{x", 1, 10 },
{ "Fortress", "{MFortress{x", 1, 10 },
{ "Customs House", "{MCstms Hous{x", 1, 10 },
{ "City Hall", "{MCity Hall{x", 1, 10 }
};
void puerto_viewp(CHAR_DATA *ch, struct player_data pdata, bool show_vps)
{
char buf[CMD_LEN];
char out_buf[MAX_STRING_LENGTH];
int i, j, max_plant = 0, ptypes = 0;
sprintf(out_buf, "{wPlayer name: {C%s{w\n\r\n\r", pdata.pname);
send_to_char(out_buf, ch);
send_to_char("Bldgs:", ch);
if (pdata.buildings[0] == -1)
{
send_to_char(" {D-none-{x\n\r", ch);
}
else
{
for (i = 0; i < 12; i++)
{
if (pdata.buildings[i] == -1)
{
send_to_char("\n\r", ch);
break;
}
sprintf(buf, "%2d.%-14s %s%s%s",
i + 1, buildings[pdata.buildings[i]].short_form,
buildings[pdata.buildings[i]].spaces >= 1 ? pdata.col_buildings[i] >= 1 ? "({y*{x)" : "( )" : " ",
buildings[pdata.buildings[i]].spaces >= 2 ? pdata.col_buildings[i] >= 2 ? "({y*{x)" : "( )" : " ",
buildings[pdata.buildings[i]].spaces >= 3 ? pdata.col_buildings[i] >= 3 ? "({y*{x)" : "( )" : " ");
send_to_char(buf, ch);
if (i % 3 == 2)
{
send_to_char("\n\r", ch);
if (i != 11)
send_to_char(" ", ch);
}
else
send_to_char(" ", ch);
// send_to_char(out_buf, ch);
}
}
send_to_char("\n\r{wPlnts:{x ", ch);
for (i = 0; i < 6; i++)
if (pdata.plants[i] > max_plant)
max_plant = pdata.plants[i];
for (i = 0; i < 6; i++)
{
max_plant = max_plant <= 5 ? 5 : max_plant <= 9 ? 9 : 12;
if (pdata.plants[i] <= 0)
continue;
if (((max_plant == 5) && ((ptypes % 3) == 2))
|| ((max_plant == 9) && ((ptypes % 2) == 1))
|| ((max_plant == 12) && (ptypes > 0)))
{
send_to_char("\n\r ", ch);
/*
if (i < 5)
send_to_char(" ", ch);
*/
}
switch (i)
{
case 0:
send_to_char("{YCorn{w ", ch);
break;
case 1:
send_to_char("{BIndigo{w ", ch);
break;
case 2:
send_to_char("{WSugar{w ", ch);
break;
case 3:
send_to_char("{RTobacc{w ", ch);
break;
case 4:
send_to_char("{yCoffee{w ", ch);
break;
case 5:
send_to_char("{wQuarry ", ch);
break;
}
for (j = 1; j <= max_plant; j++)
if (pdata.plants[i] >= j)
{
if (pdata.col_plants[i] >= j)
send_to_char("({y*{w)", ch);
else
send_to_char("( )", ch);
}
else
send_to_char(" " ,ch);
ptypes++;
}
if (ptypes == 0)
send_to_char("{D-none-{x", ch);
send_to_char("\n\r\n\r", ch);
sprintf(out_buf, "{yColonists partying in San Juan: %d. {YDoubloons: %d",
pdata.col_SanJuan, pdata.doubloons);
send_to_char(out_buf, ch);
if (show_vps)
{
sprintf(out_buf, ", Victory Points: %d\n\r\n\r", pdata.vps);
send_to_char(out_buf, ch);
}
else
send_to_char("\n\r\n\r", ch);
sprintf(out_buf, "{xGoods {D- {YCorn: %d, {BIndigo: %d, {WSugar: %d, {RTobacco: %d, {yCoffee: %d{x\n\r",
pdata.goods[0], pdata.goods[1], pdata.goods[2],
pdata.goods[3], pdata.goods[4]);
send_to_char(out_buf, ch);
}
void puerto_message(unsigned short gnum, const char *txt, CHAR_DATA *ch)
{
char buf[MAX_STRING_LENGTH];
sprintf(buf, "{rPR:{R%d{r>> {w%s{x", gnum, txt);
send_to_char(buf, ch);
return;
}
void puerto_interp(CHAR_DATA *ch, char *cmd)
{
char buf[CMD_LEN];
char *p = cmd; // + sizeof(pmsg_len);
char out_buf[MAX_STRING_LENGTH];
char *c;
char name[NAME_LEN];
unsigned short gnum;
// used in CMD_GAME_VIEW
char gov[NAME_LEN], cur[NAME_LEN];
struct game_data gdata;
int i;
bool first_found = FALSE;
#if defined(PRDEBUG)
bug("Processing %d.", *p);
#endif
switch (*p++)
{
case CMD_MSG:
{
char msg;
char *c;
if (!(c = parse_command(p, "%c", &msg)))
break;
switch (msg)
{
/*
case MSG_LOGIN_SUCCESS:
send_to_char("Puerto Rico connection successful!\n\r", ch);
break;
*/
case PR_MSG_GAME_CREATED:
{
parse_command(c, "%h", &gnum);
sprintf(out_buf, "New game (#{W%d{w) created.\n\r", gnum);
send_to_char(out_buf, ch);
}
break;
case PR_MSG_JOIN:
{
parse_command(c, "%h", &gnum);
sprintf(out_buf, "You have joined Puerto Rico game #{W%d{w!\n\r", gnum);
send_to_char(out_buf, ch);
}
break;
case PR_MSG_HAS_JOINED:
{
parse_command(c, "%h%s", &gnum, name);
sprintf(out_buf, "%s has joined Puerto Rico game #{W%d{w!\n\r", name, gnum);
send_to_char(out_buf, ch);
}
break;
case PR_MSG_GAME_START:
{
parse_command(c, "%h%s", &gnum, name);
sprintf(out_buf, "Puerto Rico game #{W%d{w has started! {W%s{w is governor, and goes first.\n\r", gnum, name);
send_to_char(out_buf, ch);
}
break;
case PR_MSG_ROLE_CHOSEN:
{
char role, gold;
parse_command(c, "%h%s%c%c", &gnum, name, &role, &gold);
sprintf(out_buf, "%s has chosen the role of {W%s{w (%d gold).\n\r", name, role_names[role], gold);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_PLANT_CHOSEN:
{
char ptype;
parse_command(c, "%h%s%c", &gnum, name, &ptype);
if (ptype == PLANT_QUARRY)
sprintf(out_buf, "%s takes a quarry.\n\r", name);
else
sprintf(out_buf, "%s takes a%s %s plantation.\n\r",
name, ptype == PLANT_INDIGO ? "n" : "", cgood_names[ptype]);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_NEXT_PHASE:
{
char action;
parse_command(c, "%h%s%c", &gnum, name, &action);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "It is now {Gyour{w turn to act ({W%s{w).\n\r", role_names[action]);
else
sprintf(out_buf, "It is now %s'%s turn to act ({W%s{w).\n\r", name, LOWER(name[strlen(name) - 1]) == 's' ? "" : "s", role_names[action]);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_NEXT_TURN:
{
char action;
char new_cols;
c = parse_command(c, "%h%s%c", &gnum, name, &action);
if (action == ROLE_MAYOR)
{
parse_command(c, "%c", &new_cols);
sprintf(out_buf, "The %s round is over, and the ship is repopulated with %d colonists.\n\r", role_names[action], new_cols);
puerto_message(gnum, out_buf, ch);
}
else
{
sprintf(out_buf, "The %s round is over%s.\n\r", role_names[action],
(action == ROLE_SETTLER) ? ", and new plantations are revealed" : "");
puerto_message(gnum, out_buf, ch);
}
if (!str_cmp(name, ch->name))
puerto_message(gnum, "It is now {Gyour{w turn to select a role.\n\r", ch);
else
{
sprintf(out_buf, "It is %s'%s turn to select a role.\n\r", name, LOWER(name[strlen(name) - 1]) == 's' ? "" : "s");
puerto_message(gnum, out_buf, ch);
}
}
break;
case PR_MSG_PASS:
{
parse_command(c, "%h%s", &gnum, name);
if (!str_cmp(name, ch->name))
puerto_message(gnum, "You pass.\n\r", ch);
else
{
sprintf(out_buf, "%s passes.\n\r", name);
puerto_message(gnum, out_buf, ch);
}
}
break;
case PR_MSG_NEXT_GOV:
{
char turn;
parse_command(c, "%h%s%c", &gnum, name, &turn);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "It is turn #%d! You are now the governor.\n\r", turn);
else
sprintf(out_buf, "It is turn #%d! %s is now the governor.\n\r", turn, name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_GAMEEND_COL:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "The colonist supply has been exhausted; the game will end on this turn.\n\r", ch);
}
break;
case PR_MSG_GAMEEND_VPS:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "The victory point supply has been exhausted; the game will end on this turn.\n\r", ch);
}
break;
case PR_MSG_GAMEEND_BUILD:
{
parse_command(c, "%h%s", &gnum, name);
if (!str_cmp(name, ch->name))
strcpy(out_buf, "You have filled your building spaces; the game will end on this turn.\n\r");
else
sprintf(out_buf, "%s has filled their building spaces; the game will end on this turn.\n\r", name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_GET_COLS:
{
char cols;
parse_command(c, "%h%s%c", &gnum, name, &cols);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You get %d colonist%s.\n\r", cols, cols == 1 ? "" : "s");
else
sprintf(out_buf, "%s gets %d colonist%s.\n\r", name, cols, cols == 1 ? "" : "s");
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_MOVE:
{
char move;
parse_command(c, "%h%c", &gnum, &move);
sprintf(out_buf, "You move a colonist from San Juan to %s %s%s.\n\r",
(move == (PLANT_INDIGO * -1)) ? "an" : (move <= 0) ? "a" : "your",
(move == (PLANT_QUARRY * -1)) ? "quarry" : (move <= 0) ? cgood_names[move * -1] : buildings[move - 1].name,
((move > (PLANT_QUARRY * -1)) && (move <= 0)) ? " plantation" : "");
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_REMOVE:
{
char move;
parse_command(c, "%h%c", &gnum, &move);
sprintf(out_buf, "You move a colonist from %s %s%s to San Juan.\n\r",
(move == (PLANT_INDIGO * -1)) ? "an" : (move <= 0) ? "a" : "your",
(move == (PLANT_QUARRY * -1)) ? "quarry" : (move <= 0) ? cgood_names[move * -1] : buildings[move - 1].name,
((move > (PLANT_QUARRY * -1)) && (move <= 0)) ? " plantation" : "");
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_BUILD:
{
char build_num, cost;
parse_command(c, "%h%s%c%c", &gnum, name, &build_num, &cost);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You build {W%s{w for %d doubloons.\n\r", buildings[build_num].name, cost);
else
sprintf(out_buf, "%s builds {W%s{w for %d doubloons.\n\r", name, buildings[build_num].name, cost);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_CRAFTS:
{
char g;
bool first = TRUE;
int i;
c = parse_command(c, "%h%s", &gnum, name);
if (!str_cmp(name, ch->name))
strcpy(out_buf, "You craft");
else
sprintf(out_buf, "%s crafts", name);
for (i = 0; i < 5; i++)
{
c = parse_command(c, "%c", &g);
if (g > 0)
{
sprintf(buf, "%s {%c%d %s{w", first ? "" : ",",
i == PLANT_CORN ? 'Y' :
i == PLANT_INDIGO ? 'B' :
i == PLANT_SUGAR ? 'W' :
i == PLANT_TOBACCO ? 'R' : 'y',
g, good_names[i]);
strcat(out_buf, buf);
first = FALSE;
}
}
if (first)
strcat(out_buf, " nothing");
strcat(out_buf, ".\n\r");
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_CRAFT_ADD:
{
char good_num;
parse_command(c, "%h%s%c", &gnum, name, &good_num);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You craft an additional %s.\n\r", cgood_names[good_num]);
else
sprintf(out_buf, "%s crafts an additional %s.\n\r", name, cgood_names[good_num]);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_TRADE:
{
char good_num, value;
parse_command(c, "%h%s%c%c", &gnum, name, &good_num, &value);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You trade %s for %d doubloons.\n\r",
cgood_names[good_num], value);
else
sprintf(out_buf, "%s trades %s for %d doubloons.\n\r", name,
cgood_names[good_num], value);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_TRADE_CLEAR:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "The trading house is cleared of goods.\n\r", ch);
}
break;
case PR_MSG_SHIP:
{
char good_num, quantity, points;
parse_command(c, "%h%s%c%c%c", &gnum, name, &quantity, &good_num, &points);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You ship {%c%d %s{w for %d points.\n\r",
good_num == PLANT_CORN ? 'Y' :
good_num == PLANT_INDIGO ? 'B' :
good_num == PLANT_SUGAR ? 'W' :
good_num == PLANT_TOBACCO ? 'R' : 'y',
quantity, good_names[good_num], points);
else
sprintf(out_buf, "%s ships {%c%d %s{w for %d points.\n\r", name,
good_num == PLANT_CORN ? 'Y' :
good_num == PLANT_INDIGO ? 'B' :
good_num == PLANT_SUGAR ? 'W' :
good_num == PLANT_TOBACCO ? 'R' : 'y',
quantity, good_names[good_num], points);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_DISCARD:
{
char good_num, quantity;
parse_command(c, "%h%s%c%c", &gnum, name, &quantity, &good_num);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You discard {%c%d %s{w.\n\r",
good_num == PLANT_CORN ? 'Y' :
good_num == PLANT_INDIGO ? 'B' :
good_num == PLANT_SUGAR ? 'W' :
good_num == PLANT_TOBACCO ? 'R' : 'y',
quantity, good_names[good_num]);
else
sprintf(out_buf, "%s discards {%c%d %s{w.\n\r", name,
good_num == PLANT_CORN ? 'Y' :
good_num == PLANT_INDIGO ? 'B' :
good_num == PLANT_SUGAR ? 'W' :
good_num == PLANT_TOBACCO ? 'R' : 'y',
quantity, good_names[good_num]);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_FACTORY:
{
char earn;
parse_command(c, "%h%s%c", &gnum, name, &earn);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "Your factory produces %d doubloons.\n\r", earn);
else
sprintf(out_buf, "%s'%s factory produces %d doubloons.\n\r", name, LOWER(name[strlen(name) - 1]) == 's' ? "" : "s", earn);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_PROSPECT:
{
parse_command(c, "%h%s", &gnum, name);
if (!str_cmp(name, ch->name))
strcpy(out_buf, "You prospect for 1 doubloon.\n\r");
else
sprintf(out_buf, "%s prospects for 1 doubloon.\n\r", name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_PHASE_DISCARD:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "Shipping is done, it is time to discard excess goods.\n\r", ch);
}
break;
case PR_MSG_GAME_OVER:
{
parse_command(c, "%h", &gnum);
sprintf(out_buf, "Puerto Rico game #{W%d{w is over!\n\r", gnum);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_POINTS:
{
unsigned char points;
parse_command(c, "%h%s%c", &gnum, name, &points);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You finish the game with {W%d{w points.\n\r", points);
else
sprintf(out_buf, "%s finishes the game with {W%d{w points.\n\r", name, points);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_GAME_WINNER:
{
unsigned char points;
parse_command(c, "%h%s%c", &gnum, name, &points);
if (!str_cmp(name, ch->name))
strcpy(out_buf, "{YYou have won the game!!\n\r");
else
sprintf(out_buf, "{Y%s has won Puerto Rico game #%d!\n\r", name, gnum);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_GAME_TIED:
{
unsigned char points;
parse_command(c, "%h%c", &gnum, &points);
sprintf(out_buf, "{YPuerto Rico game #%d has ended in a tie at %d points!\n\r", gnum, points);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_SPECTATE:
{
parse_command(c, "%h%s", &gnum, name);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You begin to spectate Puerto Rico game #{W%d{w.\n\r", gnum);
else
sprintf(out_buf, "%s begins to spectate this game.\n\r", name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_MSG_NOSPEC:
{
parse_command(c, "%h%s", &gnum, name);
if (!str_cmp(name, ch->name))
sprintf(out_buf, "You stop spectating Puerto Rico game #{W%d{w.\n\r", gnum);
else
sprintf(out_buf, "%s stops spectating this game.\n\r", name);
puerto_message(gnum, out_buf, ch);
}
break;
}
}
break;
case CMD_ERR:
{
char msg;
char *c;
if (!(c = parse_command(p, "%c", &msg)))
break;
switch (msg)
{
case PR_ERR_JOIN:
{
parse_command(c, "%h", &gnum);
sprintf(out_buf, "Error joining Puerto Rico game #%d.\n\r", gnum);
send_to_char(out_buf, ch);
}
break;
case PR_ERR_VIEW:
{
parse_command(c, "%h%s", &gnum, name);
sprintf(out_buf, "'%s' is a not a player in this game.\n\r", name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_ERR_GAME_NOT_FOUND:
{
parse_command(c, "%h", &gnum);
sprintf(out_buf, "Puerto Rico game #%d not found.\n\r", gnum);
send_to_char(out_buf, ch);
}
break;
case PR_ERR_NOT_YOUR_TURN:
{
parse_command(c, "%h", &gnum);
strcpy(out_buf, "It is not your turn in this game.\n\r");
puerto_message(gnum, out_buf, ch);
}
break;
// case PR_ERR_INVALID_ROLE:
case PR_ERR_ROLE_PICKED:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "That role has already been taken. Please choose again.\n\r", ch);
}
break;
case PR_ERR_NOT_PLAYER:
{
parse_command(c, "%h", &gnum);
strcpy(out_buf, "You are not a player in this game.\n\r");
puerto_message(gnum, out_buf, ch);
}
break;
case PR_ERR_WRONG_PHASE:
{
char phase;
parse_command(c, "%h%c", &gnum, &phase);
if (phase == -1)
puerto_message(gnum, "It is not time to pick a role.\n\r", ch);
else
{
sprintf(out_buf, "It is not currently the %s phase.\n\r", role_names[phase]);
puerto_message(gnum, out_buf, ch);
}
return;
}
break;
case PR_ERR_PLANT_UNAVAIL:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "That type of plantation is not available.\n\r", ch);
}
break;
case PR_ERR_PLANTS_FULL:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "Your plantation lot is full.\n\r", ch);
}
break;
case PR_ERR_CANT_QUARRY:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "You are unable to select a quarry at this time.\n\r", ch);
}
break;
case PR_ERR_NO_QUARRY:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "There are no quarries left available! Please select again.\n\r", ch);
}
break;
case PR_ERR_INVALID_MOVE:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "Invalid colonist move attempted.\n\r", ch);
}
break;
case PR_ERR_FREE_SPACES:
{
parse_command(c, "%h", &gnum);
puerto_message(gnum, "You cannot end the mayor phase with free spaces remaining and colonists in San Juan.\n\r", ch);
}
break;
case PR_ERR_BUILD_GONE:
{
char build_num;
parse_command(c, "%h%c", &gnum, &build_num);
sprintf(out_buf, "There are no %s remaining.\n\r", buildings[build_num].name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_ERR_BUILD_NOSPACE:
{
char build_num;
parse_command(c, "%h%c", &gnum, &build_num);
sprintf(out_buf, "You don't have enough space to build %s.\n\r", buildings[build_num].name);
puerto_message(gnum, out_buf, ch);
}
break;
case PR_ERR_BUILD_COST: