]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - warp/move.c
5c6123ee9eba3b970892d107ec7c395fe4c8ba8e
1 /* $Header: /cvsroot/src/games/warp/move.c,v 1.1 2020/11/09 23:37:05 kamil Exp $ */
4 /* Revision 1.1 2020/11/09 23:37:05 kamil
5 /* Add Warp Kit, Version 7.0 by Larry Wall
7 /* Warp is a real-time space war game that doesn't get boring very quickly.
8 /* Read warp.doc and the manual page for more information.
10 /* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD
11 /* world via NetBSD. Its remnants were still mentioned in games/Makefile.
13 /* Larry Wall, the original author and the copyright holder, generously
14 /* donated the game and copyright to The NetBSD Foundation, Inc.
16 /* Import the game sources as-is from 4.3BSD-Reno, with the cession
17 /* of the copyright and license to BSD-2-clause NetBSD-style.
19 /* Signed-off-by: Larry Wall <larry@wall.org>
20 /* Signed-off-by: Kamil Rytarowski <kamil@netbsd.org>
22 * Revision 7.0.1.2 86/10/20 14:37:06 lwall
25 * Revision 7.0.1.1 86/10/16 10:52:09 lwall
26 * Added Damage. Fixed random bugs.
28 * Revision 7.0 86/10/08 15:12:40 lwall
29 * Split into separate files. Added amoebas and pirates.
62 y
= (obj
->posy
- sgn(obj
->vely
) + YSIZE00
) % YSIZE
;
63 x
= (obj
->posx
- sgn(obj
->velx
) + XSIZE00
) % XSIZE
;
64 while (occupant
[y
][x
]) {
65 y
= (y
+ rand_mod(3) - 1 + YSIZE00
) % YSIZE
;
66 x
= (x
+ rand_mod(3) - 1 + XSIZE00
) % XSIZE
;
67 if (++count
> 10000) { /* if universe full, get out of it fast */
69 if (ent
) unmake_object(ent
);
70 if (base
) unmake_object(base
);
80 if (numamoebas
&& obj
->image
== ' ')
81 mvaddc(y
+1, x
*2, amb
[y
][x
]);
83 mvaddc(y
+1, x
*2, obj
->image
);
95 for (curobj
= movers
; curobj
!= &root
; curobj
= curobj
->next
) {
98 if (curobj
== occupant
[y
][x
]) {
101 else if (curobj
->type
!= Torp
&& curobj
->type
!= Web
) {
106 for (curobj
= movers
; curobj
!= &root
; curobj
= thenext
) {
107 thenext
= curobj
->next
;
108 if (curobj
->vely
|| curobj
->velx
) {
111 if (curobj
->image
!= ' ' &&
112 (!(temp
=occupant
[y
][x
]) || temp
->image
==' ') ) {
113 move(y
+1, x
*2, numamoebas
? amb
[y
][x
] : ' ');
115 y
= (y
+ curobj
->vely
+ YSIZE00
) % YSIZE
;
116 x
= (x
+ curobj
->velx
+ XSIZE00
) % XSIZE
;
117 if (!(temp
=occupant
[y
][x
]) || temp
->type
!= Star
||
118 curobj
->type
!= Torp
|| curobj
->image
== '+' ||
119 curobj
->image
== 'x') {
124 if (curobj
->image
== '0') {
125 curobj
->vely
= rand_mod(3)-1;
126 curobj
->velx
= rand_mod(3)-1;
129 curobj
->vely
= curobj
->velx
= 0;
134 else { /* not moving */
137 if (curobj
->type
== Torp
||
138 curobj
->type
== Star
||
139 curobj
->type
== Web
) {
140 curobj
->flags
|= STATIC
;
141 curobj
->next
->prev
= curobj
->prev
;
142 curobj
->prev
->next
= curobj
->next
;
143 curobj
->prev
= movers
->prev
;
144 curobj
->next
= movers
;
145 movers
->prev
->next
= curobj
;
146 movers
->prev
= curobj
;
149 if (temp
= occupant
[y
][x
]) { /* already occupied? */
150 if (!temp
->contend
) {
151 if (temp
->type
== Torp
) {
152 if (temp
->image
== '+')
154 else if (temp
->image
== 'o' && (base
||ent
))
155 blast
[y
][x
] += 500+super
*20;
156 else if (temp
->image
== 'O' && (base
||ent
))
157 blast
[y
][x
] += 5000+super
*100;
163 curobj
->contend
= temp
;
164 occupant
[y
][x
] = curobj
;
165 switch (curobj
->type
) {
167 if (numamoebas
&& curobj
== nuke
&& temp
->image
== '+')
168 blast
[y
][x
] += 80000;
169 else if (temp
->type
== Enemy
)
176 blast
[y
][x
] += 100000;
181 if (curobj
->image
== '+')
182 blast
[y
][x
] += (temp
==nuke
? 80000 : 1250);
183 else if (curobj
->image
== 'o')
184 blast
[y
][x
] += 500+super
*20;
185 else if (curobj
->image
== 'O')
186 blast
[y
][x
] += 5000+super
*100;
193 if (temp
->type
== Star
) {
196 if (!damflag
[NOSHIELDS
])
198 if (damflag
[NOSHIELDS
] < 100)
199 damflag
[NOSHIELDS
] += rand_mod(smarts
)/5+2;
205 blast
[y
][x
] += rand_mod(751)+1;
210 occupant
[y
][x
] = curobj
;
211 if (curobj
->image
!= ' ' &&
212 (curobj
->velx
|| curobj
->vely
||
213 curobj
->type
== Torp
|| curobj
->type
== Web
) ) {
214 mvaddc(y
+1, x
*2, curobj
->image
);
216 if (curobj
->type
== Crusher
&& curobj
->velx
) {
217 blast
[y
][x
] += 100000;
225 Reg7
int minxblast
= -1;
226 Reg8
int maxxblast
= -2;
229 blasted
= numamoebas
;
230 for (x
=0; x
<XSIZE
; x
++) {
238 for (y
=0; y
<YSIZE
; y
++) {
241 for (x
=minxblast
; x
<=maxxblast
; x
++) {
242 tmpblast
= blast
[y
][x
];
243 if (numamoebas
&& amb
[y
][x
] == '~') {
244 if (temp
= occupant
[y
][x
]) {
245 if (temp
->image
== '&')
247 else if (temp
->type
== Web
)
250 tmpblast
+= 50 + temp
->energy
/100;
251 if (tmpblast
> 250 && !rand_mod(5+(inumstars
>>4)))
252 modify_amoeba(y
,x
,1,'~',5);
258 Reg6 OBJECT
*biggie
= 0;
261 temp
= occupant
[y
][x
];
263 if (numamoebas
&& tmpblast
< -1000000 &&
264 amb
[y
][x
] == '~' && temp
!= nuke
) {
273 if ((!numamoebas
|| amb
[y
][x
]==' ') &&
277 temp
= curobj
->contend
,curobj
->contend
= 0){
279 switch (curobj
->type
) {
281 long tmp
= curobj
->energy
;
283 if (ent
->energy
>500 || apolloflag
& 1)
284 curobj
->energy
-= tmpblast
/
287 : (5+abs(ent
->velx
)+abs(ent
->vely
))
288 / ((damflag
[NOSHIELDS
]>>3)+1)+1);
290 curobj
->energy
-= tmpblast
;
291 if (rand_mod(1 + tmp
- curobj
->energy
) > 100
292 || ent
->energy
< (entmax
>>1)) {
294 (damage
<= smarts
/10 &&
295 !rand_mod(6-smarts
/20-massacre
) )) {
296 tmp
= rand_mod(MAXDAMAGE
);
298 if (damflag
[tmp
] < 60)
299 damflag
[tmp
] += rand_mod(60);
303 rand_mod(smarts
+10)+2;
311 if (base
->energy
> 1000 || apolloflag
& 2)
312 curobj
->energy
-= tmpblast
/
313 ((apolloflag
& 2)?20:5);
315 curobj
->energy
-= tmpblast
;
318 if (tmpblast
> 132767)
319 curobj
->energy
-= (tmpblast
- 100000);
320 else if (tmpblast
>= 100000) {
321 curobj
->energy
+= (tmpblast
- 100000);
322 if (curobj
->energy
> 32767)
323 curobj
->energy
= 32767;
325 else /* vulnerable while feeding */
326 curobj
->energy
-= tmpblast
;
329 curobj
->energy
-= tmpblast
*10/enemshields
;
332 curobj
->energy
-= tmpblast
;
335 if (curobj
->energy
< 0) { /* killed it? */
336 switch (curobj
->image
) {
339 make_blast(y
,x
,8192L,1);
340 numapollos
= apolloflag
= 0;
346 case 'E': case 'e': case 'C': case 'c':
367 for (i
= 0; i
< YSIZE
; i
++)
369 for (i
= 0; i
< XSIZE
; i
++)
371 numamoebas
= 0; /* ignore amb[][] now */
372 for (yyy
= 0; yyy
< YSIZE
; yyy
++) {
373 for (xxx
= 0; xxx
< XSIZE
; xxx
++) {
374 if (amb
[yyy
][xxx
] == '~' &&
375 !occupant
[yyy
][xxx
]) {
376 mvaddch(yyy
+1,xxx
*2,' ');
382 if (curobj
== enemies
)
383 enemies
= curobj
->next
;
387 case '<': case '>': {
393 if (curobj
== movers
)
394 movers
= curobj
->next
;
395 if (curobj
== enemies
)
396 enemies
= curobj
->next
;
400 make_blast(y
,(x
+XSIZE00
)%XSIZE
,10000L,0);
401 if (curobj
->image
== '<') {
402 for (i
=XSIZE00
; i
<=XSIZE01
; i
++)
403 make_blast(y
,(x
+i
)%XSIZE
,
405 for (i
=XSIZE00
; i
<=XSIZE02
; i
++)
406 make_blast(y
,(x
+i
)%XSIZE
,
408 make_blast(y
,(x
+XSIZE03
)%XSIZE
,
410 for (i
=XSIZE00
; i
<=XSIZE08
; i
++)
411 make_blast(y
,(x
+i
)%XSIZE
,
415 for (i
=XSIZE00
; i
>=XSIZE99
; i
--)
416 make_blast(y
,(x
+i
)%XSIZE
,
418 for (i
=XSIZE00
; i
>=XSIZE98
; i
--)
419 make_blast(y
,(x
+i
)%XSIZE
,
421 make_blast(y
,(x
+XSIZE97
)%XSIZE
,
423 for (i
=XSIZE00
; i
>=XSIZE92
; i
--)
424 make_blast(y
,(x
+i
)%XSIZE
,
431 curscore
+= curobj
->mass
;
432 if (curobj
== enemies
)
433 enemies
= curobj
->next
;
438 curscore
+= curobj
->mass
*3/2;
439 if (curobj
== enemies
)
440 enemies
= curobj
->next
;
443 case 'R': case ' ': case 'P':
445 if (curobj
->flags
& PIRATE
)
446 curscore
+= curobj
->mass
;
448 curscore
+= curobj
->mass
*3;
449 if (curobj
== enemies
)
450 enemies
= curobj
->next
;
458 curscore
+= curobj
->mass
/2;
460 curscore
+= curobj
->mass
*2;
461 if (curobj
== enemies
)
462 enemies
= curobj
->next
;
466 for (xxx
= -1; xxx
<=1; xxx
++)
467 for (yyy
= -1; yyy
<=1; yyy
++)
468 if (rand_mod(2+massacre
))
481 case '|': case '-': case '/': case '\\':
483 make_blast(y
,x
,curobj
->mass
,1);
515 if (curobj
== enemies
)
516 enemies
= curobj
->next
;
518 case 'Q': case 'W': case 'Y': case 'U':
519 case 'I': case 'S': case 'D': case 'H':
520 case 'J': case 'L': case 'Z': case 'V':
523 if (curobj
== enemies
)
524 enemies
= curobj
->next
;
525 if (inumfriends
< 10)
528 madfriends
+= 10000/inumfriends
;
531 if (tmpblast
< 100000)
532 make_blast(y
,x
,curobj
->mass
,1);
533 unmake_object(curobj
);
535 else { /* didn't kill anything */
539 if (biggie
->mass
> curobj
->mass
)
549 occupant
[y
][x
] = biggie
;
550 if (numamoebas
&& biggie
->image
== ' ')
551 mvaddch(y
+1,x
*2, amb
[y
][x
]);
553 mvaddch(y
+1,x
*2, biggie
->image
);
557 mvaddch(y
+1, x
*2, numamoebas
? amb
[y
][x
] : ' ');
566 if (numcrushes
&& movers
->type
== Crusher
)
573 curobj
->energy
+= 25*lookaround(curobj
->posy
,curobj
->posx
,Star
);
574 if (curobj
->energy
> basemax
)
575 curobj
->energy
= basemax
;
576 if (curobj
->energy
>= 1000)
580 if (ch
!= curobj
->image
) {
581 setimage(curobj
, ch
);
591 if (base
&& !cloaking
&& !curobj
->velx
&& !curobj
->vely
&&
592 lookfor(curobj
->posy
,curobj
->posx
,Base
)) {
598 tmp
= (int) (base
->energy
- 1000 < entmax
- curobj
->energy
?
599 base
->energy
- 1000 : entmax
- curobj
->energy
);
603 curobj
->energy
+= tmp
;
605 tmp
= (btorp
< 50 - etorp
?
610 tmp
= rand_mod(MAXDAMAGE
);
611 if (damflag
[tmp
] > 5) {
612 damflag
[tmp
] = rand_mod(5)+1;
616 if (curobj
->energy
>= 500 && (!damage
|| !damflag
[NOSHIELDS
]))
617 ch
= cloaked
?'C':'E';
619 ch
= cloaked
?'c':'e';
620 if (ch
!= curobj
->image
) {
621 setimage(curobj
, ch
);
627 lookaround(y
, x
, what
)
637 if ((obj
=occupant
[y
][xp
=(x
+XSIZE01
)%XSIZE
])&&obj
->type
== what
) /* 0, 1 */
639 if ((obj
=occupant
[y
][xm
=(x
+XSIZE99
)%XSIZE
])&&obj
->type
== what
) /* 0, -1 */
641 if ((obj
=occupant
[y
=(y
+YSIZE99
)%YSIZE
][xp
])&&obj
->type
== what
) /* -1, 1 */
643 if ((obj
=occupant
[y
][x
])&&obj
->type
== what
) /* -1, 0 */
645 if ((obj
=occupant
[y
][xm
])&&obj
->type
== what
) /* -1, -1 */
647 if ((obj
=occupant
[y
=(y
+2)%YSIZE
][xp
])&&obj
->type
== what
) /* 1, 1 */
649 if ((obj
=occupant
[y
][x
])&&obj
->type
== what
) /* 1, 0 */
651 if ((obj
=occupant
[y
][xm
])&&obj
->type
== what
) /* 1, -1 */
666 if ((obj
=occupant
[y
][xp
=(x
+XSIZE01
)%XSIZE
])&&obj
->type
== what
||/* 0, 1 */
667 (obj
=occupant
[y
][xm
=(x
+XSIZE99
)%XSIZE
])&&obj
->type
== what
||/* 0, -1 */
668 (obj
=occupant
[y
=(y
+YSIZE99
)%YSIZE
][xp
])&&obj
->type
== what
||/* -1, 1 */
669 (obj
=occupant
[y
][x
])&&obj
->type
== what
||/* -1, 0 */
670 (obj
=occupant
[y
][xm
])&&obj
->type
== what
||/* -1,-1 */
671 (obj
=occupant
[y
=(y
+2)%YSIZE
][xp
])&&obj
->type
== what
||/* 1, 1 */
672 (obj
=occupant
[y
][x
])&&obj
->type
== what
||/* 1, 0 */
673 (obj
=occupant
[y
][xm
])&&obj
->type
== what
) /* 1, -1 */
688 if ((obj
=occupant
[y
][xp
=(x
+XSIZE01
)%XSIZE
])&&obj
->image
==what
||/* 0, 1 */
689 (obj
=occupant
[y
][xm
=(x
+XSIZE99
)%XSIZE
])&&obj
->image
==what
||/* 0, -1 */
690 (obj
=occupant
[y
=(y
+YSIZE99
)%YSIZE
][xp
])&&obj
->image
==what
||/* -1, 1 */
691 (obj
=occupant
[y
][x
])&&obj
->image
==what
||/* -1, 0 */
692 (obj
=occupant
[y
][xm
])&&obj
->image
==what
||/* -1,-1 */
693 (obj
=occupant
[y
=(y
+2)%YSIZE
][xp
])&&obj
->image
==what
||/* 1, 1 */
694 (obj
=occupant
[y
][x
])&&obj
->image
==what
||/* 1, 0 */
695 (obj
=occupant
[y
][xm
])&&obj
->image
==what
) /* 1, -1 */
697 return Null(OBJECT
*);