]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - warp/init.c
401b5acc388e17df436035388226176ae44399cf
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
, xoff
, ypred
, xpred
;
54 static 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;
111 tmptholspec
= (smarts
> 15 && inumstars
< 450 && ! rand_mod(90-sm80
));
113 inumenemies
= rand_mod((smarts
+1)/2) + 1;
114 if (massacre
|| tmptholspec
)
118 inumfriends
= rand_mod(smarts
/8+1);
120 inumpirates
= rand_mod(inumfriends
/2+1);
121 if (inumfriends
+inumenemies
+inumstars
> YSIZE
*XSIZE
-20)
122 inumstars
= YSIZE
*XSIZE
-20 - inumenemies
- inumfriends
;
124 inumfriends
+= inumstars
;
127 if (inumfriends
< 0) {
128 inumenemies
+= inumfriends
;
133 numstars
= inumstars
;
134 inuminhab
= numinhab
= 0;
135 inumroms
= inumthols
= inumgorns
= 0;
136 numapollos
= apolspec
|| massacre
? 1 :
137 ((!numstars
|| rand_mod(2) || smarts
< 10) ? 0 : 1);
138 inumapollos
= apolloflag
= 0;
140 inumcrushes
= numcrushes
=
141 crushspec
||massacre
?1:(rand_mod(2000) < inumstars
);
142 inumenemies
+= inumcrushes
;
143 inumamoebas
= numamoebas
= (amoebaspec
? 1 :
144 !rand_mod(inumcrushes
?3-massacre
:8) ); /* < and & are fun together */
145 inumenemies
+= inumamoebas
;
147 inhabjackpot
= 32767;
148 inumfriends
+= rand_mod(10);
149 inumpirates
+= rand_mod(10);
152 inhabjackpot
= inumpirates
;
153 inhenergy
= 30000-super
*150;
157 inhenergy
+= rand_mod(3500+super
*150);
158 numfriends
= inumfriends
;
159 numpirates
= inumpirates
;
160 numenemies
= inumenemies
;
168 else if (numstars
> 750)
171 dist
= rand_mod(starspec
||smarts
<=5?3:5);
173 real_y
= real_x
= -100;
177 case 0: /* uniform random */
179 if (inumstars
< 700 && !rand_mod(3-(inumstars
<50))) {
180 ydist
= xdist
= 6; /* well, maybe not so random */
184 walksplit
= inumstars
/(exdis(40)+1);
189 case 1: case 2: /* clumped, maybe skewed, maybe superposed */
193 printf("%s\r\n",distname
[ydist
+4*xdist
]);
194 yoff
= rand_mod(YSIZE
);
195 xoff
= rand_mod(XSIZE
);
197 dist
= numstars
/2 + exdis(numstars
/2) - exdis(numstars
/2);
201 case 3: case 4: /* predefined or residual */
206 Sprintf(spbuf
,"smap.%d",
207 (prescene
>=0?prescene
:rand_mod(MAPS
)) );
208 if ((mapfp
= fopen(spbuf
,"r")) != NULL
&&
209 fgets(spbuf
,10,mapfp
) != NULL
) {
210 inumstars
= numstars
= atoi(spbuf
);
211 if (inumenemies
+inumstars
> YSIZE
*XSIZE
-20)
212 inumstars
= numstars
= YSIZE
*XSIZE
-20 - inumenemies
;
213 ydist
= rand_mod(2) + 4; /* flip y axis? */
214 xdist
= rand_mod(2) + 4; /* flip x axis? */
215 yoff
= rand_mod(YSIZE
); /* how much to shift y */
216 xoff
= rand_mod(XSIZE
); /* how much to shift x */
227 for (i
= 1; i
<= numstars
; i
++) {
228 if (dist
&& i
== dist
) { /* flip to another skewing? */
237 printf("%s\r\n",distname
[ydist
+4*xdist
]);
238 yoff
= rand_mod(YSIZE
);
239 xoff
= rand_mod(XSIZE
);
242 do { /* until an open spot found */
245 x
= rand_mod(XSIZE
); /* pick from 0..39, uniform */
247 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 */
255 if (fscanf(mapfp
,"%d %d\n",&ypred
,&xpred
) == EOF
)
260 if (fscanf(mapfp
,"%d %d\n",&ypred
,&xpred
) == EOF
)
265 x
+= rand_mod(3) - 1;
274 y
= (int)((((double)(myrand()-HALFRAND
)) *
275 ((double)(myrand()-HALFRAND
))/RANDRAND
)
276 * 12.0) + yoff
; /* pick from -12..12, clumped */
281 y
= (int)((((double)(myrand()-HALFRAND
)) *
282 ((double)(myrand()-HALFRAND
))/RANDRAND
)
283 * 12.0) + yoff
+ x
*YSIZE
/XSIZE
;
284 /* clumped & skewed */
289 y
= (int)((((double)(myrand()-HALFRAND
)) *
290 ((double)(myrand()-HALFRAND
))/RANDRAND
)
291 * 12.0) + yoff
- x
*YSIZE
/XSIZE
;
292 /* clumped & skewed */
302 y
+= rand_mod(3) - 1;
304 walksplit
= walksplit
;
306 if (!rand_mod(walksplit
)) {
312 while (x
<0) x
+= XSIZE00
;
313 while (y
<0) y
+= YSIZE00
;
316 } while (occupant
[y
][x
]);
318 if (--inhabjackpot
> 0 || e
>= inhenergy
) {
320 if (inhabjackpot
&& e
< 10000)
322 inuminhab
= ++numinhab
;
327 obj
= make_object(Star
,ch
,y
,x
,0,0,e
+rand_mod(super
*100+1),e
/4,&root
);
328 obj
->flags
|= STATIC
;
330 if (inumstars
> 30 && inhabjackpot
<= 0 &&
331 !rand_mod(3 - (inumstars
> 400) - (inhenergy
> 32768)) ) {
335 x
= initx
= obj
->posx
;
336 y
= inity
= obj
->posy
;
337 while (rand_mod(2) && inuminhab
< inumstars
/2) {
338 for (i
=rand_mod(smarts
)*2+20; i
; i
--) {
339 if ((obj
= occupant
[y
][x
]) && obj
->image
== '*') {
341 if (obj
->energy
< 10000)
342 obj
->energy
+= 20000; /* the benefits of civilization */
343 inuminhab
= ++numinhab
;
346 y
= (y
+ rand_mod(3) + YSIZE99
) % YSIZE
;
347 x
= (x
+ rand_mod(3) + XSIZE99
) % XSIZE
;
349 else { /* don't wander too far */
354 x
= initx
= rand_mod(XSIZE
);
355 y
= inity
= rand_mod(YSIZE
);
364 } while (occupant
[y
][x
]);
365 movers
= make_object(Crusher
,'<',y
,x
,0,1,32767L,32768L,&root
);
366 possiblescore
+= 10000;
368 ient
= (numents
!= 0);
373 } while (occupant
[y
][x
]);
375 ent
= make_object(Enterprise
,'E',y
,x
,0,0,e
,e
/2,&root
);
379 ibase
= (numbases
!= 0);
385 } while (occupant
[y
][x
] || lookaround(y
,x
,Star
) * 7 < e
--);
387 base
= make_object(Base
, 'B',y
,x
,0,0,e
,e
/4,&root
);
395 } while (occupant
[y
][x
]);
396 nuke
= make_object(Enemy
,'&',y
,x
,0,0,32767L,
397 (long)entmax
+entmax
+rand_mod(entmax
),&root
);
398 possiblescore
+= 10000;
401 modify_amoeba(y
,x
,2,'~',(int)rand_mod(smarts
<<1));/* just make blob */
403 for (i
=smarts
/10+1; i
; i
--) {
404 nuke
->strategy
= rand_mod(256); /* random direction */
405 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5));
406 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5));
407 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5));
408 modify_amoeba(y
,x
,2,'~',(int)rand_mod(5)); /* extend pseudopod */
416 if (rand_mod(27-sm50
/2) && !romspec
&& !gornspec
)
419 dist
= rand_mod(4) + 1;
420 for (i
= 1+inumcrushes
+inumamoebas
; i
<= numenemies
; i
++) {
424 } while (occupant
[y
][x
]);
425 if (rand_mod(dist
)) {
426 if (!tholspec
&& !tmptholspec
&& rand_mod((inumstars
*3)/sm50
+2))
434 if (romspec
== gornspec
)
440 if (rand_mod(100) < e
) {
449 if (possiblescore
> ENTBOUNDARY
- 10000)
450 e
= (ENTBOUNDARY
- possiblescore
) / 5;
452 e
= 250 + (sm50
-1) * 30 * 20 / numenemies
+1;
454 e
= exdis((int)e
) + e
- exdis((int)e
);
455 obj
= make_object(Enemy
,ch
,y
,x
,0,0,
456 e
+ rand_mod(super
*200+2) + 10000*massacre
,e
/4,&root
);
464 possiblescore
+= e
*3/2;
467 possiblescore
+= e
*2;
470 possiblescore
+= e
*3;
471 obj
->flags
|= CLOAKS
;
479 numgorns
= inumgorns
;
480 for (i
=0; i
<numfriends
; i
++) {
484 } while (occupant
[y
][x
]);
485 e
= 250 + (sm50
-1) * 30 * 20 / numenemies
+1;
487 e
= exdis((int)e
) + e
- exdis((int)e
);
490 static char let
[] = "QWYUISDHJLZVMFFFFFFFFF";
494 } /* grr, venix doesn't like indexing into string */
495 obj
= make_object(Enemy
,ch
,y
,x
,0,0,
496 e
+ rand_mod(super
*200+2),e
/4,&root
);
497 if (numpirates
-- > 0) {
498 obj
->flags
|= PIRATE
;
499 if (smarts
>= 20 && !rand_mod(10-smarts
/10))
500 obj
->flags
|= CLOAKS
;
502 obj
->flags
|= FRIENDLY
;
513 mvaddch(ent
->posy
+1, ent
->posx
*2, ent
->image
);
515 mvaddch(base
->posy
+1, base
->posx
*2, base
->image
);
520 for (curobj
= root
.next
; curobj
!= &root
; curobj
= curobj
->next
) {
521 mvaddch(curobj
->posy
+1, curobj
->posx
*2, curobj
->image
);
525 for (i
=0;i
<2;i
++) for (y
=0;y
<3;y
++) for (x
=0;x
<3;x
++)
533 entmode
= status
= 0;
541 "%-4s E: %4d %2d B: %5d %3d Enemies: %-3d Stars: %-3d Stardate%5d.%1d %9ld",
542 " ", 0, 0, 0, 0, 0, 0, smarts
* 100, 0, 0L);
544 oldeenergy
= oldbenergy
= oldcurscore
=
545 oldstatus
= oldetorp
= oldbtorp
= oldstrs
= oldenemies
= -1;
546 /* force everything to fill in */
547 damage
= olddamage
= 0;
548 for (i
=0; i
<MAXDAMAGE
; i
++)