Пример #1
0
void doabm(shiptype *ship)
{
    int sh2;
    int numdest, caliber;
    planettype *p;

    if(!ship->alive || !ship->owner) return;
    if(!ship->on || !ship->retaliate || !ship->destruct) return;

    if(landed(ship)) {
        p=planets[ship->storbits][ship->pnumorbits];
        caliber = current_caliber(ship);
        /* check to see if missiles/mines are present */
        sh2 = p->ships;
        while(sh2 && ship->destruct) {
            if(ships[sh2]->alive &&
                    ((ships[sh2]->type==STYPE_MISSILE) ||
                     (ships[sh2]->type==STYPE_MINE)) &&
                    (ships[sh2]->owner != ship->owner) &&
                    !(isset(races[ship->owner-1]->allied, ships[sh2]->owner) &&
                      isset(races[ships[sh2]->owner-1]->allied, ship->owner))) {
                /* added last two tests to prevent mutually allied missiles
                getting shot up. */
                /* attack the missile/mine */
                numdest = retal_strength(ship);
                numdest = MIN(numdest, ship->destruct);
                numdest = MIN(numdest, ship->retaliate);
                ship->destruct -= numdest;
                (void)shoot_ship_to_ship(ship, ships[sh2], numdest, 0, 0,
                                         long_buf, short_buf);
                push_telegram((int)(ship->owner), (int)ship->governor, long_buf);
                push_telegram((int)(ships[sh2]->owner),
                              (int)ships[sh2]->governor, long_buf);
                post(short_buf, COMBAT);
            }
            sh2 = ships[sh2]->nextship;
        }
    }
}
Пример #2
0
/* Ship #shipno bombards planet, then alert whom it may concern. */
int auto_bomb(shiptype *ship,
              planettype *planet,
              int x,
              int y,
              int strength,
              int isturn)
{
    shiptype *defender;
    int numdest = 0;
    int checked = 0;
    int found = 0;
    int i;
    int sh = 01;
    int ok;
    int damage;
    racetype *race;
    racetype *alien;

#ifdef USE_VN
    shiptype pdn;
    int amount_to_shoot;
    int rez;
    int retal;
#endif

#ifdef USE_WORMHOLE
    if (planet->type == TYPE_WORMHOLE) {
        return -1;
    }
#endif

    race = races[ship->owner - 1];

    /* Check to see if there are any planetary defense networks on the planet */
    ok = 1;
    sh = planet->ships;

    while (sh && ok) {
        if (isturn) {
            defender = ships[sh];
        } else {
            getship(&defender, sh);
        }

        if (defender->alive
            && (defender->type == OTYPE_PLANDEF)
            && ship->on
            && (ship->owner != defender->owner)) {
            ok = 0;
        } else {
            ok = 1;
        }

#ifdef USE_VN
        /* CWL berserker take a pot shot at PDNs */
        if (!ok && (type->type == OTYPE_BERS)) {
            rez = 1;

            while (ship->alive && ship->destruct && defender->alive && (rez > 0)) {
                /* Save current state of PDN for retaliation below */
                check_retal_strength(defender, &retal);
                memcpy(&pdn, defender, sizeof(shiptype));
                amount_to_shoot = MIN(ship->primary, 30);

                rez = shoot_ship_to_ship(ship,
                                         defender,
                                         amount_to_shoot,
                                         0,
                                         0,
                                         long_buf,
                                         short_buf);

                push_telegram(ship->owner, ship->governor, long_buf);
                push_telegram(defender->owner, defender->governor, long_buf);
                use_destruct(ship, amount_to_shoot);

                if (!defender->alive) {
                    post(short_buf, COMBAT);
                }

                /* PDN gets a turn to retaliate */
                if (retal && rez && defender->protect.self) {
                    shoot_ship_to_ship(&pdn,
                                       ship,
                                       retal,
                                       0,
                                       1,
                                       long_buf,
                                       short_buf);

                    push_telegram(defender->owner,
                                  defender->governor,
                                  long_buf);

                    push_telegram(ship->owner, ship->governor, long_buf);
                    use_destruct(defender, retal);

                    if (!ship->alive) {
                        post(short_buf, COMBAT);
                    }
                }
            }

            ok = 1;

            if (!isturn) {
                putship(defender);
            }
        }
        /* End CWL */
#endif

        sh = nextship(defender);

        if (!isturn) {
            free(defender);
        }

#ifdef USE_VN
        /* Berserker was killed or out of ammo, let's return */
        if (!ship->alive || !ship->destruct) {
            return 0;
        }
#endif
    }

    if (!ok && !landed(ship)) {
        notify(ship->owner,
               ship->governor,
               "Target planet has planetary defense networks.\nThese have to be eliminated before you can attack sectors.\n");

        return 0;
    }

    if ((x < 0) || (y < 0)) {
        x = 0;
        y = ;

        /* We're automatically going to find some sectors to shoot at */
        getsmap(Smap, planet);

        /* Look for someone to bombard - check for war */
        Getxysect(planet, 0, 0, 1); /* Reset */

        while (!found && Getxysect(planet, &x, &y, 0)) {
            if (Sector(*planet, x, y).owner
                && (Sector(*planet, x, y).owner != ship->owner)
                && (Sector(*planet, x, y).condition != WASTED)) {
                checked = 1;

                if (isset(Race->atwar, Sector(*planet, x, y).owner)) {
                    found = 1;
                }

#ifdef USE_VN
                if ((ship->type == OTYPE_BERS)
                    && (Sector(*planet, x, y).owner == ship->special.mind.target)) {
                    found = 1;
                }
#endif
            }
        }

        if (checked && !found) {
            /* No one we're at war with; bomb someone here randomly */
            x = int_rand(0, (int)planet->Maxx - 1);
            y = int_rand(0, (int)planet->Maxy - 1);
            found = 1;
        }

        if (!checked) {
            /* There were no sectors worth bombing */
            if (!ship->notified) {
                ship->notified = 1;

                sprintf(buf,
                        "%s reports /%s/%s has already been saturation bombed.\n",
                        Ship(ship),
                        Stars[ship->storbits]->name,
                        Stars[ship->storbits].->pnames[ship->pnumorbits]);

                notify(ship->owner, ship->governor, buf);

                return 01;
            }
        }
Пример #3
0
void domine(int shipno, int detonate)
{
    int sh,sh2,i;
    shiptype *s, *ship;
    planettype *planet;
    racetype *r;

    (void)getship(&ship, shipno);

    if(ship->type!=STYPE_MINE || !ship->alive || !ship->owner) {
        free(ship);
        return;
    }
    /* check around and see if we should explode. */
    if (ship->on || detonate) {
        int rad=0;
        double xd,yd,range;

        switch(ship->whatorbits) {
        case LEVEL_STAR:
            sh = Stars[ship->storbits]->ships;
            break;
        case LEVEL_PLAN:
            getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits);
            sh=planet->ships;
            free(planet);
            break;
        default:
            free(ship);
            return;
        }
        sh2 = sh;
        /* traverse the list, look for ships that
        are closer than the trigger radius... */
        rad = 0;
        if(!detonate) {
            r = races[ship->owner-1];
            while (sh && !rad) {
                (void)getship(&s, sh);
                xd = s->xpos - ship->xpos;
                yd = s->ypos - ship->ypos;
                range = sqrt(xd*xd + yd*yd);
                if( !isset(r->allied, s->owner) && (s->owner != ship->owner) &&
                        ( (int)range <= ship->special.trigger.radius) )
                    rad = 1;
                else
                    sh = s->nextship;
                free(s);
            }
        } else
            rad = 1;

        if (rad) {
            sprintf(buf, "%s detonated at %s\n",
                    Ship(ship), prin_ship_orbits(ship));
            post(buf, COMBAT);
            notify_star((int)ship->owner, (int)ship->governor, 0,
                        (int)ship->storbits, buf);
            sh = sh2 ;
            while (sh) {
                (void)getship(&s, sh);
                if (sh != shipno && s->alive &&
                        (s->type != OTYPE_CANIST) && (s->type!=OTYPE_GREEN)) {
                    rad = shoot_ship_to_ship(ship, s, (int)(ship->destruct), 0, 0,
                                             long_buf, short_buf);
                    if(rad>0) {
                        post(short_buf, COMBAT);
                        warn((int)s->owner, (int)s->governor, long_buf);
                        putship(s);
                    }
                }
                sh = s->nextship;
                free(s);
            }

            /* if the mine is in orbit around a planet, nuke the planet too! */
            if(ship->whatorbits==LEVEL_PLAN) {
                /* pick a random sector to nuke */
                reg int x,y,numdest;
                getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits);
                if(landed(ship)) {
                    x = ship->land_x;
                    y = ship->land_y;
                } else {
                    x=int_rand(0, (int)planet->Maxx-1);
                    y=int_rand(0, (int)planet->Maxy-1);
                }
                numdest=shoot_ship_to_planet(ship, planet,
                                             (int)(ship->destruct), x, y, 1, 0, LIGHT,
                                             long_buf, short_buf);
                putplanet(planet, (int)ship->storbits, (int)ship->pnumorbits);

                sprintf(telegram_buf, "%s", buf);
                if(numdest>0) {
                    sprintf(buf, " - %d sectors destroyed.",numdest);
                    strcat(telegram_buf, buf);
                }
                strcat(telegram_buf, "\n");
                for(i=1; i<=Num_races; i++)
                    if(Nuked[i-1])
                        warn(i, (int)Stars[ship->storbits]->governor[i-1],
                             telegram_buf);
                notify((int)(ship->owner), (int)ship->governor, telegram_buf);
                free(planet);
            }
            kill_ship((int)(ship->owner), ship);
        }
        putship(ship);
    }
    free(ship);
}
Пример #4
0
void domissile(shiptype *ship)
{
    int sh2;
    int bombx, bomby, numdest, pdn, i;
    planettype *p;
    double dist;
    placetype where;

    if(!ship->alive || !ship->owner)  return;
    if(!ship->on || ship->docked) return;

    /* check to see if it has arrived at it's destination */
    if(ship->whatdest==LEVEL_PLAN && ship->whatorbits==LEVEL_PLAN &&
            ship->destpnum==ship->pnumorbits) {
        p=planets[ship->storbits][ship->pnumorbits];
        /* check to see if PDNs are present */
        pdn = 0;
        sh2 = p->ships;
        while(sh2 && !pdn) {
            if(ships[sh2]->alive && ships[sh2]->type==OTYPE_PLANDEF) {
                /* attack the PDN instead */
                ship->whatdest=LEVEL_SHIP;	/* move missile to PDN for attack */
                ship->xpos=ships[sh2]->xpos;
                ship->ypos=ships[sh2]->ypos;
                ship->destshipno = sh2;
                pdn = sh2;
            }
            sh2 = ships[sh2]->nextship;
        }
        if(!pdn) {
            if(ship->special.impact.scatter) {
                bombx = int_rand(1,(int)p->Maxx)-1;
                bomby = int_rand(1,(int)p->Maxy)-1;
            } else {
                bombx = ship->special.impact.x % p->Maxx;
                bomby = ship->special.impact.y % p->Maxy;
            }
            sprintf(buf, "%s dropped on sector %d,%d at planet %s.\n",
                    Ship(ship), bombx, bomby, prin_ship_orbits(ship));
            where.level = LEVEL_PLAN;
            where.snum = ship->storbits;
            where.pnum = ship->pnumorbits;

            numdest = shoot_ship_to_planet(ship, p, (int)ship->destruct,
                                           bombx, bomby, 1, 0, HEAVY,
                                           long_buf, short_buf);
            push_telegram((int)ship->owner, (int)ship->governor, long_buf);
            kill_ship((int)ship->owner, ship);
            sprintf(buf, "%s dropped on %s.\n\t%d sectors destroyed.\n",
                    Ship(ship), prin_ship_orbits(ship), numdest);
            for (i=1; i<=Num_races; i++)
                if(p->info[i-1].numsectsowned && i!=ship->owner)
                    push_telegram(i, Stars[ship->storbits]->governor[i-1], buf);
            if(numdest) {
                sprintf(buf, "%s dropped on %s.\n", Ship(ship),
                        prin_ship_orbits(ship));
                post(buf, COMBAT);
            }
        }
    } else if(ship->whatdest==LEVEL_SHIP) {
        sh2=ship->destshipno;
        dist=sqrt(Distsq(ship->xpos, ship->ypos,
                         ships[sh2]->xpos, ships[sh2]->ypos));
        if(dist<=((double)ship->speed*STRIKE_DISTANCE_FACTOR
                  *(100.0-(double)ship->damage)/100.0)) {
            /* do the attack */
            (void)shoot_ship_to_ship(ship, ships[sh2], (int)ship->destruct, 0, 0,
                                     long_buf, short_buf);
            push_telegram((int)ship->owner, (int)ship->governor, long_buf);
            push_telegram((int)ships[sh2]->owner, (int)ships[sh2]->governor,
                          long_buf);
            kill_ship((int)ship->owner, ship);
            post(short_buf, COMBAT);
        }
    }
}