forked from vejeta/conquer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.c
More file actions
1903 lines (1724 loc) · 44.5 KB
/
misc.c
File metadata and controls
1903 lines (1724 loc) · 44.5 KB
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 Edward M Barlow */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curses.h>
#include <strings.h>
#ifdef CONQUER
#include <sys/types.h>
#include <sys/stat.h>
#endif /*CONQUER*/
#include "header.h"
#include "data.h"
extern FILE *fnews;
extern short country,redraw;
extern char *HVegcost, *OVegcost, *EVegcost, *DVegcost, *FVegcost;
extern char *HElecost, *OElecost, *EElecost, *DElecost, *FElecost;
#ifdef SYSV
char *memset();
#endif
#ifdef CONQUER
int
move_file( from, to )
register char *from;
register char *to;
{
if( unlink( to ) < 0 ) {
fprintf( stderr, "unlink( %s ) failed \n", to );
sleep( 2 );
return( -1 );
}
if( link( from, to ) < 0 ) {
fprintf( stderr, "link( %s, %s ) failed \n", from, to );
sleep( 2 );
return( -1 );
}
if( unlink( from ) < 0 ) {
fprintf( stderr, "unlink( %s ) failed \n", from );
sleep( 2 );
return( -1 );
}
return( 0 );
} /* move_file() */
#endif /* CONQUER */
/* returns integer input greater than zero or */
/* -1 for no input. */
long
get_number()
{
long sum=0;
char ch;
int done=FALSE,count=0,xpos,ypos;
/* this routine totally redone to allow deleting */
while(!done) {
ch=getch();
if(isdigit(ch) && count<12) {
/* only print numbers to the screen */
addch(ch);
refresh();
sum *= 10L;
count++;
sum += (long)(ch-'0');
} else if ((ch=='\b' || ch=='\177')&&(count)) {
/* only delete what was printed */
getyx(stdscr,ypos,xpos);
move(ypos,--xpos);
addch(' ');
move(ypos,xpos);
refresh();
sum /= 10L;
count--;
} else if((ch=='\n')||(ch=='\r')) {
done=TRUE;
}
}
if (count==0) {
return(-1);
}
return( sum );
}
#define INFINITE 1000
int bx; /* destination 'x' coordinate */
int by; /* destination 'y' coordinate */
int moving_country; /* country that is moving */
#define MAX_MOVE_UNITS 0x7f
unsigned char **history_reachp;
int level;
/*
* land_2reachp()
*/
int
land_2reachp( ax, ay, move_points )
int ax;
int ay;
int move_points;
{
register int i = 0;
int delta_x, delta_y;
int x_abs_delta, y_abs_delta;
int own;
int dx[ 8 ];
int dy[ 8 ];
delta_x = bx - ax;
delta_y = by - ay;
/* Have we got where we are going? */
if( delta_x == 0 && delta_y == 0 ) {
return( 1 );
}
/* Any move points left? (optimization) */
if( move_points == 0 ) {
return( 0 );
}
x_abs_delta = (delta_x < 0) ? -delta_x : delta_x;
y_abs_delta = (delta_y < 0) ? -delta_y : delta_y;
/* couldn't reach if all moves cost 1 (optimization) */
if( max( x_abs_delta, y_abs_delta ) > move_points ) {
return( 0 );
}
{
register int inc_x;
register int inc_y;
inc_x = (delta_x < 0 ) ? -1 : 1;
inc_y = (delta_y < 0 ) ? -1 : 1;
/*I HAVE CHANGED THIS CODE FROM THE ORIGINAL TO OPTIMIZE IT*/
/*I think it should work well*/
if( y_abs_delta == 0) {
/* try 'x' movements first */
dx[i] = inc_x; dy[i++] = 0;
dx[i] = inc_x; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = -inc_y;
dx[i] = 0; dy[i++] = inc_y;
dx[i] = 0; dy[i++] = -inc_y;
dx[i] = -inc_x; dy[i++] = inc_y;
dx[i] = -inc_x; dy[i++] = 0;
dx[i] = -inc_x; dy[i++] = -inc_y;
} else if( x_abs_delta == 0 ) {
/* try 'y' movements first */
dx[i] = 0; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = inc_y;
dx[i] = -inc_x; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = 0;
dx[i] = -inc_x; dy[i++] = 0;
dx[i] = inc_x; dy[i++] = -inc_y;
dx[i] = 0; dy[i++] = -inc_y;
dx[i] = -inc_x; dy[i++] = -inc_y;
} else { /* x_abs_delta != 0, 0 != y_abs_delta */
/* try diagonal movements first */
dx[i] = inc_x; dy[i++] = inc_y;
dx[i] = 0; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = 0;
dx[i] = -inc_x; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = -inc_y;
dx[i] = -inc_x; dy[i++] = 0;
dx[i] = 0; dy[i++] = -inc_y;
dx[i] = -inc_x; dy[i++] = -inc_y;
} /* if */
} /* block */
{
register int x, y;
register int new_mp;
for( i = 0; i < 8; i++ ) {
if( (x = ax + dx[i]) < 0 || x >= MAPX )
continue;
if( (y = ay + dy[i]) < 0 || y >= MAPY )
continue;
if ( movecost[ x ][ y ] < 0 ) /* just in case */
continue;
if( sct[x][y].altitude == PEAK)
continue;
if( sct[x][y].altitude == WATER)
continue;
new_mp = move_points - movecost[ x ][ y ];
if( new_mp < 0 )
continue;
/*
* If we have been to this sector before
* in fewer move points this path is not
* going to do any better.
*/
if( history_reachp[x][y] >= new_mp ) {
continue;
}
history_reachp[x][y] = new_mp;
/*
* Test for a hostile army
*/
/* BUG: should engage if army is hostile but does not own sector */
/* BUG: take into account THE_VOID, HIDDEN, and NINJA */
if( (own = sct[x][y].owner) > 0 &&
ntn[own].dstatus[moving_country] >= WAR &&
x != bx && y != by &&
solds_in_sector( x, y, own ) > 0 ) {
continue; /* at war with the owner, may not pass */
}
if( own > 0 &&
ntn[moving_country].dstatus[own] < WAR &&
ntn[own].dstatus[moving_country] > ALLIED &&
ntn[own].dstatus[moving_country] < WAR) {
/* not at war with owner & owner is neutral,no passing*/
continue;
}
level++;
if( land_2reachp( x, y, new_mp ) ) {
level--;
return( 1 );
} /* if */
level--;
} /* for */
} /* block */
return( 0 );
} /* land_2reachp() */
/*
* land_reachp()
*/
#ifdef ADMIN
int
land_reachp( ax, ay, gx, gy, move_points, movee )
int ax;
int ay;
int gx;
int gy;
int move_points;
int movee;
{
int result;
if( move_points >= MAX_MOVE_UNITS ) {
fprintf( stderr, "land_reachp(): move_points = %d\n",
move_points );
abrt();
}
/* Are we starting or ending in the water or on a peak? */
if( sct[ax][ay].altitude == WATER || sct[ax][ay].altitude == PEAK )
return( 0 );
if( sct[gx][gy].altitude == WATER || sct[gx][gy].altitude == PEAK )
return( 0 );
history_reachp = (unsigned char **) m2alloc(MAPX,MAPY,sizeof(char));
#ifdef BSD
bzero((char *) *history_reachp,MAPX*MAPY);
#else
memset((char *) *history_reachp, 0, MAPX*MAPY );
#endif
history_reachp[ax][ay] = move_points;
bx = gx;
by = gy;
moving_country = movee;
level = 1;
result = land_2reachp( ax, ay, move_points );
free(history_reachp);
return( result );
} /* land_reachp() */
#endif /* ADMIN */
#ifdef ADMIN
/*
* water_2reachp()
*/
int
water_2reachp( ax, ay, move_points )
int ax;
int ay;
int move_points;
{
register int i = 0;
int delta_x;
int delta_y;
int dx[ 8 ];
int dy[ 8 ];
/* this path uses too many move units */
if( move_points < 0 )
return( 0 );
/*
* If we have been to this sector before in fewer move points
* this path is not going to do any better.
*/
if( history_reachp[ ax ][ ay ] <= move_points )
return( 0 );
history_reachp[ ax ][ ay ] = move_points;
delta_x = ax - bx;
delta_y = ay - by;
/* Have we got where we are going? */
if( delta_x == 0 && delta_y == 0 )
return( 1 );
/* Have we run into ground, but not reached our destination? */
if( sct[ax][ay].altitude != WATER )
return( 0 );
/* Any move points left? (optimization) */
if( move_points == 0 )
return( 0 );
/* couldn't reach if all moves cost 1 (optimization) */
if( max( abs( delta_x ), abs( delta_y ) ) > move_points )
return( 0 );
/* BUG: test for an enemy navy */
{
register int inc_x;
register int inc_y;
inc_x = (delta_x < 0 ) ? -1 : (delta_x > 0) ? 1 : 0;
inc_y = (delta_y < 0 ) ? -1 : (delta_y > 0) ? 1 : 0;
if( abs(delta_x) > abs(delta_y) ) {
/* try 'x' movements first */
dx[i] = inc_x; dy[i++] = 0;
dx[i] = inc_x; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = -inc_y;
dx[i] = 0; dy[i++] = inc_y;
dx[i] = 0; dy[i++] = -inc_y;
dx[i] = -inc_x; dy[i++] = inc_y;
dx[i] = -inc_x; dy[i++] = 0;
dx[i] = -inc_x; dy[i++] = -inc_y;
} else { /* abs(delta_x) < abs(delta_y) */
/* try 'y' movements first */
dx[i] = 0; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = inc_y;
dx[i] = -inc_x; dy[i++] = inc_y;
dx[i] = inc_x; dy[i++] = 0;
dx[i] = -inc_x; dy[i++] = 0;
dx[i] = inc_x; dy[i++] = -inc_y;
dx[i] = 0; dy[i++] = -inc_y;
dx[i] = -inc_x; dy[i++] = -inc_y;
} /* if */
} /* block */
{
register int x, y;
register int new_mp;
for( i = 0; i < 8; i++ ) {
if( (x = ax + dx[i]) < 0 || x >= MAPX )
continue;
if( (y = ay + dy[i]) < 0 || y >= MAPY )
continue;
new_mp = move_points - 1;
if( new_mp < 0 )
continue;
if( water_2reachp( x, y, new_mp ) )
return( 1 );
} /* for */
} /* block */
return( 0 );
} /* water_2reachp() */
#endif /* ADMIN */
#ifdef XYZ /* XYZ never is defined */
/*
* water_reachp()
*/
int
water_reachp( ax, ay, gx, gy, move_points, movee )
int ax;
int ay;
int gx;
int gy;
int move_points;
int movee;
{
if( move_points >= MAX_MOVE_UNITS ) {
fprintf( stderr, "water_reachp(): move_points = %d\n",
move_points );
abrt();
}
#ifdef SYSV
memset(history_reachp, MAX_MOVE_UNITS, MAPX*MAPY*sizeof(history_reachp));
#else
{ register int i,j;
for (i=0; i < MAPX ; i++)
for (j=0; j < MAPY ; j++ )
history_reachp [i] [j] = MAX_MOVE_UNITS ;
}/* eof memset replacement block */
#endif
history_reachp[ ax ][ ay ] = 0;
bx = gx;
by = gy;
moving_country = movee;
return( water_2reachp( ax, ay, move_points ) );
} /* water_reachp() */
#endif /* 0 */
/*
* solds_in_sector()
*/
long
solds_in_sector( x, y, nation )
int x;
int y;
int nation;
{
register struct s_nation *nptr = &ntn[nation];
register int j;
long total = 0;
for( j = 0; j < MAXARM; j++ ) {
if( nptr->arm[j].sold == 0 )
continue;
if( nptr->arm[j].xloc == x && nptr->arm[j].yloc == y )
total += nptr->arm[j].sold;
}
return( total );
} /* solds_in_sector() */
#ifdef ADMIN
/* score_one() */
struct wght {
int sectors;
int civilians;
int soldiers;
int gold;
int jewels;
int metal;
int magics;
int ships;
} weights[] = {
/* Per 2 1000 1000 100K 100K 100K Magic 10 */
/* Races Sector People Soldiers Gold Jewels Iron Power Ship */
/* NPC */ { 2, 1, 0, 0, 1, 1, 1, 0 },
/* kingdom */ { 2, 1, 2, 3, 0, 0, 0, 0 },
/* empire */ { 3, 0, 0, 1, 1, 0, 0, 0 },
/* wizard */ { 0, 2, 1, 0, 3, 5, 7, 0 },
/* theocracy */ { 2, 1, 0, 0, 3, 0, 3, 0 },
/* pirate */ { 0, 0, 5, 0, 10, 10, 1, 5 },
/* trader */ { 2, 1, 0, 0, 1, 1, 1, 8 },
/* warlord */ { 2, 1, 2, 0, 1, 1, 1, 0 },
/* demon */ { 2, 0, 1, 0, 1, 0, 5, 0 },
/* dragon */ { 0, 0, 0, 10, 20, 0, 0, 0 },
/* shadow */ { 2, 0, 0, 0, 0, 5, 0, 0 },
/* miner */ { 0, 0, 5, 0, 10, 10, 1, 5 },
};
long
score_one( nation )
int nation;
{
struct s_nation *nptr = &ntn[ nation ];
long total = 0;
int bonus;
struct wght *wght = &weights[ nptr->class ];
total += wght->sectors * nptr->tsctrs / 2L;
total += wght->civilians * nptr->tciv / 1000L;
total += wght->soldiers * nptr->tmil / 1000L;
if(nptr->tgold > 0 ) total += wght->gold * (nptr->tgold / 100000L);
total += wght->jewels * nptr->jewels / 100000L;
total += wght->metal * nptr->metals / 100000L;
total += wght->magics * num_powers(nation,M_MIL);
total += wght->magics * num_powers(nation,M_CIV);
total += wght->magics * num_powers(nation,M_MGK);
total += wght->ships * nptr->tships / 10L;
switch( nptr->class ) {
case C_KING:
bonus=(nptr->popularity+nptr->prestige-nptr->poverty);
break;
case C_EMPEROR:
bonus=(nptr->power+nptr->prestige-nptr->poverty);
break;
case C_WIZARD:
bonus=(nptr->knowledge+nptr->power-50);
break;
case C_PRIEST:
bonus=(nptr->wealth+nptr->terror-nptr->poverty);
break;
case C_PIRATE:
bonus=(nptr->reputation+nptr->wealth-50);
break;
case C_TRADER:
bonus=(nptr->wealth+nptr->prestige-nptr->tax_rate*5);
break;
case C_WARLORD:
bonus=(nptr->reputation+nptr->prestige-50);
break;
case C_DEMON :
bonus=(nptr->knowledge+nptr->terror-50);
break;
case C_DRAGON:
bonus=(nptr->wealth+nptr->terror-50);
break;
case C_SHADOW:
bonus=(nptr->power+nptr->terror-50);
break;
default: bonus=0;
}
total += bonus/10;
return( total );
} /* score_one() */
#endif /* ADMIN */
/*
* print_accum()
*/
/* max number of print_accum() calls in one printf() */
#define MAX_BUFFER 4
#define BUFFER_SIZE 20
/* is_habitable() - returns TRUE/FALSE if habitable */
int
is_habitable( x, y )
int x;
int y;
{
char temp;
if(( (temp=sct[x][y].altitude)==WATER )||( temp==PEAK )) return(FALSE);
if(((temp=sct[x][y].vegetation)==BARREN )
|| ( temp==LT_VEG )
|| ( temp==GOOD )
|| ( temp==WOOD )
|| ( temp==FOREST )) return( TRUE );
return( FALSE );
}
#ifdef CONQUER
int
units_in_sector(x,y,nation)
int x;
int y;
{
int count=0, armynum, nvynum;
struct s_nation *nptr = curntn;
curntn = &ntn[nation];
for(armynum=0;armynum<MAXARM;armynum++)
if((P_ASOLD>0)&&(P_AXLOC==x)&&(P_AYLOC==y)) count++;
for(nvynum=0;nvynum<MAXNAVY;nvynum++)
if(((P_NWSHP+P_NMSHP+P_NGSHP)!=0)&&
(P_NXLOC==x)&&(P_NYLOC==y)) count++;
curntn = nptr;
return(count);
}
#endif /* CONQUER */
int
num_powers(nation,type)
int nation,type;
{
int count_magic=0;
int try;
long start, end;
switch(type){
case M_MGK:
start=S_MGK;
end=E_MGK;
break;
case M_CIV:
start=S_CIV;
end=E_CIV;
break;
case M_MIL:
start=S_MIL;
end=E_MIL;
break;
case M_ALL:
start=S_MIL;
end=E_MGK;
break;
default:
fprintf(stderr,"fatal error in num_powers");
abrt();
}
for( try = start; try < start+end; try++ )
if( magic(nation, powers[try] ) == 1 ) count_magic++;
return(count_magic);
}
/* returns food value of sector */
/* 4 is limit of livable land */
int
tofood(sptr,cntry)
struct s_sector *sptr;
int cntry;
{
register int i=0;
register int foodvalue;
while( sptr->vegetation != *(veg+i) ) i++;
foodvalue = *(vegfood+i) - '0';
if( cntry != 0 ) {
if(foodvalue == 0) {
#ifdef DERVDESG
if ((magic(cntry,DERVISH)||magic(cntry,DESTROYER))
&&(sptr->vegetation==DESERT || sptr->vegetation==ICE))
return(6);
#endif /* DERVDESG */
return( 0 );
}
if(ntn[cntry].race == ELF){
if(sptr->vegetation == FOREST) foodvalue+=3;
else if(sptr->vegetation == BARREN) foodvalue--;
}
}
if(( sptr->tradegood <= END_EATRATE )
&&( sptr->tradegood > END_COMMUNICATION ))
foodvalue += *(tg_value+sptr->tradegood) - '0';
return( foodvalue );
}
/*jewel cost for civilian power = Base * 2**( #mgk/2 + #civ + #mil/2 ) */
/*race magical civilian military */
/* elves - 50K 50K 50K */
/* dwarves - 80K 40K 40K */
/* humans - 100K 25K 50K */
/* orcs - 100K 50K 25K */
/* returns cost of magic power - returns -1 if invalid */
long
getmgkcost(type,nation)
int type, nation;
{
int i;
long cost;
long base=BASEMAGIC;
int npowers;
switch(type) {
case M_MGK:
if(ntn[nation].race==DWARF) base=DWFMAGIC;
else if(ntn[nation].race==HUMAN) base=HUMMAGIC;
else if(ntn[nation].race==ORC) base=ORCMAGIC;
npowers=num_powers(nation,M_CIV)+num_powers(nation,M_MIL)+1
+2*num_powers(nation,M_MGK);
npowers/=2;
break;
case M_CIV:
if(ntn[nation].race==DWARF) base=DWFCIVIL;
else if(ntn[nation].race==HUMAN) base=HUMCIVIL;
else if(ntn[nation].race==ORC) base=ORCCIVIL;
npowers=num_powers(nation,M_MGK)+num_powers(nation,M_MIL)+1
+2*num_powers(nation,M_CIV);
npowers/=2;
break;
case M_MIL:
if(ntn[nation].race==DWARF) base=DWFMILIT;
else if(ntn[nation].race==ORC) base=ORCMILIT;
npowers=num_powers(nation,M_CIV)+num_powers(nation,M_MGK)+1
+2*num_powers(nation,M_MIL);
npowers/=2;
break;
default:
return(-1);
}
cost = base;
for (i=1; i<npowers; i++) {
cost <<= 1;
if (cost > BIG)
return(BIG/2L);
}
return(cost);
}
int
todigit(character)
register int character;
{
if( character >= '0' && character <= '9' )
return( character - '0' );
return( -1 );
}
/* set up occ[][] for country.
* if leader==true, only for leader sectors plus ntn.communicatins range
* if leader==(-1), do not include ships on the sector search
*/
void
prep(nation,leader)
int nation,leader;
{
short armynum,nvynum;
int save,i,j,x,y,start,end,com;
/*set occ to 0*/
for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++) occ[i][j]=0;
save=nation;
if(leader==TRUE) {
/* only do the given country */
start=save;
end=save+1;
} else {
/* go through all countries */
start=0;
end=NTOTAL;
}
/*set occ to country of occupant army*/
for(nation=start;nation<end;nation++) if(ntn[nation].active!=INACTIVE) {
curntn = &ntn[nation];
for(armynum=0;armynum<MAXARM;armynum++){
if( leader==TRUE ) {
if((P_ATYPE<MINLEADER)
||(P_ATYPE>=MINMONSTER)
||(P_ASOLD<=0)) continue;
i=P_AXLOC;
j=P_AYLOC;
com = P_NTNCOM; /* do communications radius */
for(x=i-com;x<=i+com;x++)
for(y=j-com;y<=j+com;y++)
if(ONMAP(x,y)) occ[x][y]=nation;
} else if((P_ASOLD>0)&&(P_ASTAT!=SCOUT)){
i=P_AXLOC;
j=P_AYLOC;
if((occ[i][j]== 0)||(occ[i][j]== nation))
occ[i][j]= nation;
else occ[i][j]= NTOTAL;
}
}
if( leader==FALSE ) for(nvynum=0;nvynum<MAXNAVY;nvynum++){
if((P_NWSHP!=0)||(P_NGSHP!=0)||(P_NMSHP!=0)){
i=P_NXLOC;
j=P_NYLOC;
if((occ[i][j]== 0)||(occ[i][j]== nation))
occ[i][j]= nation;
else occ[i][j]= NTOTAL;
}
}
}
nation=save;
curntn = &ntn[nation];
}
#ifdef ADMIN
/*routine to depelete a nation without a capitol */
void
deplete(nation)
int nation;
{
struct s_nation *saventn=curntn;
int i,j,x,y,armynum;
x = ntn[nation].capx;
y = ntn[nation].capy;
if((sct[x][y].designation==DCAPITOL)&&((sct[x][y].owner==nation)
||(sct[x][y].owner==0)||(!isntn(ntn[sct[x][y].owner].active))))
return;
curntn = &ntn[nation];
fprintf(fnews,"1.\tNation %s is depleted by the lack of a Capitol\n",ntn[nation].name);
for(armynum=0;armynum<MAXARM;armynum++) if (P_ASOLD>0) {
/* first disband PDEPLETE% of the military */
if (P_ATYPE<MINLEADER &&
(rand()%100<PDEPLETE||P_ATYPE==A_MERCENARY)) {
if(P_ATYPE==A_MERCENARY) {
MERCMEN += P_ASOLD;
} else if(ntn[sct[AXLOC][AYLOC].owner].race==ntn[nation].race) {
sct[P_AXLOC][P_AYLOC].people += P_ASOLD;
}
P_ASOLD=0;
if(ispc(curntn->active)) {
if (mailopen(nation)!=(-1)) {
fprintf(fm,"Message to %s from Conquer\n\n",curntn->name);
fprintf(fm,"\tYour %s Army %d disperses into the population\n",*(unittype+(P_ATYPE%UTYPE)),armynum);
mailclose(nation);
}
}
} else if(P_ATYPE>=MINMONSTER) {
/* disbanding of ALL monsters should take place */
P_ASOLD=0;
if(ispc(curntn->active)) {
if (mailopen(nation)!=(-1)) {
fprintf(fm,"Message to %s from Conquer\n\n",curntn->name);
fprintf(fm,"\tYour %s (unit %d) leaves due to the loss of your jewels.\n",*(unittype+(P_ATYPE%UTYPE)),armynum);
mailclose(nation);
}
}
}
}
/* check for sectors breaking away -- not capx, capy */
if(ispc(curntn->active)) {
/* create a summarized mail message of sectors effected */
if (mailopen(nation)!=(1)) {
fprintf(fm,"Message to %s from Conquer\n\n",curntn->name);
fprintf(fm,"Riots and Rebellion flourish:\n");
}
}
for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++)
if(sct[i][j].owner==nation && (i!=x || j!=y) ) {
if(rand()%100 < PDEPLETE && sct[x][y].people>0) {
if(rand()%100 < PDEPLETE) {
/* sector riots */
flee(i,j,TRUE,FALSE);
DEVASTATE(i,j);
if(ispc(curntn->active)) {
/* add to listing */
fprintf(fm,"\tsector %d, %d has massive riots\n",i,j);
}
} else {
/* sector becomes owned by another nation */
#ifdef NOTDONE
/* must work on this still */
giveaway(i,j,&nation);
if(ispc(curntn->active)) {
fprintf(fm,"\tsector %d, %d joins nation %s\n",ntn[nation].name);
}
#endif /* NOTDONE */
}
}
}
if(ispc(curntn->active)) {
mailclose(nation);
} else if(isnpc(curntn->active)) {
if(sct[curntn->capx][curntn->capy].owner==nation) {
/* reset capitol for npcs */
sct[curntn->capx][curntn->capy].designation=DCAPITOL;
if(sct[curntn->capx][curntn->capy].fortress<1)
sct[curntn->capx][curntn->capy].fortress=1;
}
}
/* restore */
curntn = saventn;
}
/*routine to sack a nation's captiol */
void
sackem(cntry)
int cntry;
{
struct s_nation *saventn=curntn;
int x,y,i,j,foundcap,nation;
/* hail the conquerer */
curntn = &ntn[cntry];
x = curntn->capx;
y = curntn->capy;
nation = sct[x][y].owner;
if(nation==cntry || nation==0) return;
/* advertise */
fprintf(fnews,"1.\tCapitol of %s sacked by %s\n",ntn[cntry].name,ntn[nation].name);
/* Remove goods from trade board */
fixtrade(cntry);
/* first give all prizes to the conquerer */
if(curntn->tgold > 0) { /* all gold */
ntn[nation].tgold += curntn->tgold;
curntn->tgold=0;
}
ntn[nation].jewels += curntn->jewels; /* all jewels */
curntn->jewels=0;
ntn[nation].metals += curntn->metals; /* all metals */
curntn->metals=0;
ntn[nation].tfood += curntn->tfood/5L; /* 20% of food */
curntn->tfood -= curntn->tfood/5L;
/* fix the designation */
if(sct[x][y].designation==DCAPITOL) {
if(isntn(ntn[nation].active)) {
sct[x][y].designation = DCITY;
} else {
DEVASTATE(x,y);
sct[x][y].owner=cntry;
}
}
/* set another sector to the capx, capy to make sure that */
/* sacking does not occur next update for same sacking. */
foundcap=FALSE;
for(i=0;foundcap==FALSE && i<MAPX;i++)
for(j=0;foundcap==FALSE && j<MAPY;j++) if(sct[i][j].owner==cntry) {
if(sct[i][j].designation==DCITY) {
x = i; y = j;
foundcap=TRUE;
} else if((sct[i][j].designation==DTOWN)
&&(((x==curntn->capx)&&(y==curntn->capy))
||(sct[x][y].designation!=DTOWN))) {
x = i; y = j;
} else if((x==curntn->capx)&&(y==curntn->capy)) {
x = i; y = j;
}
}
if ((x!=curntn->capx)||(y!=curntn->capy)) {
/* assign new pseudo capitol */
if(ispc(curntn->active)) {
if(mailopen(cntry)!=(-1)) {
fprintf(fm,"Message to %s from Conquer\n\n",ntn[cntry].name);
fprintf(fm,"\tYour Capitol at sector location %d,%d\n",curntn->capx,curntn->capy);
fprintf(fm,"\t was overrun by nation %s.\n\n",ntn[nation].name);
fprintf(fm,"\tA temporary headquarters is now in sector %d,%d,\n",x,y);
fprintf(fm,"\t but designation of a new Capitol is recommended.\n");
mailclose(cntry);
}
}
curntn->capx=x;
curntn->capy=y;
} else {
/* no new capitol assignment */
if(ispc(curntn->active)) {
if(mailopen(cntry)!=(-1)) {
fprintf(fm,"Message to %s from Conquer\n\n",ntn[cntry].name);
fprintf(fm,"\tYour Capitol at sector location %d,%d\n",curntn->capx,curntn->capy);
fprintf(fm,"\t was overrun by nation %s.\n\n",ntn[nation].name);
fprintf(fm,"\tNo other land remains. The destruction\n");
fprintf(fm,"\t of your nation seems imminent.\n");
mailclose(cntry);
}
}
}
/* restore */
curntn = saventn;
}
#endif /* ADMIN */
/*destroy nation--special case if capitol not owned by other nation*/
void
destroy(cntry)
int cntry;
{
short armynum, nvynum;
int i, x, y;
char buf[LINELTH];
struct s_nation *nptr;
nptr = &ntn[cntry];
if( !isactive(nptr->active) ) return;
if( !ismonst(nptr->active) ) {
fprintf(fnews,"1.\tNation %s was destroyed ",nptr->name);
if(cntry!=sct[nptr->capx][nptr->capy].owner){
fprintf(fnews,"(their capitol is now owned by %s)\n",ntn[sct[nptr->capx][nptr->capy].owner].name);
/*get +5% to combat skill*/
ntn[sct[nptr->capx][nptr->capy].owner].aplus+=5;
}
else fprintf(fnews,"(they owned their capitol)\n");
}
nptr->active=INACTIVE;
nptr->score=0;
sprintf(buf,"%s%d",msgfile,cntry);
unlink(buf);
for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0) {
if(ntn[sct[AXLOC][AYLOC].owner].race==nptr->race)
sct[AXLOC][AYLOC].people+=ASOLD;
ASOLD=0;
}
for(nvynum=0;nvynum<MAXNAVY;nvynum++) {
NMSHP=0;