* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
* Copy permission is hereby granted provided that this notice is
* retained on all partial or complete copies.
* For more info on this and all of my stuff, mail edjames@berkeley.edu.
static char sccsid
[] = "@(#)update.c 5.5 (Berkeley) 10/30/90";
int i
, dir_diff
, mask
, unclean
;
mask
= sigblock(sigmask(SIGINT
));
/* put some planes in the air */
for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
) {
if (pp
->new_altitude
> 0) {
/* do altitude change and basic movement */
for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
/* type 0 only move every other turn */
if (pp
->plane_type
== 0 && clck
& 1)
loser(pp
, "ran out of fuel.");
pp
->altitude
+= SGN(pp
->new_altitude
- pp
->altitude
);
dir_diff
= pp
->new_dir
- pp
->dir
;
* Allow for circle commands
if (pp
->new_dir
>= 0 && pp
->new_dir
< MAXDIR
) {
else if (dir_diff
< -(MAXDIR
/2))
pp
->xpos
+= displacement
[pp
->dir
].dx
;
pp
->ypos
+= displacement
[pp
->dir
].dy
;
if (pp
->delayd
&& pp
->xpos
== sp
->beacon
[pp
->delayd_no
].x
&&
pp
->ypos
== sp
->beacon
[pp
->delayd_no
].y
) {
if (pp
->status
== S_UNMARKED
)
if (pp
->xpos
== sp
->airport
[pp
->dest_no
].x
&&
pp
->ypos
== sp
->airport
[pp
->dest_no
].y
&&
if (pp
->dir
!= sp
->airport
[pp
->dest_no
].dir
)
loser(pp
, "landed in the wrong direction.");
if (pp
->xpos
== sp
->exit
[pp
->dest_no
].x
&&
pp
->ypos
== sp
->exit
[pp
->dest_no
].y
) {
loser(pp
, "exited at the wrong altitude.");
loser(pp
, "has a bizarre destination, get help!");
/* "this is impossible" */
loser(pp
, "exceded flight ceiling.");
for (i
= 0; i
< sp
->num_airports
; i
++)
if (pp
->xpos
== sp
->airport
[i
].x
&&
pp
->ypos
== sp
->airport
[i
].y
) {
if (pp
->dest_type
== T_AIRPORT
)
"landed at the wrong airport.");
"landed instead of exited.");
loser(pp
, "crashed on the ground.");
if (pp
->xpos
< 1 || pp
->xpos
>= sp
->width
- 1 ||
pp
->ypos
< 1 || pp
->ypos
>= sp
->height
- 1) {
for (i
= 0; i
< sp
->num_exits
; i
++)
if (pp
->xpos
== sp
->exit
[i
].x
&&
pp
->ypos
== sp
->exit
[i
].y
) {
if (pp
->dest_type
== T_EXIT
)
"exited via the wrong exit.");
"exited instead of landed.");
loser(pp
, "illegally left the flight arena.");
* Traverse the list once, deleting the planes that are gone.
for (pp
= air
.head
; pp
!= NULL
; pp
= p2
) {
if (pp
->status
== S_GONE
) {
for (p1
= air
.head
; p1
!= NULL
; p1
= p1
->next
)
for (p2
= p1
->next
; p2
!= NULL
; p2
= p2
->next
)
if (too_close(p1
, p2
, 1)) {
(void)sprintf(buf
, "collided with plane '%c'.",
* Check every other update. Actually, only add on even updates.
* Otherwise, prop jobs show up *on* entrance. Remember that
* we don't update props on odd updates.
if ((rand() % sp
->newplane_time
) == 0)
static char buf
[50], *bp
, *comm_start
;
(void)sprintf(bp
, "%c%d%c%c%d: ", name(pp
), pp
->altitude
,
(pp
->fuel
< LOWFUEL
) ? '*' : ' ',
(pp
->dest_type
== T_AIRPORT
) ? 'A' : 'E', pp
->dest_no
);
comm_start
= bp
= index(buf
, '\0');
(void)sprintf(bp
, "Holding @ A%d", pp
->orig_no
);
else if (pp
->new_dir
>= MAXDIR
|| pp
->new_dir
< 0)
else if (pp
->new_dir
!= pp
->dir
)
(void)sprintf(bp
, "%d", dir_deg(pp
->new_dir
));
(void)sprintf(bp
, " @ B%d", pp
->delayd_no
);
if (*comm_start
== '\0' &&
(pp
->status
== S_UNMARKED
|| pp
->status
== S_IGNORED
))
return ('A' + p
->plane_no
);
return ('a' + p
->plane_no
);
if (l
< 'a' && l
> 'z' && l
< 'A' && l
> 'Z')
else if (l
>= 'a' && l
<= 'z')
static int last_plane
= -1;
int found
, start_plane
= last_plane
;
for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
)
if (pp
->plane_no
== last_plane
) {
for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
)
if (pp
->plane_no
== last_plane
) {
} while (found
&& last_plane
!= start_plane
);
if (last_plane
== start_plane
)
int i
, num_starts
, close
, rnd
, rnd2
, pnum
;
p
.plane_type
= random() % 2;
num_starts
= sp
->num_exits
+ sp
->num_airports
;
rnd
= random() % num_starts
;
if (rnd
< sp
->num_exits
) {
p
.dest_no
= rnd
- sp
->num_exits
;
/* loop until we get a plane not near another */
for (i
= 0; i
< num_starts
; i
++) {
/* loop till we get a different start point */
while ((rnd2
= random() % num_starts
) == rnd
)
if (rnd2
< sp
->num_exits
) {
p
.xpos
= sp
->exit
[rnd2
].x
;
p
.ypos
= sp
->exit
[rnd2
].y
;
p
.new_dir
= p
.dir
= sp
->exit
[rnd2
].dir
;
p
.altitude
= p
.new_altitude
= 7;
for (p1
= air
.head
; p1
!= NULL
; p1
= p1
->next
)
if (too_close(p1
, &p
, 4)) {
p
.orig_no
= rnd2
- sp
->num_exits
;
p
.xpos
= sp
->airport
[p
.orig_no
].x
;
p
.ypos
= sp
->airport
[p
.orig_no
].y
;
p
.new_dir
= p
.dir
= sp
->airport
[p
.orig_no
].dir
;
p
.altitude
= p
.new_altitude
= 0;
p
.fuel
= sp
->width
+ sp
->height
;
bcopy(&p
, pp
, sizeof (p
));
if (pp
->orig_type
== T_AIRPORT
)
for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
)
for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
)
if (ABS(p1
->altitude
- p2
->altitude
) <= dist
&&
ABS(p1
->xpos
- p2
->xpos
) <= dist
&& ABS(p1
->ypos
- p2
->ypos
) <= dist
)