]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - warp/move.c
1 /* Header: move.c,v 7.0.1.2 86/10/20 14:37:06 lwall Exp */
4 * Revision 7.0.1.2 86/10/20 14:37:06 lwall
7 * Revision 7.0.1.1 86/10/16 10:52:09 lwall
8 * Added Damage. Fixed random bugs.
10 * Revision 7.0 86/10/08 15:12:40 lwall
11 * Split into separate files. Added amoebas and pirates.
43 y
= (obj
->posy
- sgn(obj
->vely
) + YSIZE00
) % YSIZE
;
44 x
= (obj
->posx
- sgn(obj
->velx
) + XSIZE00
) % XSIZE
;
45 while (occupant
[y
][x
]) {
46 y
= (y
+ rand_mod(3) - 1 + YSIZE00
) % YSIZE
;
47 x
= (x
+ rand_mod(3) - 1 + XSIZE00
) % XSIZE
;
48 if (++count
> 10000) { /* if universe full, get out of it fast */
50 if (ent
) unmake_object(ent
);
51 if (base
) unmake_object(base
);
61 if (numamoebas
&& obj
->image
== ' ')
62 mvaddc(y
+1, x
*2, amb
[y
][x
]);
64 mvaddc(y
+1, x
*2, obj
->image
);
76 for (curobj
= movers
; curobj
!= &root
; curobj
= curobj
->next
) {
79 if (curobj
== occupant
[y
][x
]) {
82 else if (curobj
->type
!= Torp
&& curobj
->type
!= Web
) {
87 for (curobj
= movers
; curobj
!= &root
; curobj
= thenext
) {
88 thenext
= curobj
->next
;
89 if (curobj
->vely
|| curobj
->velx
) {
92 if (curobj
->image
!= ' ' &&
93 (!(temp
=occupant
[y
][x
]) || temp
->image
==' ') ) {
94 move(y
+1, x
*2, numamoebas
? amb
[y
][x
] : ' ');
96 y
= (y
+ curobj
->vely
+ YSIZE00
) % YSIZE
;
97 x
= (x
+ curobj
->velx
+ XSIZE00
) % XSIZE
;
98 if (!(temp
=occupant
[y
][x
]) || temp
->type
!= Star
||
99 curobj
->type
!= Torp
|| curobj
->image
== '+' ||
100 curobj
->image
== 'x') {
105 if (curobj
->image
== '0') {
106 curobj
->vely
= rand_mod(3)-1;
107 curobj
->velx
= rand_mod(3)-1;
110 curobj
->vely
= curobj
->velx
= 0;
115 else { /* not moving */
118 if (curobj
->type
== Torp
||
119 curobj
->type
== Star
||
120 curobj
->type
== Web
) {
121 curobj
->flags
|= STATIC
;
122 curobj
->next
->prev
= curobj
->prev
;
123 curobj
->prev
->next
= curobj
->next
;
124 curobj
->prev
= movers
->prev
;
125 curobj
->next
= movers
;
126 movers
->prev
->next
= curobj
;
127 movers
->prev
= curobj
;
130 if ((temp
= occupant
[y
][x
]) != NULL
) { /* already occupied? */
131 if (!temp
->contend
) {
132 if (temp
->type
== Torp
) {
133 if (temp
->image
== '+')
135 else if (temp
->image
== 'o' && (base
||ent
))
136 blast
[y
][x
] += 500+super
*20;
137 else if (temp
->image
== 'O' && (base
||ent
))
138 blast
[y
][x
] += 5000+super
*100;
144 curobj
->contend
= temp
;
145 occupant
[y
][x
] = curobj
;
146 switch (curobj
->type
) {
148 if (numamoebas
&& curobj
== nuke
&& temp
->image
== '+')
149 blast
[y
][x
] += 80000;
150 else if (temp
->type
== Enemy
)
157 blast
[y
][x
] += 100000;
162 if (curobj
->image
== '+')
163 blast
[y
][x
] += (temp
==nuke
? 80000 : 1250);
164 else if (curobj
->image
== 'o')
165 blast
[y
][x
] += 500+super
*20;
166 else if (curobj
->image
== 'O')
167 blast
[y
][x
] += 5000+super
*100;
174 if (temp
->type
== Star
) {
177 if (!damflag
[NOSHIELDS
])
179 if (damflag
[NOSHIELDS
] < 100)
180 damflag
[NOSHIELDS
] += rand_mod(smarts
)/5+2;
186 blast
[y
][x
] += rand_mod(751)+1;
191 occupant
[y
][x
] = curobj
;
192 if (curobj
->image
!= ' ' &&
193 (curobj
->velx
|| curobj
->vely
||
194 curobj
->type
== Torp
|| curobj
->type
== Web
) ) {
195 mvaddc(y
+1, x
*2, curobj
->image
);
197 if (curobj
->type
== Crusher
&& curobj
->velx
) {
198 blast
[y
][x
] += 100000;
210 blasted
= numamoebas
;
211 for (x
=0; x
<XSIZE
; x
++) {
219 for (y
=0; y
<YSIZE
; y
++) {
222 for (x
=minxblast
; x
<=maxxblast
; x
++) {
223 tmpblast
= blast
[y
][x
];
224 if (numamoebas
&& amb
[y
][x
] == '~') {
225 if ((temp
= occupant
[y
][x
]) != NULL
) {
226 if (temp
->image
== '&')
228 else if (temp
->type
== Web
)
231 tmpblast
+= 50 + temp
->energy
/100;
232 if (tmpblast
> 250 && !rand_mod(5+(inumstars
>>4)))
233 modify_amoeba(y
,x
,1,'~',5);
242 temp
= occupant
[y
][x
];
244 if (numamoebas
&& tmpblast
< -1000000 &&
245 amb
[y
][x
] == '~' && temp
!= nuke
) {
254 if ((!numamoebas
|| amb
[y
][x
]==' ') &&
258 temp
= curobj
->contend
,curobj
->contend
= 0){
260 switch (curobj
->type
) {
262 long tmp
= curobj
->energy
;
264 if (ent
->energy
>500 || apolloflag
& 1)
265 curobj
->energy
-= tmpblast
/
268 : (5+abs(ent
->velx
)+abs(ent
->vely
))
269 / ((damflag
[NOSHIELDS
]>>3)+1)+1);
271 curobj
->energy
-= tmpblast
;
272 if (rand_mod(1 + tmp
- curobj
->energy
) > 100
273 || ent
->energy
< (entmax
>>1)) {
275 (damage
<= smarts
/10 &&
276 !rand_mod(6-smarts
/20-massacre
) )) {
277 tmp
= rand_mod(MAXDAMAGE
);
279 if (damflag
[tmp
] < 60)
280 damflag
[tmp
] += rand_mod(60);
284 rand_mod(smarts
+10)+2;
292 if (base
->energy
> 1000 || apolloflag
& 2)
293 curobj
->energy
-= tmpblast
/
294 ((apolloflag
& 2)?20:5);
296 curobj
->energy
-= tmpblast
;
299 if (tmpblast
> 132767)
300 curobj
->energy
-= (tmpblast
- 100000);
301 else if (tmpblast
>= 100000) {
302 curobj
->energy
+= (tmpblast
- 100000);
303 if (curobj
->energy
> 32767)
304 curobj
->energy
= 32767;
306 else /* vulnerable while feeding */
307 curobj
->energy
-= tmpblast
;
310 curobj
->energy
-= tmpblast
*10/enemshields
;
313 curobj
->energy
-= tmpblast
;
316 if (curobj
->energy
< 0) { /* killed it? */
317 switch (curobj
->image
) {
320 make_blast(y
,x
,8192L,1);
321 numapollos
= apolloflag
= 0;
327 case 'E': case 'e': case 'C': case 'c':
348 for (i
= 0; i
< YSIZE
; i
++)
350 for (i
= 0; i
< XSIZE
; i
++)
352 numamoebas
= 0; /* ignore amb[][] now */
353 for (yyy
= 0; yyy
< YSIZE
; yyy
++) {
354 for (xxx
= 0; xxx
< XSIZE
; xxx
++) {
355 if (amb
[yyy
][xxx
] == '~' &&
356 !occupant
[yyy
][xxx
]) {
357 mvaddch(yyy
+1,xxx
*2,' ');
363 if (curobj
== enemies
)
364 enemies
= curobj
->next
;
368 case '<': case '>': {
374 if (curobj
== movers
)
375 movers
= curobj
->next
;
376 if (curobj
== enemies
)
377 enemies
= curobj
->next
;
381 make_blast(y
,(x
+XSIZE00
)%XSIZE
,10000L,0);
382 if (curobj
->image
== '<') {
383 for (i
=XSIZE00
; i
<=XSIZE01
; i
++)
384 make_blast(y
,(x
+i
)%XSIZE
,
386 for (i
=XSIZE00
; i
<=XSIZE02
; i
++)
387 make_blast(y
,(x
+i
)%XSIZE
,
389 make_blast(y
,(x
+XSIZE03
)%XSIZE
,
391 for (i
=XSIZE00
; i
<=XSIZE08
; i
++)
392 make_blast(y
,(x
+i
)%XSIZE
,
396 for (i
=XSIZE00
; i
>=XSIZE99
; i
--)
397 make_blast(y
,(x
+i
)%XSIZE
,
399 for (i
=XSIZE00
; i
>=XSIZE98
; i
--)
400 make_blast(y
,(x
+i
)%XSIZE
,
402 make_blast(y
,(x
+XSIZE97
)%XSIZE
,
404 for (i
=XSIZE00
; i
>=XSIZE92
; i
--)
405 make_blast(y
,(x
+i
)%XSIZE
,
412 curscore
+= curobj
->mass
;
413 if (curobj
== enemies
)
414 enemies
= curobj
->next
;
419 curscore
+= curobj
->mass
*3/2;
420 if (curobj
== enemies
)
421 enemies
= curobj
->next
;
424 case 'R': case ' ': case 'P':
426 if (curobj
->flags
& PIRATE
)
427 curscore
+= curobj
->mass
;
429 curscore
+= curobj
->mass
*3;
430 if (curobj
== enemies
)
431 enemies
= curobj
->next
;
439 curscore
+= curobj
->mass
/2;
441 curscore
+= curobj
->mass
*2;
442 if (curobj
== enemies
)
443 enemies
= curobj
->next
;
447 for (xxx
= -1; xxx
<=1; xxx
++)
448 for (yyy
= -1; yyy
<=1; yyy
++)
449 if (rand_mod(2+massacre
))
462 case '|': case '-': case '/': case '\\':
464 make_blast(y
,x
,curobj
->mass
,1);
496 if (curobj
== enemies
)
497 enemies
= curobj
->next
;
499 case 'Q': case 'W': case 'Y': case 'U':
500 case 'I': case 'S': case 'D': case 'H':
501 case 'J': case 'L': case 'Z': case 'V':
504 if (curobj
== enemies
)
505 enemies
= curobj
->next
;
506 if (inumfriends
< 10)
509 madfriends
+= 10000/inumfriends
;
512 if (tmpblast
< 100000)
513 make_blast(y
,x
,curobj
->mass
,1);
514 unmake_object(curobj
);
516 else { /* didn't kill anything */
520 if (biggie
->mass
> curobj
->mass
)
530 occupant
[y
][x
] = biggie
;
531 if (numamoebas
&& biggie
->image
== ' ')
532 mvaddch(y
+1,x
*2, amb
[y
][x
]);
534 mvaddch(y
+1,x
*2, biggie
->image
);
538 mvaddch(y
+1, x
*2, numamoebas
? amb
[y
][x
] : ' ');
547 if (numcrushes
&& movers
->type
== Crusher
)
549 if ((curobj
= base
) != NULL
) {
554 curobj
->energy
+= 25*lookaround(curobj
->posy
,curobj
->posx
,Star
);
555 if (curobj
->energy
> basemax
)
556 curobj
->energy
= basemax
;
557 if (curobj
->energy
>= 1000)
561 if (ch
!= curobj
->image
) {
562 setimage(curobj
, ch
);
565 if ((curobj
= ent
) != NULL
) {
572 if (base
&& !cloaking
&& !curobj
->velx
&& !curobj
->vely
&&
573 lookfor(curobj
->posy
,curobj
->posx
,Base
)) {
579 tmp
= (int) (base
->energy
- 1000 < entmax
- curobj
->energy
?
580 base
->energy
- 1000 : entmax
- curobj
->energy
);
584 curobj
->energy
+= tmp
;
586 tmp
= (btorp
< 50 - etorp
?
591 tmp
= rand_mod(MAXDAMAGE
);
592 if (damflag
[tmp
] > 5) {
593 damflag
[tmp
] = rand_mod(5)+1;
597 if (curobj
->energy
>= 500 && (!damage
|| !damflag
[NOSHIELDS
]))
598 ch
= cloaked
?'C':'E';
600 ch
= cloaked
?'c':'e';
601 if (ch
!= curobj
->image
) {
602 setimage(curobj
, ch
);
608 lookaround(int y
, int x
, char what
)
615 if ((obj
=occupant
[y
][xp
=(x
+XSIZE01
)%XSIZE
])&&obj
->type
== what
) /* 0, 1 */
617 if ((obj
=occupant
[y
][xm
=(x
+XSIZE99
)%XSIZE
])&&obj
->type
== what
) /* 0, -1 */
619 if ((obj
=occupant
[y
=(y
+YSIZE99
)%YSIZE
][xp
])&&obj
->type
== what
) /* -1, 1 */
621 if ((obj
=occupant
[y
][x
])&&obj
->type
== what
) /* -1, 0 */
623 if ((obj
=occupant
[y
][xm
])&&obj
->type
== what
) /* -1, -1 */
625 if ((obj
=occupant
[y
=(y
+2)%YSIZE
][xp
])&&obj
->type
== what
) /* 1, 1 */
627 if ((obj
=occupant
[y
][x
])&&obj
->type
== what
) /* 1, 0 */
629 if ((obj
=occupant
[y
][xm
])&&obj
->type
== what
) /* 1, -1 */
635 lookfor(int y
, int x
, char what
)
641 if (((obj
=occupant
[y
][xp
=(x
+XSIZE01
)%XSIZE
])&&obj
->type
== what
)||/* 0, 1 */
642 ((obj
=occupant
[y
][xm
=(x
+XSIZE99
)%XSIZE
])&&obj
->type
== what
)||/* 0, -1 */
643 ((obj
=occupant
[y
=(y
+YSIZE99
)%YSIZE
][xp
])&&obj
->type
== what
)||/* -1, 1 */
644 ((obj
=occupant
[y
][x
])&&obj
->type
== what
) ||/* -1, 0 */
645 ((obj
=occupant
[y
][xm
])&&obj
->type
== what
) ||/* -1,-1 */
646 ((obj
=occupant
[y
=(y
+2)%YSIZE
][xp
])&&obj
->type
== what
) ||/* 1, 1 */
647 ((obj
=occupant
[y
][x
])&&obj
->type
== what
) ||/* 1, 0 */
648 ((obj
=occupant
[y
][xm
])&&obj
->type
== what
)) /* 1, -1 */
654 lookimg(int y
, int x
, char what
)
660 if (((obj
=occupant
[y
][xp
=(x
+XSIZE01
)%XSIZE
])&&obj
->image
==what
)||/* 0, 1 */
661 ((obj
=occupant
[y
][xm
=(x
+XSIZE99
)%XSIZE
])&&obj
->image
==what
)||/* 0, -1 */
662 ((obj
=occupant
[y
=(y
+YSIZE99
)%YSIZE
][xp
])&&obj
->image
==what
)||/* -1, 1 */
663 ((obj
=occupant
[y
][x
])&&obj
->image
==what
) ||/* -1, 0 */
664 ((obj
=occupant
[y
][xm
])&&obj
->image
==what
) ||/* -1,-1 */
665 ((obj
=occupant
[y
=(y
+2)%YSIZE
][xp
])&&obj
->image
==what
) ||/* 1, 1 */
666 ((obj
=occupant
[y
][x
])&&obj
->image
==what
) ||/* 1, 0 */
667 ((obj
=occupant
[y
][xm
])&&obj
->image
==what
)) /* 1, -1 */