]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - warp/init.c
1 /* Header: init.c,v 7.0.1.4 86/12/12 16:58:03 lwall Exp */
4 * Revision 7.0.1.4 86/12/12 16:58:03 lwall
5 * Baseline for net release.
7 * Revision 7.0.1.3 86/10/20 14:35:31 lwall
10 * Revision 7.0.1.2 86/10/17 15:53:30 lwall
11 * Added random walk star fields.
13 * Revision 7.0.1.1 86/10/16 10:51:19 lwall
14 * Added Damage. Fixed random bugs.
16 * Revision 7.0 86/10/08 15:12:10 lwall
17 * Split into separate files. Added amoebas and pirates.
46 int yoff
= 0, xoff
= 0, ypred
, xpred
;
54 static const char *distname
[] =
55 {" #"," -"," \\"," /",
58 cloaking
= madgorns
= false;
59 deados
= madfriends
= 0;
60 curscore
= possiblescore
= 0L;
61 yamblast
= xamblast
= ambsize
= 0;
64 scandist
= (massacre
?20:15);
65 antibase
= (smarts
>60?1:(smarts
>40?2:(smarts
>25?4:100)));
66 sm35
= (smarts
>35?35:smarts
);
67 sm45
= (smarts
>45?45:smarts
);
68 sm50
= (smarts
>50?50:smarts
);
69 sm55
= (smarts
>55?55:smarts
);
70 sm80
= (smarts
>80?80:smarts
);
71 sm95
= (smarts
>95?95:smarts
);
72 super
= (smarts
>50?smarts
-50:0);
73 enemshields
= 10 + super
/2; /* (scaled by 10) 1 @ 50 .. 3 @ 90 */
75 enemshields
+= (smarts
-90)*10; /* lay it on thick: ~13 @ 99 */
76 entmax
= (smarts
>=75?5000:(smarts
>=50?4000:(smarts
>=40?3000:2000)));
77 basemax
= (smarts
>=75?20000:(smarts
>=50?15000:(smarts
>=40?12500:10000)));
80 while (root
.next
!= &root
) {
81 root
.next
= root
.next
->next
;
82 free_object(root
.next
->prev
);
85 enemies
= movers
= NULL
;
87 #if defined(vax) && XYSIZEx4 == 3680
88 asm("movc5 $0,_occupant,$0,$3680,_occupant");
89 asm("movc5 $0,_blast,$0,$3680,_blast"); /* 3680 = XYSIZEx4 */
90 asm("movc5 $0,_amb,$32,$920,_amb");
93 for (x
=0;x
<XSIZE
;x
++) {
99 for (y
=0; y
<YSIZE
; y
++)
101 for (x
=0; x
<XSIZE
; x
++)
106 inumstars
= 50 + rand_mod(50);
107 else if (smarts
< 50 || smarts
> 85)
108 inumstars
= exdis(800) + rand_mod(100) + 1;
109 else /* too few stars makes 50..85 too hard */
110 inumstars
= exdis(700) + rand_mod(150-super
*2) + 50+super
*2;
112 tmptholspec
= (smarts
> 15 && inumstars
< 450 && ! rand_mod(90-sm80
));
114 inumenemies
= rand_mod((smarts
+1)/2) + 1;
115 if (massacre
|| tmptholspec
)
119 inumfriends
= rand_mod(smarts
/8+1);
121 inumpirates
= rand_mod(inumfriends
/2+1);
122 if (inumfriends
+inumenemies
+inumstars
> YSIZE
*XSIZE
-20)
123 inumstars
= YSIZE
*XSIZE
-20 - inumenemies
- inumfriends
;
125 inumfriends
+= inumstars
;
128 if (inumfriends
< 0) {
129 inumenemies
+= inumfriends
;
134 numstars
= inumstars
;
135 inuminhab
= numinhab
= 0;
136 inumroms
= inumthols
= inumgorns
= 0;
137 numapollos
= apolspec
|| massacre
? 1 :
138 ((!numstars
|| rand_mod(2) || smarts
< 10) ? 0 : 1);
139 inumapollos
= apolloflag
= 0;
141 inumcrushes
= numcrushes
=
142 crushspec
||massacre
?1:(rand_mod(2000) < inumstars
);
143 inumenemies
+= inumcrushes
;
144 inumamoebas
= numamoebas
= (amoebaspec
? 1 :
145 !rand_mod(inumcrushes
?3-massacre
:8) ); /* < and & are fun together */
146 inumenemies
+= inumamoebas
;
148 inhabjackpot
= 32767;
149 inumfriends
+= rand_mod(10);
150 inumpirates
+= rand_mod(10);
153 inhabjackpot
= inumpirates
;
154 inhenergy
= 30000-super
*150;
158 inhenergy
+= rand_mod(3500+super
*150);
159 numfriends
= inumfriends
;
160 numpirates
= inumpirates
;
161 numenemies
= inumenemies
;
169 else if (numstars
> 750)
172 dist
= rand_mod(starspec
||smarts
<=5?3:5);
174 real_y
= real_x
= -100;
178 case 0: /* uniform random */
180 if (inumstars
< 700 && !rand_mod(3-(inumstars
<50))) {
181 ydist
= xdist
= 6; /* well, maybe not so random */
185 walksplit
= inumstars
/(exdis(40)+1);
190 case 1: case 2: /* clumped, maybe skewed, maybe superposed */
194 printf("%s\r\n",distname
[ydist
+4*xdist
]);
195 yoff
= rand_mod(YSIZE
);
196 xoff
= rand_mod(XSIZE
);
198 dist
= numstars
/2 + exdis(numstars
/2) - exdis(numstars
/2);
202 case 3: case 4: /* predefined or residual */
207 snprintf(spbuf
, sizeof(spbuf
), "smap.%d",
208 (prescene
>=0?prescene
:rand_mod(MAPS
)) );
209 if ((mapfp
= fopen(spbuf
,"r")) != NULL
&&
210 fgets(spbuf
,10,mapfp
) != NULL
) {
211 inumstars
= numstars
= atoi(spbuf
);
212 if (inumenemies
+inumstars
> YSIZE
*XSIZE
-20)
213 inumstars
= numstars
= YSIZE
*XSIZE
-20 - inumenemies
;
214 ydist
= rand_mod(2) + 4; /* flip y axis? */
215 xdist
= rand_mod(2) + 4; /* flip x axis? */
216 yoff
= rand_mod(YSIZE
); /* how much to shift y */
217 xoff
= rand_mod(XSIZE
); /* how much to shift x */
228 for (i
= 1; i
<= numstars
; i
++) {
229 if (dist
&& i
== dist
) { /* flip to another skewing? */
238 printf("%s\r\n",distname
[ydist
+4*xdist
]);
239 yoff
= rand_mod(YSIZE
);
240 xoff
= rand_mod(XSIZE
);
243 do { /* until an open spot found */
246 x
= rand_mod(XSIZE
); /* pick from 0..39, uniform */
248 case 1: case 2: case 3:
249 x
= (int)((((double)(myrand()-HALFRAND
)) *
250 ((double)(myrand()-HALFRAND
))/RANDRAND
)
251 * 20.0) + xoff
; /* pick from -20..20, clumped */
254 if (fscanf(mapfp
,"%d %d\n",&ypred
,&xpred
) == EOF
)
259 if (fscanf(mapfp
,"%d %d\n",&ypred
,&xpred
) == EOF
)
264 x
+= rand_mod(3) - 1;
272 y
= (int)((((double)(myrand()-HALFRAND
)) *
273 ((double)(myrand()-HALFRAND
))/RANDRAND
)
274 * 12.0) + yoff
; /* pick from -12..12, clumped */
278 y
= (int)((((double)(myrand()-HALFRAND
)) *
279 ((double)(myrand()-HALFRAND
))/RANDRAND
)
280 * 12.0) + yoff
+ x
*YSIZE
/XSIZE
;
281 /* clumped & skewed */
286 y
= (int)((((double)(myrand()-HALFRAND
)) *
287 ((double)(myrand()-HALFRAND
))/RANDRAND
)
288 * 12.0) + yoff
- x
*YSIZE
/XSIZE
;
289 /* clumped & skewed */
299 y
+= rand_mod(3) - 1;
301 walksplit
= walksplit
;
303 if (!rand_mod(walksplit
)) {
309 while (x
<0) x
+= XSIZE00
;
310 while (y
<0) y
+= YSIZE00
;
313 } while (occupant
[y
][x
]);
315 if (--inhabjackpot
> 0 || e
>= inhenergy
) {
317 if (inhabjackpot
&& e
< 10000)
319 inuminhab
= ++numinhab
;
324 obj
= make_object(Star
,ch
,y
,x
,0,0,e
+rand_mod(super
*100+1),e
/4,&root
);
325 obj
->flags
|= STATIC
;
327 if (inumstars
> 30 && inhabjackpot
<= 0 &&
328 !rand_mod(3 - (inumstars
> 400) - (inhenergy
> 32768)) ) {
332 x
= initx
= obj
->posx
;
333 y
= inity
= obj
->posy
;
334 while (rand_mod(2) && inuminhab
< inumstars
/2) {
335 for (i
=rand_mod(smarts
)*2+20; i
; i
--) {
336 if ((obj
= occupant
[y
][x
]) && obj
->image
== '*') {
338 if (obj
->energy
< 10000)
339 obj
->energy
+= 20000; /* the benefits of civilization */
340 inuminhab
= ++numinhab
;
343 y
= (y
+ rand_mod(3) + YSIZE99
) % YSIZE
;
344 x
= (x
+ rand_mod(3) + XSIZE99
) % XSIZE
;
346 else { /* don't wander too far */
351 x
= initx
= rand_mod(XSIZE
);
352 y
= inity
= rand_mod(YSIZE
);
361 } while (occupant
[y
][x
]);
362 movers
= make_object(Crusher
,'<',y
,x
,0,1,32767L,32768L,&root
);
363 possiblescore
+= 10000;
365 ient
= (numents
!= 0);
370 } while (occupant
[y
][x
]);
372 ent
= make_object(Enterprise
,'E',y
,x
,0,0,e
,e
/2,&root
);
376 ibase
= (numbases
!= 0);
382 } while (occupant
[y
][x
] || lookaround(y
,x
,Star
) * 7 < e
--);
384 base
= make_object(Base
, 'B',y
,x
,0,0,e
,e
/4,&root
);
392 } while (occupant
[y
][x
]);
393 nuke
= make_object(Enemy
,'&',y
,x
,0,0,32767L,
394 (long)entmax
+entmax
+rand_mod(entmax
),&root
);
395 possiblescore
+= 10000;
398 modify_amoeba(y
,x
,2,'~',(int)rand_mod(smarts
<<1));/* just make blob */
400 for (i
=smarts
/10+1; i
; i
--) {
401 nuke
->strategy
= rand_mod(256); /* random direction */
402 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5));
403 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5));
404 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5));
405 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5)); /* extend pseudopod */
413 if (rand_mod(27-sm50
/2) && !romspec
&& !gornspec
)
416 dist
= rand_mod(4) + 1;
417 for (i
= 1+inumcrushes
+inumamoebas
; i
<= numenemies
; i
++) {
421 } while (occupant
[y
][x
]);
422 if (rand_mod(dist
)) {
423 if (!tholspec
&& !tmptholspec
&& rand_mod((inumstars
*3)/sm50
+2))
431 if (romspec
== gornspec
)
437 if (rand_mod(100) < e
) {
446 if (possiblescore
> ENTBOUNDARY
- 10000)
447 e
= (ENTBOUNDARY
- possiblescore
) / 5;
449 e
= 250 + (sm50
-1) * 30 * 20 / numenemies
+1;
451 e
= exdis((int)e
) + e
- exdis((int)e
);
452 obj
= make_object(Enemy
,ch
,y
,x
,0,0,
453 e
+ rand_mod(super
*200+2) + 10000*massacre
,e
/4,&root
);
461 possiblescore
+= e
*3/2;
464 possiblescore
+= e
*2;
467 possiblescore
+= e
*3;
468 obj
->flags
|= CLOAKS
;
476 numgorns
= inumgorns
;
477 for (i
=0; i
<numfriends
; i
++) {
481 } while (occupant
[y
][x
]);
482 e
= 250 + (sm50
-1) * 30 * 20 / numenemies
+1;
484 e
= exdis((int)e
) + e
- exdis((int)e
);
487 static char let
[] = "QWYUISDHJLZVMFFFFFFFFF";
491 } /* grr, venix doesn't like strchring into string */
492 obj
= make_object(Enemy
,ch
,y
,x
,0,0,
493 e
+ rand_mod(super
*200+2),e
/4,&root
);
494 if (numpirates
-- > 0) {
495 obj
->flags
|= PIRATE
;
496 if (smarts
>= 20 && !rand_mod(10-smarts
/10))
497 obj
->flags
|= CLOAKS
;
499 obj
->flags
|= FRIENDLY
;
510 mvaddch(ent
->posy
+1, ent
->posx
*2, ent
->image
);
512 mvaddch(base
->posy
+1, base
->posx
*2, base
->image
);
517 for (curobj
= root
.next
; curobj
!= &root
; curobj
= curobj
->next
) {
518 mvaddch(curobj
->posy
+1, curobj
->posx
*2, curobj
->image
);
522 for (i
=0;i
<2;i
++) for (y
=0;y
<3;y
++) for (x
=0;x
<3;x
++)
530 entmode
= status
= 0;
537 snprintf(spbuf
, sizeof(spbuf
),
538 "%-4s E: %4d %2d B: %5d %3d Enemies: %-3d Stars: %-3d Stardate%5d.%1d %9ld",
539 " ", 0, 0, 0, 0, 0, 0, smarts
* 100, 0, 0L);
541 oldeenergy
= oldbenergy
= oldcurscore
=
542 oldstatus
= oldetorp
= oldbtorp
= oldstrs
= oldenemies
= -1;
543 /* force everything to fill in */
544 damage
= olddamage
= 0;
545 for (i
=0; i
<MAXDAMAGE
; i
++)