forked from quixadhal/conquer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands.c
1465 lines (1353 loc) · 34.3 KB
/
commands.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
/*conquer : Copyright (c) 1988 by Ed Barlow.
* I spent a long time writing this code & I hope that you respect this.
* I give permission to alter the code, but not to copy or redistribute
* it without my explicit permission. If you alter the code,
* please document changes and send me a copy, so all can have it.
* This code, to the best of my knowledge works well, but it is my first
* 'C' program and should be treated as such. I disclaim any
* responsibility for the codes actions (use at your own risk). I guess
* I am saying "Happy gaming", and am trying not to get sued in the process.
* Ed
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <curses.h>
#ifdef CONQUER
#include <sys/types.h>
#include <sys/stat.h>
#endif /*CONQUER*/
#include "header.h"
#include "data.h"
extern long conq_mail_size;
extern FILE *fexe; /*execute file pointer*/
extern short country;
extern short selector;
extern short pager;
extern short xcurs,ycurs,xoffset,yoffset;
extern short redraw;
int roads_this_turn = 0;
/* routine to determine if the given designation is ok; TRUE for ok */
int
desg_ok(prtflag, desg, sptr)
int prtflag;
char desg;
struct s_sector *sptr;
{
/* check vegetation */
if((desg!=DNODESIG)&&(desg!=DROAD)&&(desg!=DFORT)
&&(desg!=DSTOCKADE)&&(tofood(sptr,country)<DESFOOD)) {
if(prtflag) errormsg("vegetation too sparse");
return(FALSE);
}
/* don't allow the same designation */
if(desg==sptr->designation) {
if(prtflag) errormsg("Hey, get your act together! There is already one there.");
return(FALSE);
}
/* check for city/capitol being made into something else */
if((desg!=DRUIN)
&&((desg!=DCAPITOL && sptr->designation==DCITY)
||sptr->designation==DCAPITOL)) {
if(prtflag) {
char buf[LINELTH+1];
sprintf(buf,"Must first burn down city/capitol (designate as '%c')",DRUIN);
errormsg(buf);
}
return(FALSE);
}
/* check for proper population */
if((sptr->people<500)
&&(desg==DCAPITOL || desg==DCITY || desg==DTOWN)) {
if(prtflag) errormsg("Need 500 people to build a city or town");
return(FALSE);
}
/* only god may create pirate */
if(desg==DBASECAMP) {
if(prtflag) errormsg("A Pirate Cove?? Are you serious?!");
return(FALSE);
}
/* should not appear in display list */
if (prtflag==FALSE &&
((desg==DSPECIAL && sptr->tradegood!=TG_stones) || desg==DNODESIG))
return(FALSE);
if (desg==DRUIN) {
if(sptr->designation!=DCITY&&sptr->designation!=DCAPITOL) {
if(prtflag) errormsg("Ruins may only come from cities or capitols");
return(FALSE);
}
}
if (desg==DCAPITOL || desg==DCITY) {
if((desg==DCAPITOL && sptr->designation!=DCITY)
&& sptr->designation!=DTOWN && sptr->designation!=DRUIN) {
if(prtflag) errormsg("You can't build a city from that!");
return(FALSE);
}
}
if (desg==DUNIVERSITY || desg==DLUMBERYD) {
if((sptr->tradegood != TG_none)
&&(*(tg_stype + sptr->tradegood) != desg)
&&(*(tg_stype + sptr->tradegood) != 'x')) {
if(prtflag) errormsg("You can't have one of those here!");
return(FALSE);
}
}
if(desg==DMINE || desg==DGOLDMINE) {
if( !tg_ok( country, sptr )) {
if(prtflag) errormsg("Your people refuse to be unemployed");
return(FALSE);
}
if((desg==DMINE && sptr->metal==0 )
||( desg==DGOLDMINE && sptr->jewels==0)) {
if(prtflag) errormsg("Your people refuse to be unemployed");
return(FALSE);
}
}
if((desg==DSPECIAL)&&(magic(country,SUMMON)!=TRUE)) {
if(prtflag) errormsg("You are gonna need SUMMON power to use those stones!");
return(FALSE);
}
return(TRUE);
}
/*change current hex designation*/
void
redesignate()
{
char newdes;
char tgtype[NAMELTH+1];
struct s_sector *sptr= &sct[XREAL][YREAL];
short x,y;
long metal=0;
int isgod=FALSE;
if(country==0){
isgod=TRUE;
country=sptr->owner;
curntn= &ntn[country];
clear_bottom(0);
mvaddstr(LINES-4,0,"SUPER USER: CHANGE (v)eg, (e)lev, (d)esig, (o)wner, (p)op, (t)radegood");
refresh();
switch(getch()){
case 'd':
/* fall into normal redesignation command */
break;
case 'e':
/*simple contour map definitions*/
mvprintw(LINES-3,7,"ELEVATIONS: change to %c, %c, %c, %c or %c?",WATER,PEAK,MOUNTAIN,HILL,CLEAR);
refresh();
newdes=getch();
if(newdes!=WATER&&newdes!=PEAK&&newdes!=MOUNTAIN
&&newdes!=HILL&&newdes!=CLEAR) {
reset_god();
return;
}
sptr->altitude=newdes;
if((newdes==PEAK)||(newdes==WATER)) {
sptr->owner=0;
sptr->people=0;
sptr->fortress=0;
}
/*will fall through as must change vegetation*/
case 'v':
/*vegetation types*/
mvprintw(LINES-3,7,"VEGETATIONS: change to %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c or %c?",
VOLCANO,DESERT,TUNDRA,BARREN,LT_VEG,
GOOD,WOOD,FOREST,JUNGLE,SWAMP,ICE,NONE);
refresh();
newdes=getch();
if(newdes!=VOLCANO
&&newdes!=DESERT&&newdes!=TUNDRA
&&newdes!=BARREN&&newdes!=LT_VEG
&&newdes!=NONE&&newdes!=GOOD
&&newdes!=WOOD&&newdes!=FOREST&&newdes!=JUNGLE
&&newdes!=SWAMP&&newdes!=ICE) {
reset_god();
return;
}
sptr->vegetation=newdes;
if( tofood(sptr,0) < DESFOOD )
sptr->designation=newdes;
else sptr->designation=DNODESIG;
reset_god();
return;
case 'o':
mvaddstr(LINES-3,7,"What nation owner:");
refresh();
x = get_country();
if (x>0 && x<NTOTAL) sptr->owner=x;
reset_god();
return;
case 'p':
if (sptr->altitude == WATER) {
errormsg("Trying to build a colony of mermen?");
reset_god();
return;
}
mvaddstr(LINES-3,7,"new population for sector: ");
refresh();
metal = get_number();
if (metal <= (-1)) return;
sptr->people = metal;
reset_god();
return;
case 't':
x=TRUE;
while(x==TRUE) {
mvaddstr(LINES-2,7,"new sector tradegood type:");
clrtoeol();
refresh();
get_nname(tgtype);
if(strlen(tgtype)==0) {
reset_god();
return;
}
for(y=0;x==TRUE && y<=TG_none;y++)
if(strcmp(tg_name[y],tgtype)==0) x=FALSE;
}
y--;
if((y!=TG_none)&&(y>END_NORMAL)) {
mvaddstr(LINES-1,7,"new sector value: ");
refresh();
x = get_number();
if(x<100 && x>0) {
if(y>END_MINE) {
sptr->jewels = (char)x;
sptr->metal = 0;
} else {
sptr->metal = (char)x;
sptr->jewels = 0;
}
} else {
sptr->jewels = 0;
sptr->metal = 0;
}
} else {
sptr->jewels=0;
sptr->metal=0;
}
sptr->tradegood= (char)y;
reset_god();
return;
default:
reset_god();
return;
}
}
clear_bottom(0);
if((SOWN!=country)&&(isgod==FALSE)) {
errormsg("Hey! You don't own that sector!");
return;
}
mvaddstr(LINES-4,0,"Possible sector designations: ");
x = 30;
y = LINES-4;
for(newdes=0; *(des+newdes) != '0'; newdes++ ) {
if((isgod==TRUE)||desg_ok(FALSE,*(des+newdes),sptr)) {
mvprintw(y,x,"(%c)",*(des+newdes));
x+=4;
if(x>COLS-15) {
x=5;
y++;
}
}
}
if((sptr->tradegood != TG_none)
&&( *(tg_stype+sptr->tradegood) != 'x')
&&( isgod==TRUE || desg_ok(FALSE,*(tg_stype+sptr->tradegood),sptr)) )
mvprintw(y,x,"(%c special=>%c)",DSPECIAL,*(tg_stype+sptr->tradegood));
mvaddstr(++y,0,"<Any other key to return> What new designation:");
refresh();
/*read answer*/
if((newdes=getch())==DSPECIAL) {
if((sptr->tradegood == TG_none)
||( *(tg_stype+sptr->tradegood) == 'x')||(isgod==FALSE
&& !desg_ok(FALSE,*(tg_stype+sptr->tradegood),sptr)) ) {
errormsg("no special designation possible" );
if(isgod==TRUE) reset_god();
return;
} else
newdes = *(tg_stype + sptr->tradegood);
}
for(x=0; *(des+x) != '0'; x++ )
if(newdes == *(des+x)) break;
if(*(des+x) == '0') {
if(isgod==TRUE) reset_god();
return;
}
/* validate designation */
if((isgod==FALSE)&&!desg_ok(TRUE,newdes,sptr)) {
return;
}
if (newdes == DROAD && isgod==FALSE) {
if( sptr->people < 100 ) {
errormsg("Need 100+ people to build a road!");
return;
}
roads_this_turn++;
if (roads_this_turn>2) {
roads_this_turn=2;
errormsg("Only two roads a turn! Let the road crews sleep!!");
return;
}
}
/* do not need metal to build a capitol from a city */
if((newdes==DFORT)||(newdes == DTOWN)) metal=DESCOST;
else if((newdes == DCITY)
||(newdes == DCAPITOL && sptr->designation!=DCITY)) metal=5*DESCOST;
if((newdes!=DTOWN)&&(newdes!=DFORT)&&(newdes!=DCITY)&&(newdes!=DCAPITOL)){
/*decrement treasury*/
if(newdes==DRUIN) {
if (sptr->fortress>4) {
sptr->fortress-=4;
} else {
sptr->fortress=0;
}
} else if (sptr->designation==DRUIN) {
curntn->tgold-=REBUILDCOST;
}
sptr->designation=newdes;
SADJDES;
if(newdes == DSTOCKADE)
curntn->tgold-=STOCKCOST*(1-isgod);
else
curntn->tgold-=DESCOST*(1-isgod);
} else if((isgod==FALSE)&&(curntn->metals<metal)) {
errormsg("Not enough metal for city, town, or fort");
} else if((newdes==DCITY)||(newdes==DCAPITOL)) {
if(sptr->designation==DRUIN){
curntn->tgold-=10*DESCOST*(1-isgod);
curntn->metals-=metal/2*(1-isgod);
} else {
curntn->tgold-=20*DESCOST*(1-isgod);
if(newdes==DCITY || sptr->designation!=DCITY)
curntn->metals-=metal*(1-isgod);
}
x=curntn->capx; /* need this for SADJDES2 */
y=curntn->capy;
/* can only have one capitol */
if(newdes==DCAPITOL){
if (sct[x][y].owner==country) {
sct[x][y].designation=DCITY;
SADJDES2;
}
curntn->capx=XREAL;
curntn->capy=YREAL;
}
sptr->designation=newdes;
SADJDES;
} else if((newdes==DFORT)||(newdes==DTOWN)){
curntn->tgold-=10*DESCOST*(1-isgod);
curntn->metals-=metal*(1-isgod);
sptr->designation=newdes;
SADJDES;
} else errormsg("Serious error: What designation are you?");
if(isgod==TRUE) reset_god();
}
/*build fort or ship-type */
void
construct()
{
int tmpvar,tmpvar2,onboard;
long cost;
int armbonus;
int x,y;
short nvynum=0;
short shipsize,amount;
short isgod=FALSE;
char type;
clear_bottom(0);
if(country==0){
isgod=TRUE;
country=sct[XREAL][YREAL].owner;
curntn= &ntn[country];
}
if(sct[XREAL][YREAL].owner!=country) {
errormsg("You do not own");
if(isgod==TRUE) reset_god();
return;
}
if((isgod==FALSE)&&(sct[XREAL][YREAL].people<=500)) {
errormsg("You need over 500 people to construct");
return;
}
if((isgod==FALSE) && (curntn->tgold < 0 )) {
errormsg("You are broke");
return;
}
tmpvar=FALSE;
for(x=XREAL-1;x<=XREAL+1;x++)
for(y=YREAL-1;y<=YREAL+1;y++)
if(ONMAP(x,y) && sct[x][y].altitude==WATER)
tmpvar=TRUE;
if((sct[XREAL][YREAL].designation==DTOWN)
||(sct[XREAL][YREAL].designation==DFORT)
||(sct[XREAL][YREAL].designation==DCAPITOL)
||(sct[XREAL][YREAL].designation==DCITY)) {
/*calculate cost for fort*/
cost=FORTCOST;
if(isgod==TRUE) cost=0;
else for(x=1;x<=sct[XREAL][YREAL].fortress;x++)
cost*=2;
if(sct[XREAL][YREAL].designation==DTOWN) armbonus=TOWNSTR;
else if(sct[XREAL][YREAL].designation==DFORT) armbonus=FORTSTR;
else if(sct[XREAL][YREAL].designation==DCAPITOL) armbonus=CITYSTR;
else if(sct[XREAL][YREAL].designation==DCITY) armbonus=CITYSTR;
if(magic(country,ARCHITECT)==TRUE) armbonus*=2;
if(tmpvar)
mvprintw(LINES-4,0,"<f>ortify sector (+%d%%/%ld talons); <b>uild or <r>epair ships?: ",armbonus,cost);
else
mvprintw(LINES-4,0,"<f>ortify sector (+%d%% - %ld talons):",armbonus,cost);
refresh();
type=getch();
} else {
errormsg("Must construct in town, city, or fortress");
if (isgod==TRUE) reset_god();
return;
}
/* construct ships*/
if((type=='b')||(type=='r')) {
/*check if next to sea*/
if((tmpvar==FALSE)||(sct[XREAL][YREAL].designation==DFORT)){
errormsg("not in a harbor");
if(isgod==TRUE) reset_god();
return;
}
nvynum=getselunit()-MAXARM;
if(type=='r') {
if((nvynum>=MAXNAVY)||(nvynum<0)){
errormsg("INVALID NAVY");
if(isgod==TRUE) reset_god();
return;
}
if (P_NCREW==SHIPCREW) {
errormsg("You may only &^#$! repair damaged fleets!!!");
return;
}
clear_bottom(0);
shipsize = flthold(nvynum);
mvprintw(LINES-4,0,"Repairing Fleet (%d)",nvynum);
mvprintw(LINES-4,30,"Storage Units [%d]",shipsize);
mvprintw(LINES-3,0,"crew per unit = %d",(int)P_NCREW);
mvprintw(LINES-3,30,"max crew per unit = %d",SHIPCREW);
mvaddstr(LINES-2,0,"How many crew per unit do you wish to add:");
clrtoeol();
refresh();
amount = (short) get_number();
if (amount<0) {
if(isgod==TRUE) reset_god();
return;
}
/* find cost of repairs on all ships */
cost = 0;
for(tmpvar=N_LIGHT;tmpvar<=N_HEAVY;tmpvar++) {
cost += (tmpvar+1)*WARSHPCOST*P_NWAR(tmpvar);
cost += (tmpvar+1)*MERSHPCOST*P_NMER(tmpvar);
cost += (tmpvar+1)*GALSHPCOST*P_NGAL(tmpvar);
}
cost *= amount / SHIPCREW;
if(isgod==TRUE) cost=0;
else if(magic(country,SAILOR)==TRUE) cost/=2L;
if( curntn->tgold < cost ) {
errormsg("NOT ENOUGH GOLD");
if(isgod==TRUE) reset_god();
return;
}
if( sct[XREAL][YREAL].people < amount * shipsize) {
errormsg("NOT ENOUGH CIVILIANS IN SECTOR");
if(isgod==TRUE) reset_god();
return;
}
if( SHIPCREW < P_NCREW + amount ){
errormsg("THAT WOULD EXCEED MAXIMUM SHIP CREW");
if(isgod==TRUE) reset_god();
return;
}
curntn->tgold -= cost;
sct[XREAL][YREAL].people -= amount*shipsize;
P_NCREW += (unsigned char) amount;
NADJCRW;
SADJCIV;
if(isgod==TRUE) reset_god();
return;
}
mvaddstr(LINES-3,0,"Do you wish to raise a new fleet? (y or n)");
clrtoeol();
refresh();
if(getch()=='y') nvynum=(-1);
clear_bottom(0);
if(nvynum<0) {
nvynum=0;
x=(-1);
while((x==(-1))&&(nvynum<MAXNAVY)) {
if(P_NWSHP==0 && P_NMSHP==0 && P_NGSHP==0) {
x=nvynum;
P_NWSHP=0;
P_NMSHP=0;
P_NGSHP=0;
P_NCREW=0;
P_NARMY=MAXARM;
P_NPEOP=0;
NADJHLD;
NADJCRW;
NADJWAR;
NADJMER;
NADJGAL;
}
nvynum++;
}
nvynum=x;
if(nvynum<0){
errormsg("NO FREE NAVIES");
if(isgod==TRUE) reset_god();
return;
} else
mvprintw(LINES-1,0,"Raising New Fleet (%d)",nvynum);
} else mvprintw(LINES-1,0,"Adding to Fleet (%d)",nvynum);
/* process type first to be consistant with drafting */
mvaddstr(LINES-4,0,"What ship type to construct: (W)arship (M)erchant (G)alley?");
refresh();
/*
* Note: 3 and 6 hard-coded for ship sizes based on
* 0 = light 1 = medium 2 = heavy
* Bad technique, but it is not worth saying
* (N_HEAVY-N_LIGHT+1) everywhere.
*/
switch(getch()) {
case 'w':
case 'W':
shipsize=0;
break;
case 'g':
case 'G':
shipsize=3;
break;
case 'm':
case 'M':
shipsize=6;
break;
case ' ':
if(isgod==TRUE) reset_god();
return;
default:
errormsg("Invalid Ship Type");
if(isgod==TRUE) reset_god();
return;
}
mvaddstr(LINES-3,0,"What ship class to construct: (L)ight (M)edium");
if(sct[XREAL][YREAL].designation!=DTOWN) addstr(" (H)eavy?");
else addstr("?");
refresh();
switch(getch()) {
case 'l':
case 'L':
shipsize+=N_LIGHT;
break;
case 'm':
case 'M':
shipsize+=N_MEDIUM;
break;
case 'h':
case 'H':
if(sct[XREAL][YREAL].designation==DTOWN) {
errormsg("Towns cannot construct heavy ships");
if(isgod==TRUE) reset_god();
return;
}
shipsize+=N_HEAVY;
break;
case ' ':
if(isgod==TRUE) reset_god();
return;
default:
errormsg("Invalid Ship Class");
if(isgod==TRUE) reset_god();
return;
}
mvaddstr(LINES-2,0,"How many ships to construct?");
refresh();
amount = (short) get_number();
/*sanity checks*/
if((amount>N_MASK)) amount=0;
if (amount<=0)
{
if(isgod==TRUE) reset_god();
return;
}
/* 6 and 3 hard coded ... see above comment */
cost = (long) amount * ( shipsize%3 + 1 );
if (shipsize>=6) {
cost *= MERSHPCOST;
} else if (shipsize>=3) {
cost *= GALSHPCOST;
} else {
cost *= WARSHPCOST;
}
if(isgod==TRUE) cost=0;
else if(magic(country,SAILOR)==TRUE) cost/=2L;
if((cost > curntn->tgold) && (cost > 0)) {
errormsg("sorry - not enough talons");
return;
}
if( sct[XREAL][YREAL].people < amount * (shipsize+1) * SHIPCREW ){
errormsg("NOT ENOUGH CIVILIANS IN SECTOR");
if(isgod==TRUE) reset_god();
return;
}
if((nvynum>=0)&&(nvynum<MAXNAVY)) {
clear_bottom(0);
tmpvar = amount*SHIPCREW*(shipsize%3+1)
+ flthold(nvynum)*P_NCREW;
onboard = P_NPEOP*fltmhold(nvynum);
if (shipsize>=6) {
shipsize %= 3;
tmpvar2 = NADD_MER(amount);
} else if (shipsize>=3) {
shipsize %= 3;
tmpvar2 = NADD_GAL(amount);
} else {
shipsize %= 3;
tmpvar2 = NADD_WAR(amount);
}
/* check for bad build */
if (tmpvar2==FALSE) {
errormsg("Too many such ships in fleet.");
if(isgod==TRUE) reset_god();
return;
}
/* crew average based on number of holding units */
P_NCREW = (unsigned char)( tmpvar / flthold(nvynum) );
sct[XREAL][YREAL].people-=amount*(shipsize+1)*SHIPCREW;
curntn->tgold -= cost;
P_NXLOC =XREAL;
P_NYLOC =YREAL;
P_NMOVE=0;
mvprintw(LINES-4,0,"Fleet (%2d): Warships = [Light %2hd/Medium %2hd/Heavy %2hd]",nvynum,P_NWAR(N_LIGHT),P_NWAR(N_MEDIUM),P_NWAR(N_HEAVY));
mvprintw(LINES-3,0," Merchants = [Light %2hd/Medium %2hd/Heavy %2hd]",P_NMER(N_LIGHT),P_NMER(N_MEDIUM),P_NMER(N_HEAVY));
mvprintw(LINES-2,0,"Avg Crew[%3d] Galleys = [Light %2hd/Medium %2hd/Heavy %2hd]",(int)P_NCREW,P_NGAL(N_LIGHT),P_NGAL(N_MEDIUM),P_NGAL(N_HEAVY));
if(fltmhold(nvynum)>0)
P_NPEOP = (unsigned char) (onboard/fltmhold(nvynum));
else P_NPEOP = 0;
SADJCIV;
NADJCRW;
NADJWAR;
NADJMER;
NADJGAL;
NADJHLD;
NADJLOC;
NADJMOV;
mvaddstr(LINES-2,65,"HIT ANY KEY");
refresh();
getch();
} else errormsg("ERROR!!!!!!!!!!!!!");
}
/* construct fortification points*/
else if(type=='f'){
/* can only go into debt as much as the nation has jewels */
if (sct[XREAL][YREAL].fortress>11) {
errormsg("That sector is as impregnable as you can make it");
} else if ((curntn->tgold - cost) >= ((-1)*10*curntn->jewels)) {
mvprintw(LINES-2,5,"you build +%d%% fort points for %ld gold",armbonus,cost);
curntn->tgold-=cost;
sct[XREAL][YREAL].fortress++;
INCFORT;
errormsg("");
} else errormsg("you may not spend that much");
}
else errormsg("invalid input error");
if(isgod==TRUE) reset_god();
refresh();
}
/*DRAFT IF IN A CITY*/
void
draft()
{
short armynum,x,y,i;
long men=0,mercs;
short army=(-1), isgod=FALSE, newtype=0;
long i_cost, e_cost;
char ch;
clear_bottom(0);
if(country==0) {
isgod=TRUE;
country=sct[XREAL][YREAL].owner;
curntn= &ntn[country];
} else if(sct[XREAL][YREAL].owner!=country) {
errormsg("You do not own");
return;
}
if((sct[XREAL][YREAL].designation!=DTOWN)
&&(sct[XREAL][YREAL].designation!=DCAPITOL)
&&(sct[XREAL][YREAL].designation!=DCITY)) {
errormsg("must raise in towns/cities/capitols");
if(isgod==TRUE) reset_god();
return;
}
if(curntn->tgold <= 0){
errormsg("You are broke");
if(isgod==TRUE) reset_god();
return;
}
if(ISCITY(sct[XREAL][YREAL].designation)
&&(sct[XREAL][YREAL].people*(3*CITYLIMIT+(curntn->tsctrs/2))<curntn->tciv)){
mvprintw(LINES-1,0,"Need %d people in sector: hit any key",curntn->tciv/(3*CITYLIMIT+(curntn->tsctrs/2)));
refresh();
getch();
if(isgod==TRUE) reset_god();
return;
}
/*ask what type of unit*/
y=LINES-2;
mvaddstr(y,0,"options: 1) spy 2) scout");
clrtoeol();
x=25;
for(i=0;i<=NOUNITTYPES;i++){
if(unitvalid(i)==TRUE) {
mvprintw(y,x+2,"%s",*(shunittype+i));
mvprintw(y,x,"(%c)",*(shunittype+i)[0]);
x+= strlen( *(shunittype+i) ) +3;
if(x>COLS-10){
x=0;
y++;
}
}
}
move(y,x);
clrtoeol();
if((magic(country,WARRIOR)==TRUE)
||(magic(country,WARLORD)==TRUE)
||(magic(country,CAPTAIN)==TRUE))
mvaddstr(LINES-3,0,"(Warrior = 1/2 enlist cost) what type of unit do you want:");
else
mvaddstr(LINES-3,0,"what type of unit do you want to raise:");
clrtoeol();
refresh();
ch = getch();
for(newtype=0;newtype<=NOUNITTYPES;newtype++)
if(ch == *(shunittype+newtype)[0]) break;
if((newtype == NOUNITTYPES+1 )||(unitvalid(newtype)==FALSE)) {
if( ch == '1' ) newtype=A_SPY;
else if( ch == '2' ) newtype=A_SCOUT;
else {
errormsg("Invalid type");
if (isgod==TRUE) reset_god();
return;
}
}
clear_bottom(0);
/* marines and sailors may only be drafted in harbors */
if(newtype==A_MARINES || newtype==A_SAILOR) {
i=FALSE;
for (x=XREAL-1;x<=XREAL+1;x++)
for (y=YREAL-1;y<=YREAL+1;y++)
if (sct[x][y].altitude==WATER) i=TRUE;
/* not a harbor */
if (i==FALSE) {
if (newtype==A_MARINES)
errormsg("Huh? What would marines do without the water?");
else errormsg("You gotta be kinding!? Sailors on land?");
if (isgod==TRUE) reset_god();
return;
}
}
/*raise an untrained army */
i = FALSE;
if( newtype==A_SPY || newtype==A_SCOUT ) {
men=1;
} else {
mvprintw(LINES-3,0,"how many %s do you wish to raise:",unittype[newtype]);
clrtoeol();
refresh();
men = get_number();
if(men<=0) {
if (isgod==TRUE) reset_god();
return;
}
}
/* i_people*256 is initial people -> can draft up to following */
/* draftable = max_draft - already drafted */
/* = imen/4 - ( imen - people) */
/* = -3/4 * imen + people) */
/* 192 comes from 3*256/4 */
if( (newtype != A_MERCENARY && (men > sct[XREAL][YREAL].people - (sct[XREAL][YREAL].i_people*192) ) )
||(sct[XREAL][YREAL].i_people < 0)) {
if(sct[XREAL][YREAL].i_people < 0)
errormsg("error: sector wasn't city at beginning of turn");
else errormsg("error: raising too many soldiers");
if(isgod==TRUE) reset_god();
return;
}
/* check that you dont have too many mercenaries */
mercs=0;
if(newtype == A_MERCENARY){
int totalsolds=0;
for(armynum=0;armynum<MAXARM;armynum++){
if(P_ATYPE<MINLEADER) {
if(P_ATYPE==A_MERCENARY) mercs+=P_ASOLD;
totalsolds+=P_ASOLD;
}
}
if(men+mercs > (totalsolds+men)/2) {
errormsg("you would then have more than 50%% mercenaries");
if(isgod==TRUE) reset_god();
return;
}
if(mercgot+men > MERCMEN/NTOTAL) {
errormsg("there are not that many mercanaries available");
if(isgod==TRUE) reset_god();
return;
}
}
e_cost= (long) *(u_encost+newtype) * men;
i_cost= (long) *(u_enmetal+newtype) * men;
/*magiced get 1/2 enlistment costs*/
if((magic(country,WARRIOR)==TRUE)
||(magic(country,WARLORD)==TRUE)
||(magic(country,CAPTAIN)==TRUE))
e_cost/=2;
if((magic(country,SAPPER)==TRUE)
&&((newtype==A_SIEGE)||(newtype==A_CATAPULT))){
e_cost/=2;
i_cost/=2;
}
/*check to see if enough gold*/
if(e_cost > curntn->tgold) {
errormsg("You don't have enough talons");
if(isgod==TRUE) reset_god();
return;
} else if(i_cost > curntn->metals) {
mvprintw(LINES-1,0,"You don't have %ld metal",i_cost);
mvaddstr(LINES-1,COLS-20,"PRESS ANY KEY");
clrtoeol();
refresh();
getch();
if(isgod==TRUE) reset_god();
return;
} else {
move(LINES-2,0);
clrtoeol();
}
/*count is order of that army in sector*/
/*armynum is number of that army*/
if((armynum=getselunit())>=0){
if(armynum>=MAXARM || newtype==A_SPY || newtype==A_SCOUT) {
army = -1;
} else {
/*if different types, must raise new army*/
if((newtype == P_ATYPE)&&(P_ASTAT!=ONBOARD)) {
mvaddstr(LINES-1,0,"Do you wish to raise a new army:");
clrtoeol();
refresh();
if(getch()!='y') army=armynum;
else army= -1;
}
else army=(-1);
}
}
if(army==(-1)) {
mvprintw(LINES-2,0,"(%s, gold talons=%ld, metal=%ld) raising a new army",*(unittype+newtype),e_cost,i_cost);
clrtoeol();
refresh();
sleep(1);
armynum=0;
while((army==(-1))&&(armynum<MAXARM)) {
if(P_ASOLD<=0) {
army=armynum;
P_ASOLD=0;
if( newtype==A_MILITIA )
P_ASTAT=MILITIA;/* new militia units=MILITIA */
else
P_ASTAT=DEFEND; /* set new armies to DEFEND */
AADJSTAT;
AADJMEN;
}
armynum++;
}
if(army==(-1)){
errormsg("NO FREE ARMIES");
if(isgod==TRUE) reset_god();
return;
}
armynum=army;
} else {
mvprintw(LINES-2,0,"(%s, gold talons=%ld, metal=%ld) adding to existing army",*(unittype+newtype),e_cost,i_cost);
clrtoeol();
refresh();
sleep(2);
}
if( newtype == A_SPY ) {
while(TRUE){
clear_bottom(0);
mvaddstr(LINES-3,0,"Spy Against What Nation: ");
refresh();
if((i = get_country())==(-1)) {
if (isgod==TRUE) reset_god();
return;
}
if(i==country) {
errormsg("What? You don't even trust yourself?");
i=NTOTAL;
}
if(!(isntn(ntn[i].active))) {
errormsg("You can't spy against them");
i=NTOTAL;
}
if( i<NTOTAL && isactive(i)) break;
}
if(curntn->dstatus[i]!=UNMET) {
P_AYLOC = ntn[i].capy;
P_AXLOC = ntn[i].capx;
mvprintw(LINES-2,0,"The Spy Starts in %s's Capitol (%d,%d)",
ntn[i].name,(int)P_AXLOC,(int)P_AYLOC);
clrtoeol();
} else {
clear_bottom(0);
mvprintw(LINES-4,0,"You do not yet know where %s is",ntn[i].name);
mvaddstr(LINES-3,0,"Have the Spy start from this sector? [y or n]");
refresh();
if(getch()!='y') {
if(isgod==TRUE) reset_god();
return;
}
P_AYLOC = YREAL;
P_AXLOC = XREAL;