-
Notifications
You must be signed in to change notification settings - Fork 37
/
parseorders.cpp
3109 lines (2844 loc) · 73.3 KB
/
parseorders.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
// START A3HEADER
//
// This source file is part of the Atlantis PBM game program.
// Copyright (C) 1995-1999 Geoff Dunbar
//
// 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, in the file license.txt. If not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// See the Atlantis Project web page for details:
// http://www.prankster.com/project
//
// END A3HEADER
#include <stdlib.h>
#include <memory>
#include "game.h"
#include "gameio.h"
#include "orders.h"
#include "skills.h"
#include "gamedata.h"
using namespace std;
void OrdersCheck::error(const string& err)
{
pCheckFile << "\n\n*** Error: " << err << " ***\n";
numerrors++;
}
int Game::ParseDir(AString *token)
{
for (int i=0; i<NDIRS; i++) {
if (*token == DirectionStrs[i]) return i;
if (*token == DirectionAbrs[i]) return i;
}
if (*token == "in") return MOVE_IN;
if (*token == "out") return MOVE_OUT;
if (*token == "pause" || *token == "p") return MOVE_PAUSE;
int num = token->value();
if (num) return MOVE_ENTER + num;
return -1;
}
int ParseTF(AString *token)
{
if (*token == "true") return 1;
if (*token == "false") return 0;
if (*token == "t") return 1;
if (*token == "f") return 0;
if (*token == "on") return 1;
if (*token == "off") return 0;
if (*token == "yes") return 1;
if (*token == "no") return 0;
if (*token == "1") return 1;
if (*token == "0") return 0;
return -1;
}
UnitId *Game::ParseUnit(AString *s)
{
AString *token = s->gettoken();
if (!token) return 0;
if (*token == "0") {
delete token;
UnitId *id = new UnitId;
id->unitnum = -1;
id->alias = 0;
id->faction = 0;
return id;
}
if (*token == "faction") {
delete token;
/* Get faction number */
token = s->gettoken();
if (!token) return 0;
int fn = token->value();
delete token;
if (!fn) return 0;
/* Next token should be "new" */
token = s->gettoken();
if (!token) return 0;
if (!(*token == "new")) {
delete token;
return 0;
}
delete token;
/* Get alias number */
token = s->gettoken();
if (!token) return 0;
int un = token->value();
delete token;
if (!un) return 0;
/* Return UnitId */
UnitId *id = new UnitId;
id->unitnum = 0;
id->alias = un;
id->faction = fn;
return id;
}
if (*token == "new") {
delete token;
token = s->gettoken();
if (!token) return 0;
int un = token->value();
delete token;
if (!un) return 0;
UnitId *id = new UnitId;
id->unitnum = 0;
id->alias = un;
id->faction = 0;
return id;
} else {
int un = token->value();
delete token;
if (!un) return 0;
UnitId *id = new UnitId;
id->unitnum = un;
id->alias = 0;
id->faction = 0;
return id;
}
}
int ParseFactionType(AString *o, std::unordered_map<std::string, int> &type)
{
for (auto &ft : *FactionTypes) {
type[ft] = 0;
}
AString *token = o->gettoken();
if (!token) return -1;
if (*token == "generic") {
delete token;
for (auto &ft : *FactionTypes) {
type[ft] = 1;
}
return 0;
}
while(token) {
bool foundone = false;
for (auto &ft : *FactionTypes) {
if (*token == ft.c_str()) {
delete token;
token = o->gettoken();
if (!token) return -1;
type[ft] = token->value();
delete token;
foundone = true;
break;
}
}
if (!foundone) {
delete token;
return -1;
}
token = o->gettoken();
}
int tot = 0;
for (auto &kv : type) {
tot += kv.second;
}
if (tot > Globals->FACTION_POINTS) return -1;
return 0;
}
void Game::parse_error(OrdersCheck *order_check, Unit *unit, Faction *faction, const string& error) {
if (order_check) order_check->error(error);
else if (unit) unit->error(error);
else if (faction) faction->error(error);
}
void Game::ParseOrders(int faction, istream& f, OrdersCheck *pCheck)
{
Faction *fac = nullptr;
Faction *passFac = nullptr;
Unit *unit = 0;
int indent = 0, code, i;
AString order, prefix;
f >> ws >> order;
while (!f.eof()) {
AString saveorder = order;
int getatsign = order.getat();
AString *token = order.gettoken();
if (token) {
code = Parse1Order(token);
switch (code) {
case -1:
parse_error(pCheck, unit, fac, string(token->const_str()) + " is not a valid order.");
break;
case O_ATLANTIS:
if (fac)
parse_error(pCheck, 0, fac, "No #END statement given.");
delete token;
token = order.gettoken();
if (!token) {
parse_error(pCheck, 0, 0, "No faction number given on #atlantis line.");
fac = 0;
break;
}
if (pCheck) {
fac = &(pCheck->dummyFaction);
pCheck->numshows = 0;
// Even though we don't use the real faction for other things, we do want it for the password check.
passFac = GetFaction(&factions, token->value());
} else {
fac = GetFaction(&factions, token->value());
}
if (!fac) break;
delete token;
token = order.gettoken();
if (pCheck) {
if (!token) {
parse_error(pCheck, 0, fac, "Warning: No password on #atlantis line.");
parse_error(pCheck, 0, fac, "If this is your first turn, ignore this error.");
} else {
// If we found their real faction above (we should have but let's not assume), then we
// can check if they gave us the correct password.
if (passFac) {
bool has_password = !(*(passFac->password) == "none");
bool wrong_password = !(*(passFac->password) == *token);
if (has_password && wrong_password) {
parse_error(pCheck, 0, fac, "Incorrect password on #atlantis line.");
fac = 0;
break;
}
}
}
} else {
if (!(*(fac->password) == "none")) {
if (!token || !(*(fac->password) == *token)) {
parse_error(pCheck, 0, fac, "Incorrect password on #atlantis line.");
fac = 0;
break;
}
}
if (fac->num == monfaction || fac->num == guardfaction) {
fac = 0;
break;
}
if (!Globals->LASTORDERS_MAINTAINED_BY_SCRIPTS)
fac->lastorders = TurnNumber();
}
unit = 0;
break;
case O_END:
indent = 0;
while (unit) {
Unit *former = unit->former;
if (unit->inTurnBlock)
parse_error(pCheck, unit, fac, "TURN: without ENDTURN");
if (unit->former)
parse_error(pCheck, unit, fac, "FORM: without END.");
if (unit && pCheck) unit->ClearOrders();
if (pCheck && former) delete unit;
unit = former;
}
unit = 0;
fac = 0;
break;
case O_UNIT:
indent = 0;
if (fac) {
while (unit) {
Unit *former = unit->former;
if (unit->inTurnBlock)
parse_error(pCheck, unit, fac, "TURN: without ENDTURN");
if (unit->former)
parse_error(pCheck, unit, fac, "FORM: without END.");
if (unit && pCheck) unit->ClearOrders();
if (pCheck && former) delete unit;
unit = former;
}
unit = 0;
delete token;
token = order.gettoken();
if (!token) {
parse_error(pCheck, 0, fac, "UNIT without unit number.");
unit = 0;
break;
}
if (pCheck) {
if (!token->value()) {
parse_error(pCheck, 0, fac, "Invalid unit number.");
} else {
unit = &(pCheck->dummyUnit);
unit->monthorders = 0;
}
} else {
unit = GetUnit(token->value());
if (!unit || unit->faction != fac) {
// as we get rid of more uses of astring, these will become unnecessary
string tmp(token->const_str());
fac->error(tmp + " is not your unit.");
unit = 0;
} else {
unit->ClearOrders();
}
}
}
break;
case O_FORM:
if (fac) {
if (unit) {
if (unit->former && !unit->inTurnBlock) {
parse_error(pCheck, unit, fac, "FORM: cannot nest.");
}
else {
unit = ProcessFormOrder(unit, &order, pCheck, getatsign);
if (!pCheck && unit && unit->former && unit->former->format)
unit->former->oldorders.push_back(saveorder.const_str());
if (!pCheck) {
if (unit) unit->ClearOrders();
}
}
} else {
parse_error(pCheck, 0, fac,
"Order given without a unit selected.");
}
}
break;
case O_ENDFORM:
if (fac) {
if (unit && unit->former) {
Unit *former = unit->former;
if (unit->inTurnBlock)
parse_error(pCheck, unit, fac, "TURN: without ENDTURN");
if (!pCheck && unit->former && unit->former->format)
unit->former->oldorders.push_back(saveorder.const_str());
if (pCheck && former) delete unit;
unit = former;
} else {
parse_error(pCheck, unit, fac, "END: without FORM.");
}
}
break;
case O_TURN:
if (unit && unit->inTurnBlock) {
parse_error(pCheck, unit, fac, "TURN: cannot nest");
} else if (!unit)
parse_error(pCheck, 0, fac, "Order given without a unit selected.");
else {
// faction is 0 if checking syntax only, not running turn.
if (faction != 0) {
AString *retval;
if (!pCheck && unit->former && unit->former->format)
unit->former->oldorders.push_back(saveorder.const_str());
retval = ProcessTurnOrder(unit, f, pCheck, getatsign);
if (retval) {
order = *retval;
continue;
}
} else {
unit->inTurnBlock = 1;
unit->presentMonthOrders = unit->monthorders;
unit->monthorders = 0;
unit->presentTaxing = unit->taxing;
unit->taxing = 0;
}
}
break;
case O_ENDTURN:
if (unit && unit->inTurnBlock) {
unit->monthorders = unit->presentMonthOrders;
unit->presentMonthOrders = 0;
unit->taxing = unit->presentTaxing;
unit->presentTaxing = 0;
unit->inTurnBlock = 0;
if (!pCheck && unit->former && unit->former->format)
unit->former->oldorders.push_back(saveorder.const_str());
} else
parse_error(pCheck, unit, fac, "ENDTURN: without TURN.");
break;
default:
if (fac) {
if (unit) {
if (!pCheck && getatsign)
unit->oldorders.push_back(saveorder.const_str());
if (!pCheck && unit->former && unit->former->format)
unit->former->oldorders.push_back(saveorder.const_str());
ProcessOrder(code, unit, &order, pCheck);
} else {
parse_error(pCheck, 0, fac,
"Order given without a unit selected.");
}
}
}
SAFE_DELETE(token);
} else {
code = NORDERS;
if (!pCheck) {
if (getatsign && fac && unit)
unit->oldorders.push_back(saveorder.const_str());
}
}
if (pCheck) {
if (code == O_ENDTURN || code == O_ENDFORM)
indent--;
for (i = 0, prefix = ""; i < indent; i++)
prefix += " ";
pCheck->pCheckFile << prefix << saveorder << "\n";
if (code == O_TURN || code == O_FORM)
indent++;
}
f >> ws >> order;
}
while (unit) {
Unit *former = unit->former;
if (unit->inTurnBlock)
parse_error(pCheck, 0, fac, "TURN: without ENDTURN");
if (unit->former)
parse_error(pCheck, 0, fac, "FORM: without END.");
if (unit && pCheck) unit->ClearOrders();
if (pCheck && former) delete unit;
unit = former;
}
if (unit && pCheck) {
unit->ClearOrders();
unit = 0;
}
if (pCheck) {
pCheck->pCheckFile << "\n";
if (!pCheck->numerrors) {
pCheck->pCheckFile << "No errors found.\n";
} else {
pCheck->pCheckFile << pCheck->numerrors << " error" << (pCheck->numerrors == 1 ? "" : "s") << " found!\n";
}
}
}
void Game::ProcessOrder(int orderNum, Unit *unit, AString *o,
OrdersCheck *pCheck)
{
switch(orderNum) {
case O_ADDRESS:
ProcessAddressOrder(unit, o, pCheck);
break;
case O_ADVANCE:
ProcessAdvanceOrder(unit, o, pCheck);
break;
case O_ASSASSINATE:
ProcessAssassinateOrder(unit, o, pCheck);
break;
case O_ATTACK:
ProcessAttackOrder(unit, o, pCheck);
break;
case O_AUTOTAX:
ProcessAutoTaxOrder(unit, o, pCheck);
break;
case O_AVOID:
ProcessAvoidOrder(unit, o, pCheck);
break;
case O_IDLE:
ProcessIdleOrder(unit, o, pCheck);
break;
case O_BEHIND:
ProcessBehindOrder(unit, o, pCheck);
break;
case O_BUILD:
ProcessBuildOrder(unit, o, pCheck);
break;
case O_BUY:
ProcessBuyOrder(unit, o, pCheck);
break;
case O_CAST:
ProcessCastOrder(unit, o, pCheck);
break;
case O_CLAIM:
ProcessClaimOrder(unit, o, pCheck);
break;
case O_COMBAT:
ProcessCombatOrder(unit, o, pCheck);
break;
case O_CONSUME:
ProcessConsumeOrder(unit, o, pCheck);
break;
case O_DECLARE:
ProcessDeclareOrder(unit->faction, o, pCheck);
break;
case O_DESCRIBE:
ProcessDescribeOrder(unit, o, pCheck);
break;
case O_DESTROY:
ProcessDestroyOrder(unit, pCheck);
break;
case O_ENTER:
ProcessEnterOrder(unit, o, pCheck);
break;
case O_ENTERTAIN:
ProcessEntertainOrder(unit, pCheck);
break;
case O_EVICT:
ProcessEvictOrder(unit, o, pCheck);
break;
case O_EXCHANGE:
ProcessExchangeOrder(unit, o, pCheck);
break;
case O_FACTION:
ProcessFactionOrder(unit, o, pCheck);
break;
case O_FIND:
ProcessFindOrder(unit, o, pCheck);
break;
case O_FORGET:
ProcessForgetOrder(unit, o, pCheck);
break;
case O_WITHDRAW:
ProcessWithdrawOrder(unit, o, pCheck);
break;
case O_GIVE:
ProcessGiveOrder(orderNum, unit, o, pCheck);
break;
case O_GUARD:
ProcessGuardOrder(unit, o, pCheck);
break;
case O_HOLD:
ProcessHoldOrder(unit, o, pCheck);
break;
case O_JOIN:
ProcessJoinOrder(unit, o, pCheck);
break;
case O_LEAVE:
ProcessLeaveOrder(unit, pCheck);
break;
case O_MOVE:
ProcessMoveOrder(unit, o, pCheck);
break;
case O_NAME:
ProcessNameOrder(unit, o, pCheck);
break;
case O_NOAID:
ProcessNoaidOrder(unit, o, pCheck);
break;
case O_NOCROSS:
ProcessNocrossOrder(unit, o, pCheck);
break;
case O_NOSPOILS:
ProcessNospoilsOrder(unit, o, pCheck);
break;
case O_OPTION:
ProcessOptionOrder(unit, o, pCheck);
break;
case O_PASSWORD:
ProcessPasswordOrder(unit, o, pCheck);
break;
case O_PILLAGE:
ProcessPillageOrder(unit, pCheck);
break;
case O_PREPARE:
ProcessPrepareOrder(unit, o, pCheck);
break;
case O_WEAPON:
ProcessWeaponOrder(unit, o, pCheck);
break;
case O_ARMOR:
ProcessArmorOrder(unit, o, pCheck);
break;
case O_PRODUCE:
ProcessProduceOrder(unit, o, pCheck);
break;
case O_PROMOTE:
ProcessPromoteOrder(unit, o, pCheck);
break;
case O_QUIT:
ProcessQuitOrder(unit, o, pCheck);
break;
case O_RESTART:
ProcessRestartOrder(unit, o, pCheck);
break;
case O_REVEAL:
ProcessRevealOrder(unit, o, pCheck);
break;
case O_SAIL:
ProcessSailOrder(unit, o, pCheck);
break;
case O_SELL:
ProcessSellOrder(unit, o, pCheck);
break;
case O_SHARE:
ProcessShareOrder(unit, o, pCheck);
break;
case O_SHOW:
ProcessReshowOrder(unit, o, pCheck);
break;
case O_SPOILS:
ProcessSpoilsOrder(unit, o, pCheck);
break;
case O_STEAL:
ProcessStealOrder(unit, o, pCheck);
break;
case O_STUDY:
ProcessStudyOrder(unit, o, pCheck);
break;
case O_TAKE:
ProcessGiveOrder(orderNum, unit, o, pCheck);
break;
case O_TAX:
ProcessTaxOrder(unit, pCheck);
break;
case O_TEACH:
ProcessTeachOrder(unit, o, pCheck);
break;
case O_WORK:
ProcessWorkOrder(unit, 0, pCheck);
break;
case O_TRANSPORT:
case O_DISTRIBUTE:
ProcessTransportOrder(unit, o, pCheck);
break;
// NO7 victory condition orders
case O_ANNIHILATE:
ProcessAnnihilateOrder(unit, o, pCheck);
break;
case O_SACRIFICE:
ProcessSacrificeOrder(unit, o, pCheck);
break;
}
}
void Game::ProcessPasswordOrder(Unit *u, AString *o, OrdersCheck *pCheck)
{
if (pCheck) return;
AString *token = o->gettoken();
if (u->faction->password) delete u->faction->password;
if (token) {
u->faction->password = token;
string tmp = "Password is now: ";
tmp += token->const_str();
u->faction->event(tmp, "password");
} else {
u->faction->password = new AString("none");
u->faction->event("Password cleared.", "password");
}
}
void Game::ProcessOptionOrder(Unit *u, AString *o, OrdersCheck *pCheck)
{
AString *token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "OPTION: What option?");
return;
}
if (*token == "times") {
delete token;
if (!pCheck) {
u->faction->event("Times will be sent to your faction.", "option");
u->faction->times = 1;
}
return;
}
if (*token == "notimes") {
delete token;
if (!pCheck) {
u->faction->event("Times will not be sent to your faction.", "option");
u->faction->times = 0;
}
return;
}
if (*token == "showattitudes") {
delete token;
if (!pCheck) {
u->faction->event("Units will now have a leading sign to show your attitude to them.", "option");
u->faction->showunitattitudes = 1;
}
return;
}
if (*token == "dontshowattitudes") {
delete token;
if (!pCheck) {
u->faction->event("Units will now have a leading minus sign regardless of your attitude to them.", "option");
u->faction->showunitattitudes = 0;
}
return;
}
if (*token == "template") {
delete token;
token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "OPTION: No template type specified.");
return;
}
int newformat = -1;
if (*token == "off") {
newformat = TEMPLATE_OFF;
}
if (*token == "short") {
newformat = TEMPLATE_SHORT;
}
if (*token == "long") {
newformat = TEMPLATE_LONG;
}
// DK
if (*token == "map") {
newformat = TEMPLATE_MAP;
}
delete token;
if (newformat == -1) {
parse_error(pCheck, u, 0, "OPTION: Invalid template type.");
return;
}
if (!pCheck) {
u->faction->temformat = newformat;
}
return;
}
delete token;
parse_error(pCheck, u, 0, "OPTION: Invalid option.");
}
void Game::ProcessReshowOrder(Unit *u, AString *o, OrdersCheck *pCheck)
{
int sk, lvl, item, obj;
AString *token;
token = o->gettoken();
if (!token) {
// LLS
parse_error(pCheck, u, 0, "SHOW: Show what?");
return;
}
int count = (pCheck ? pCheck->numshows++ : u->faction->numshows++);
if (count > 100) {
if (count == 102) {
parse_error(pCheck, u, 0, "Too many SHOW orders.");
}
return;
}
if (*token == "skill") {
delete token;
token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "SHOW: Show what skill?");
return;
}
sk = ParseSkill(token);
delete token;
token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "SHOW: No skill level given.");
return;
}
lvl = token->value();
delete token;
if (!pCheck) {
if (sk == -1 ||
SkillDefs[sk].flags & SkillType::DISABLED ||
(SkillDefs[sk].flags & SkillType::APPRENTICE &&
!Globals->APPRENTICES_EXIST) ||
lvl > u->faction->skills.GetDays(sk)) {
u->error("SHOW: Faction doesn't have that skill.");
return;
}
u->faction->shows.push_back({ .skill = sk, .level = lvl });
}
return;
}
if (*token == "object") {
delete token;
token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "SHOW: Show which object?");
return;
}
obj = ParseObject(token, 1);
delete token;
if (!pCheck && obj >= -1) {
if (obj == -1 ||
obj == O_DUMMY ||
(ObjectDefs[obj].flags & ObjectType::DISABLED)) {
u->error("SHOW: No such object.");
return;
}
u->faction->objectshows.push_back({.obj = obj});
}
if (obj >= -1)
return;
token = new AString("item");
o = new AString(ItemDefs[-(obj + 1)].abr);
}
if (*token == "item") {
delete token;
token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "SHOW: Show which item?");
return;
}
item = ParseEnabledItem(token);
delete token;
if (!pCheck) {
if (item == -1 || (ItemDefs[item].flags & ItemType::DISABLED)) {
u->error("SHOW: You don't know anything about that item.");
return;
}
if (ItemDefs[item].pSkill) {
token = new AString(ItemDefs[item].pSkill);
sk = LookupSkill(token);
delete token;
if (ItemDefs[item].pLevel <= u->faction->skills.GetDays(sk)) {
u->faction->DiscoverItem(item, 1, 1);
return;
}
}
if (ItemDefs[item].mSkill) {
token = new AString(ItemDefs[item].mSkill);
sk = LookupSkill(token);
delete token;
if (ItemDefs[item].mLevel <= u->faction->skills.GetDays(sk)) {
u->faction->DiscoverItem(item, 1, 1);
return;
}
}
if (u->faction->items.GetNum(item)) {
u->faction->DiscoverItem(item, 1, 0);
return;
}
if (ItemDefs[item].type & (IT_MAN | IT_NORMAL | IT_TRADE | IT_MONSTER)) {
u->faction->DiscoverItem(item, 1, 0);
return;
}
u->error("SHOW: You don't know anything about that item.");
}
return;
}
parse_error(pCheck, u, 0, "SHOW: Show what?");
}
void Game::ProcessForgetOrder(Unit *u, AString *o, OrdersCheck *pCheck)
{
AString *token = o->gettoken();
if (!token) {
parse_error(pCheck, u, 0, "FORGET: No skill given.");
return;
}
int sk = ParseSkill(token);
delete token;
if (sk==-1) {
parse_error(pCheck, u, 0, "FORGET: Invalid skill.");
return;
}
if (!pCheck) {
std::shared_ptr<ForgetOrder> ord = std::make_shared<ForgetOrder>();
ord->skill = sk;
u->forgetorders.push_back(ord);
}
}
void Game::ProcessEntertainOrder(Unit *unit, OrdersCheck *pCheck)
{
if (unit->monthorders ||
(Globals->TAX_PILLAGE_MONTH_LONG &&
((unit->taxing == TAX_TAX) ||
(unit->taxing == TAX_PILLAGE)))) {
string err = string("ENTERTAIN: Overwriting previous ") +
(unit->inTurnBlock ? "DELAYED " : "") + "month-long order.";
parse_error(pCheck, unit, 0, err);
}
std::shared_ptr<ProduceOrder> o = std::make_shared<ProduceOrder>();
o->item = I_SILVER;
o->skill = S_ENTERTAINMENT;
o->target = 0;
unit->monthorders = o;
}
void Game::ProcessCombatOrder(Unit *u, AString *o, OrdersCheck *pCheck)
{
AString *token = o->gettoken();
if (!token) {
if (!pCheck) {
u->combat = -1;
u->event("Combat spell set to none.", "combat_preparation");
}
return;
}
int sk = ParseSkill(token);
delete token;
if (!pCheck) {
if (sk==-1) {
parse_error(pCheck, u, 0, "COMBAT: Invalid skill.");
return;
}
if (!(SkillDefs[sk].flags & SkillType::MAGIC)) {
parse_error(pCheck, u, 0, "COMBAT: That is not a magic skill.");
return;
}
if (!(SkillDefs[sk].flags & SkillType::COMBAT)) {
parse_error(pCheck, u, 0,
"COMBAT: That skill cannot be used in combat.");
return;
}
if (u->type != U_MAGE) {
u->error("COMBAT: That unit is not a mage.");
return;
}
if (!u->GetSkill(sk)) {
u->error("COMBAT: Unit does not possess that skill.");
return;
}
u->combat = sk;
string temp = "Combat spell set to " + SkillDefs[sk].name;
if (Globals->USE_PREPARE_COMMAND) {
u->readyItem = -1;
temp += " and prepared item set to none";
}
temp += ".";
u->event(temp, "combat_preparation");
}
}
// Lacandon's prepare command
void Game::ProcessPrepareOrder(Unit *u, AString *o, OrdersCheck *pCheck)
{
if (!(Globals->USE_PREPARE_COMMAND)) {
parse_error(pCheck, u, 0, "PREPARE is not a valid order.");