Exemplo n.º 1
0
/*
 * Function:    Fly
 *
 * Function called directly after TakeOff is completed to move the drone out of the
 * starting space and to its destination. This is done by first moving horizontally, 
 * then vertically. If the next spot is already occupied it switches to FLYING_EVADE, where it
 * it waits in its current position for 1 second and checks again.
 *
 * Drone *d:    The drone that you want to fly
 */
void Fly(Drone *d) {
  // First step is set our drone in the grid.
  d->grid[d->c_x][d->c_y] = OCCUPIED;
  if (d->d_x > GRID_X || d->d_y > GRID_Y) {
    printf("Coordinates are out of range! Failed to travel. Returning to base. \n");
    set_drone_state(d, FAILED);
    return;
  }
  // Ok next step is to calculate where the hell we have to go.
  signed int x_diff = d->d_x - d->c_x;
  signed int y_diff = d->d_y - d->c_y;
  // Our speed will be 1sps (square per second)
  // First Horizontal
  while (d->c_x != d->d_x) {
    move_drone(d, x_diff, &d->c_x);
    sleep(SPS_SPEED);
  }
  // Now Verticle
  while(d->c_y != d->d_y) {
    move_drone(d, y_diff, &d->c_y);
    sleep(SPS_SPEED);
  }
  // Should have arrived at our destination by now. Hopefully..
  set_drone_state(d, ARRIVED);
}
Exemplo n.º 2
0
/*
 * moveshots:
 *	Move the shots already in the air, taking explosions into account
 */
void
moveshots(void)
{
    BULLET	*bp, *next;
    PLAYER	*pp;
    int	x, y;
    BULLET	*blist;

    rollexpl();
    if (Bullets == NULL)
        goto no_bullets;

    /*
     * First we move through the bullet list conf_bulspd times, looking
     * for things we may have run into.  If we do run into
     * something, we set up the explosion and disappear, checking
     * for damage to any player who got in the way.
     */

    /* Move the list to a working list */
    blist = Bullets;
    Bullets = NULL;

    /* Work with bullets on the working list (blist) */
    for (bp = blist; bp != NULL; bp = next) {
        next = bp->b_next;

        x = bp->b_x;
        y = bp->b_y;

        /* Un-draw the bullet on all screens: */
        Maze[y][x] = bp->b_over;
        check(ALL_PLAYERS, y, x);

        /* Decide how to move the bullet: */
        switch (bp->b_type) {

        /* Normal, atomic bullets: */
        case SHOT:
        case GRENADE:
        case SATCHEL:
        case BOMB:
            if (move_normal_shot(bp)) {
                /* Still there: put back on the active list */
                bp->b_next = Bullets;
                Bullets = bp;
            }
            break;

        /* Slime bullets that explode into slime on impact: */
        case SLIME:
            if (bp->b_expl || move_normal_shot(bp)) {
                /* Still there: put back on the active list */
                bp->b_next = Bullets;
                Bullets = bp;
            }
            break;

        /* Drones that wander about: */
        case DSHOT:
            if (move_drone(bp)) {
                /* Still there: put back on the active list */
                bp->b_next = Bullets;
                Bullets = bp;
            }
            break;

        /* Other/unknown: */
        default:
            /* Place it back on the active list: */
            bp->b_next = Bullets;
            Bullets = bp;
            break;
        }
    }

    /* Again, hang the Bullets list off `blist' and work with that: */
    blist = Bullets;
    Bullets = NULL;
    for (bp = blist; bp != NULL; bp = next) {
        next = bp->b_next;
        /* Is the bullet exploding? */
        if (!bp->b_expl) {
            /*
             * Its still flying through the air.
             * Put it back on the bullet list.
             */
            save_bullet(bp);

            /* All the monitors can see the bullet: */
            for (pp = Monitor; pp < End_monitor; pp++)
                check(pp, bp->b_y, bp->b_x);

            /* All the scanning players can see the drone: */
            if (bp->b_type == DSHOT)
                for (pp = Player; pp < End_player; pp++)
                    if (pp->p_scan >= 0)
                        check(pp, bp->b_y, bp->b_x);
        } else {
            /* It is exploding. Check what we hit: */
            chkshot(bp, next);
            /* Release storage for the destroyed bullet: */
            free(bp);
        }
    }

    /* Re-draw all the players: (in case a bullet wiped them out) */
    for (pp = Player; pp < End_player; pp++)
        Maze[pp->p_y][pp->p_x] = pp->p_face;

no_bullets:

    /* Move flying boots through the air: */
    for (pp = Boot; pp < &Boot[NBOOTS]; pp++)
        if (pp->p_flying >= 0)
            move_flyer(pp);

    /* Move flying players through the air: */
    for (pp = Player; pp < End_player; pp++) {
        if (pp->p_flying >= 0)
            move_flyer(pp);
        /* Flush out the explosions: */
        sendcom(pp, REFRESH);
        look(pp);
    }

    /* Flush out and synchronise all the displays: */
    sendcom(ALL_PLAYERS, REFRESH);
}