Ejemplo n.º 1
0
/*
 * Find out whether planes can fly one-way to X,Y.
 * Offer the player any carriers there.  If he chooses one, read it
 * into TARGET->ship.  Else read the target sector into TARGET->sect.
 * If planes can land there, set required plane flags in *FLAGSP, and
 * return 0.  Else return -1.
 */
int
pln_where_to_land(coord x, coord y,
		  union empobj_storage *target, int *flagsp)
{
    int nships;
    int cno;
    int fl;
    char buf[1024];
    char *p;

    /* offer carriers */
    nships = carriersatxy(x, y, player->cnum);
    if (nships) {
	for (;;) {
	    p = getstring("Carrier #? ", buf);
	    if (!p)
		return -1;
	    if (!*p)
		break;
	    cno = atoi(p);
	    if (!getship(cno, &target->ship)
		|| (!player->owner
		    && (relations_with(target->ship.shp_own, player->cnum)
			!= ALLIED))) {
		pr("Not yours\n");
		continue;
	    }
	    if (target->ship.shp_x != x || target->ship.shp_y != y) {
		pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
		continue;
	    }
	    fl = carrier_planes(&target->ship, 0);
	    if (fl == 0) {
		pr("Can't land on %s.\n", prship(&target->ship));
		continue;
	    }
	    /* clear to land on ship#CNO */
	    pr("landing on carrier %d\n", cno);
	    *flagsp |= fl;
	    return 0;
	}
    }

    /* try to land at sector */
    getsect(x, y, &target->sect);
    if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
	pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
	return -1;
    }
    if (target->sect.sct_type == SCT_MOUNT) {
	pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
	return -1;
    }
    /* clear to land at sector */
    if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
	*flagsp |= P_V;
    return 0;
}
Ejemplo n.º 2
0
static void
anti_torp(int f, int ntorping, int vshipown)
{
    struct shpstr sub;
    struct shpstr dd;
    int x;

    getship(f, &sub);

    if (sub.shp_own == vshipown)
	return;

    x = 0;
    while (getship(x++, &dd) && sub.shp_effic >= SHIP_MINEFF) {
	if (dd.shp_own == 0)
	    continue;
	if (dd.shp_own != vshipown)
	    continue;

	if (!fire_torp(&dd, &sub, ntorping))
	    fire_dchrg(&dd, &sub, ntorping);
    }
}
Ejemplo n.º 3
0
static void refit(struct player *me, int type)
{
  getship(&(me->p_ship), type);

  /* enable docking */
  if (type == STARBASE) me->p_flags |= PFDOCKOK;

  /* restrict speed to new class */
  if (me->p_desspeed > me->p_ship.s_maxspeed)
    me->p_desspeed = me->p_ship.s_maxspeed;

  /* bump all docked ships */
  bay_release_all(me);
  me->p_flags |= PFDOCKOK;
}
Ejemplo n.º 4
0
void
pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
{
    struct emp_qelem *qp;
    struct plist *plp;
    struct shpstr ship;
    struct sctstr sect;

    if (cno >= 0)
	getship(cno, &ship);
    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
	plp = (struct plist *)qp;
	if (cno >= 0) {
	    if (!could_be_on_ship(&plp->plane, &ship))
		pr("\t%s cannot land on ship #%d! %s aborts!\n",
		   prplane(&plp->plane), cno, prplane(&plp->plane));
	    else if (!put_plane_on_ship(&plp->plane, &ship))
		pr("\tNo room on ship #%d! %s aborts!\n",
		   cno, prplane(&plp->plane));
	    else {
		if (plp->plane.pln_own != ship.shp_own) {
		    wu(0, ship.shp_own, "%s %s lands on your %s\n",
		       cname(player->cnum), prplane(&plp->plane),
		       prship(&ship));
		}
		if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
		    && ship.shp_pstage == PLG_HEALTHY)
		    ship.shp_pstage = PLG_EXPOSED;
	    }
	} else {
	    plp->plane.pln_x = tx;
	    plp->plane.pln_y = ty;
	    getsect(tx, ty, &sect);
	    if (plp->plane.pln_own != sect.sct_own) {
		wu(0, sect.sct_own,
		   "%s %s lands at your sector %s\n",
		   cname(player->cnum),
		   prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
	    }
	    if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
		&& sect.sct_pstage == PLG_HEALTHY)
		sect.sct_pstage = PLG_EXPOSED;
	    plp->plane.pln_ship = cno;
	}
    }
}
Ejemplo n.º 5
0
void
pln_put1(struct plist *plp)
{
    struct plnstr *pp;
    struct shpstr ship;
    struct sctstr sect;

    pp = &plp->plane;

    if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
		    && (plchr[pp->pln_type].pl_flags & P_M)
		    && pp->pln_effic >= PLANE_MINEFF))
	pp->pln_effic = 0;   /* bug: missile launched but not used up */

    if (!(pp->pln_flags & PLN_LAUNCHED))
	;			/* never took off */
    else if (pp->pln_effic < PLANE_MINEFF) {
	;			/* destroyed */
    } else if (pp->pln_ship >= 0) {
	/* It is landing on a carrier */
	getship(pp->pln_ship, &ship);
	/* We should do more, like make sure it's really
	   a carrier, etc. but for now just make sure it's
	   not sunk. */
	if (ship.shp_effic < SHIP_MINEFF) {
	    mpr(pp->pln_own,
		"Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
		"splashes into the sea.\n",
		pp->pln_ship, pp->pln_uid);
	    pp->pln_effic = 0;
	}
    } else {
	/* Presume we are landing back in a sector. */
	getsect(pp->pln_x, pp->pln_y, &sect);
	if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
	    mpr(pp->pln_own,
		"Nowhere to land at %s, plane #%d crashes and burns...\n",
		xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
	    pp->pln_effic = 0;
	}
    }
    pp->pln_flags &= ~PLN_LAUNCHED;
    putplane(pp->pln_uid, pp);
    emp_remque(&plp->queue);
    free(plp);
}
Ejemplo n.º 6
0
void continue_ship(region * r, unit * u, int want)
{
    const construction *cons;
    ship *sh;
    int msize;

    if (!eff_skill(u, SK_SHIPBUILDING, r)) {
        cmistake(u, u->thisorder, 100, MSG_PRODUCE);
        return;
    }

    /* Die Schiffsnummer bzw der Schiffstyp wird eingelesen */
    sh = getship(r);

    if (!sh)
        sh = u->ship;

    if (!sh) {
        cmistake(u, u->thisorder, 20, MSG_PRODUCE);
        return;
    }
    cons = sh->type->construction;
    assert(cons->improvement == NULL);    /* sonst ist construction::size nicht ship_type::maxsize */
    if (sh->size == cons->maxsize && !sh->damage) {
        cmistake(u, u->thisorder, 16, MSG_PRODUCE);
        return;
    }
    if (eff_skill(u, cons->skill, r) < cons->minskill) {
        ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
            "error_build_skill_low", "value", cons->minskill));
        return;
    }
    msize = maxbuild(u, cons);
    if (msize == 0) {
        cmistake(u, u->thisorder, 88, MSG_PRODUCE);
        return;
    }
    if (want > 0)
        want = _min(want, msize);
    else
        want = msize;

    build_ship(u, sh, want);
}
Ejemplo n.º 7
0
void cleanup(void)
{
    register struct player *j;
    register int i;

    /* Free the held slots - MK 9-20-92 */
    for (i=12, j = &players[i]; i < MAXPLAYER - TESTERS; i++, j++) {
        if ( j->p_status==POUTFIT && j->p_team==NOBODY){
            j->p_status = PFREE;
	}
    }

    if (!practice) {
	memcpy(planets, oldplanets, sizeof(struct planet) * MAXPLANETS);
	for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
	    if ((j->p_status != PALIVE) || (j == me)) continue;
	    getship(&(j->p_ship), j->p_ship.s_type);
	}
    }
    status->gameup &= ~GU_DOG;
    exitRobot();
}
Ejemplo n.º 8
0
char *prin_ship_orbits(shiptype *s)
{
    shiptype *mothership;
    char *motherorbits;

    switch (s->whatorbits) {
    case LEVEL_UNIV:
        sprintf(Dispshiporbits_buf, "/(%.0f,%.0f)", s->xpos, s->ypos);

        break;
    case LEVEL_STAR:
        sprintf(Dispshiporbits_buf, "/%s", Stars[s->storbits]->name);

        break;
    case LEVEL_PLAN:
        sprintf(Dispshiporbits_buf,
                "/%s/%s",
                Stars[s->storbits]->name,
                Stars[s->storbits]->pnames[s->pnumorbits]);

        break;
    case LEVEL_SHIP:
        if (getship(&mothership, s->destshipno)) {
            motherorbits = prin_ship_orbits(mothership);
            strcpy(Dispshiporbits_buf, motherorbits);
            free(mothership);
        } else {
            strcpy(Dispshiporbits_buf, "/");
        }

        break;
    default:

        break;
    }

    return Dispshiporbits_buf;
}
Ejemplo n.º 9
0
/*
  go_arena
*/
void enterFight(int a, int b, int ano, int schedule)
{
    /* 1. Removes arena_num from free arena list    D>
       2. Sets p_pflag & PFDOG			    <D>
       3. Announces fight				*/

    char buf[80];
    struct player *p1, *p2;
    int times_fought = 0, shiptype1 = 0, shiptype2 = 0;
    Track *tr1;
    Track *tr2;

    checkBadPlayerNo(a,"in enterFight a\n");
    checkBadPlayerNo(b,"in enterFight b\n");
    checkBadArenaNo(ano,"in enterFight\n");

    p1 = &players[a];
    p2 = &players[b];
    tr1 = &tracks[a];
    tr2 = &tracks[b];

    if (p1 == me || p2 == me) {
	ERROR(2,("Just tried to enter myself in a fight.  Exitting.\n"));
	cleanup();
    }
	
    /* announces match */
    sprintf(buf,"[MATCH %d] %s(%c%c) versus %s(%c%c) in arena %d!",
	    matchnum++,p1->p_name,
	    teamlet[p1->p_team],shipnos[p1->p_no],p2->p_name,
	    teamlet[p2->p_team],shipnos[p2->p_no],ano);
    messAll(255,roboname,buf);
    messOne(255,roboname,a,buf);
    messOne(255,roboname,b,buf);
    
    times_fought = (schedule % 5);
    switch(times_fought) {
	case 0:
	    shiptype1 = shiptype2 = BATTLESHIP;
	    break;
	case 1:
	    shiptype1 = shiptype2 = CRUISER;
	    break;
	case 2:
	    shiptype1 = shiptype2 = DESTROYER;
	    break;
	case 3:
	    shiptype1 = shiptype2 = SCOUT;
	    break;
	case 4:
	    shiptype1 = tr1->t_preferred;
	    shiptype2 = tr2->t_preferred;
	    break;
	default:
	    shiptype1 = shiptype2 = -1;	/* don't change their ship type */
	    break;
    }
    if (shiptype1 != -1)
	getship(&p1->p_ship, shiptype1);
    if (shiptype2 != -1)
	getship(&p2->p_ship, shiptype2);

    tr1->t_opponent = b;
    tr2->t_opponent = a;
    tr1->t_flags |= PU_DOG;
    tr2->t_flags |= PU_DOG;

    go_arena(ano,a,0);
    go_arena(ano,b,1);
}
Ejemplo n.º 10
0
int
torp(void)
{
    natid vshipown;
    int range;
    int dam;
    int subno;
    int victno;
    int erange;
    double hitchance;
    struct shpstr vship;
    struct shpstr sub;
    struct mchrstr *sub_mcp;
    char *ptr;
    struct nstr_item nbst;
    char buf[1024];
    int ntorping = 0;
    char prompt[128];

    if (!snxtitem(&nbst, EF_SHIP, player->argp[1], "From ship(s)? "))
	return RET_SYN;
    while (nxtitem(&nbst, &sub)) {
	if (sub.shp_own != player->cnum)
	    continue;
	if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0)
	    continue;
	if (sub.shp_item[I_GUN] == 0
	    || sub.shp_item[I_SHELL] < SHP_TORP_SHELLS)
	    continue;
	if (sub.shp_item[I_MILIT] < 1)
	    continue;
	if (sub.shp_effic < 60)
	    continue;
	if (sub.shp_mobil <= 0)
	    continue;
	ntorping++;
    }
    pr("%d ships are eligible to torpedo\n", ntorping);
    snxtitem_rewind(&nbst);
    while (nxtitem(&nbst, &sub)) {
	if (!sub.shp_own)
	    continue;
	if (sub.shp_own != player->cnum) {
	    continue;
	}
	sub_mcp = &mchr[sub.shp_type];
	if (!(sub_mcp->m_flags & M_TORP)) {
	    pr("Ship # %d: A %s can't fire torpedoes!\n",
	       sub.shp_uid, sub_mcp->m_name);
	    continue;
	}
	if (sub.shp_item[I_GUN] == 0
	    || sub.shp_item[I_SHELL] < SHP_TORP_SHELLS) {
	    pr("Ship #%d has insufficient armament\n", sub.shp_uid);
	    continue;
	}
	if (sub.shp_item[I_MILIT] < 1) {
	    pr("Ship #%d has insufficient crew\n", sub.shp_uid);
	    continue;
	}
	if (sub.shp_effic < 60) {
	    pr("Ship #%d torpedo tubes inoperative.\n", sub.shp_uid);
	    continue;
	}
	if (sub.shp_mobil <= 0) {
	    pr("Ship #%d has insufficient mobility\n", sub.shp_uid);
	    continue;
	}
	subno = sub.shp_uid;
	sprintf(prompt, "Ship %d, target? ", sub.shp_uid);
	if (!(ptr = getstarg(player->argp[2], prompt, buf)))
	    return RET_SYN;
	if (!check_ship_ok(&sub))
	    return RET_FAIL;
	if ((victno = atoi(ptr)) < 0)
	    return RET_SYN;
	if (!getship(victno, &vship))
	    return RET_FAIL;
	if (!vship.shp_own)
	    return RET_FAIL;
	vshipown = vship.shp_own;
	if (victno == subno) {
	    pr("Shooting yourself, eh?  How strange...\n");
	    continue;
	}
	if (mchr[(int)vship.shp_type].m_flags & M_SUB) {
	    if (!(sub_mcp->m_flags & M_SUBT)) {
		pr("You can't torpedo a submarine!\n");
		continue;
	    }
	}
	dam = shp_torp(&sub, 1);
	sub.shp_mission = 0;
	putship(sub.shp_uid, &sub);
	if (CANT_HAPPEN(dam < 0)) {
	    pr("Ship #%d has insufficient armament\n", sub.shp_uid);
	    continue;
	}

	if (!(sub_mcp->m_flags & M_SUB)) {
	    pr("Starting our attack run...\n");
	    anti_torp(sub.shp_uid, ntorping, vshipown);
	}
	getship(sub.shp_uid, &sub);
	if (sub.shp_own == 0)
	    continue;

	erange = roundrange(torprange(&sub));
	pr("Effective torpedo range is %d.0\n", erange);
	pr("Whooosh... ");
	getship(victno, &vship);
	vshipown = vship.shp_own;
	range = mapdist(sub.shp_x, sub.shp_y, vship.shp_x, vship.shp_y);
	hitchance = shp_torp_hitchance(&sub, range);
	if (range <= erange) {
	    pr("Hitchance = %.0f%%\n", hitchance * 100);
	}
	if (range > erange)
	    pr("Out of range\n");
	else if (!line_of_sight(NULL, sub.shp_x, sub.shp_y,
				vship.shp_x, vship.shp_y)) {
	    pr("BOOM!... Torpedo slams into land before reaching target.\n");
	    /* We only tell the victim if we were within range. */
	    if (vshipown != 0 && vshipown != player->cnum)
		wu(0, vshipown, "Torpedo sighted @ %s by %s\n",
		   xyas(sub.shp_x, sub.shp_y, vshipown),
		   prship(&vship));
	} else if (chance(hitchance)) {
	    pr("BOOM!...\n");
	    if (vshipown != 0 && vshipown != player->cnum)
		wu(0, vshipown, "%s in %s torpedoed %s for %d damage.\n",
		   sub_mcp->m_flags & M_SUB ? "sub" : prship(&sub),
		   xyas(sub.shp_x, sub.shp_y, vshipown),
		   prship(&vship), dam);
	    pr("Torpedo hit %s for %d damage.\n", prsub(&vship), dam);
	    if (!(mchr[vship.shp_type].m_flags & M_SUB)) {
		if (mchr[sub.shp_type].m_flags & M_SUB)
		    nreport(vshipown, N_TORP_SHIP, 0, 1);
		else
		    nreport(vshipown, N_SHIP_TORP, player->cnum, 1);
	    }
	    shipdamage(&vship, dam);
	    if (vship.shp_effic < SHIP_MINEFF)
		pr("%s sunk!\n", prsub(&vship));
	    if (vship.shp_rflags & RET_TORPED)
		retreat_ship(&vship, vshipown, 't');
	    putship(vship.shp_uid, &vship);
	} else {
	    pr("Missed\n");
	    if (vshipown != 0 && vshipown != player->cnum)
		wu(0, vshipown, "Torpedo sighted @ %s by %s\n",
		   xyas(sub.shp_x, sub.shp_y, vshipown), prship(&vship));
	}

	if (sub_mcp->m_flags & M_SUB)
	    anti_torp(sub.shp_uid, ntorping, vshipown);
    }
    return RET_OK;
}
Ejemplo n.º 11
0
void scrap(int playernum, int governor, int apcount)
{
    planettype *planet;
    sectortype *sect;
    shiptype *s;
    shiptype *s2;
    int shipno;
    int nextshipno;
    int scrapval = 0;
    int destval = 0;
    int crewval = 0;
    int max_crew = 0;
    int xtalval = 0;
    int troopval = 0;
    int max_resource = 0;
    int max_mil = 0;
    int max_fuel = 0;
    int max_destruct = 0;
    int cost = 0;
    double fuelval = 0.0;
    racetype *race;

    if (argn < 2) {
        notify(playernum, governor, "Scrap what?\n");

        return;
    }

    nextshipno = start_shiplist(playernum, governor, args[1]);
    race = races[playernum - 1];

    if (race->Guest) {
        notify(playernum, governor, "Guest races cannot scrap ships\n");

        return;
    }

    shipno = do_shiplist(&s, &nextshipno);

    while (shipno) {
        if (in_list(playernum, args[1], s, &nextshipno)) {
#ifdef USE_VN
            if ((s->type == OTYPE_VN) || (s->type == OTYPE_BERS)) {
                notify(playernum, governor, "VNs will not scrap themselves.\n");
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }
#endif

            if (s->max_crew && !s->popn) {
                notify(playernum,
                       governor,
                       "Can't scrap that ship - no crew.\n");

                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            if (s->whatorbits == LEVEL_UNIV) {
                /*
                 * Used to not allow scrapping at the UNIV level for
                 * anything. However, I'm going to permit pods. This is so pod
                 * races can clean up their messes. I'm not going to charge APs
                 * at the UNIV scope either. -mfw
                 */
                if (s->type) {
                    apcount = 0;
                } else {
                    notify(playernum,
                           governor,
                           "Can't scrap at the ship's scope.\n");

                    free(s);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }
            } else if (!enufAP(playernum, governor, Stars[s->storbits]->AP[playernum - 1], apcount)) {
                notify(playernum, governor, "Not enough APs to scrap.\n");
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            /* HUTm (kse) wc's can't be scrapped inside of ship anymore */
            if (inship(s) && (s->type == OTYPE_TOXIC)) {
                sprintf(buf,
                        "Can't scrap waste canisters inside of other ship.\n");

                notify(playernum, governor, buf);
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            /* Ships that have other ships in the hangar can't scrap *mfw */
            if (s->ships) {
                sprintf(buf,
                        "There are other ships in the hangar; scrap those first.\n");

                notify(playernum, governor, buf);
                free(s);
                shipno = do_shiplist(&s, &nextshipno);

                continue;
            }

            if ((s->whatorbits == LEVEL_PLAN) && (s->type == OTYPE_TOXIC)) {
                sprintf(buf,
                        "WARNING: This releases %d toxin points back into the atmosphere!!!\n",
                        s->special.waste.toxic);

                notify(playernum, governor, buf);
            }

            if (!s->docked) {
                sprintf(buf,
                        "%s is not landed or docked.\nNo resources can be reclaimed.\n",
                        Ship(s));

                notify(playernum, governor, buf);
            }

            if (s->whatorbits == LEVEL_PLAN) {
                /* wc's release poison */
                getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);

                if (landed(s)) {
                    if (!getsector(&sect, planet, (int)s->land_x, (int)s->land_y)) {
                        notify(playernum,
                               governor,
                               "Error in sector database, notify deity.\n");

                        free(s);

                        return;
                    }
                }
            }

            if (docked(s) || inship(s)) {
                if (!getship(&s2, (int)s->destshipno)) {
                    free(s);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }

                if ((!s2->docked || (s2->destshipno != s->number))
                    && (!s->whatorbits == LEVEL_SHIP)) {
                    sprintf(buf, "Warning, other ship not docked...\n");
                    notify(playernum, governor, buf);
                    free(s);
                    free(s2);
                    shipno = do_shiplist(&s, &nextshipno);

                    continue;
                }
            }

            if (s->type == OTYPE_FACTORY) {
                cost = (2 * s->build_code * s->on) + Shipdata[s->type][ABIL_COST];
            } else {
                cost = s->build_cost;
            }

            scrapval = (cost / 2) + s->resource;

            if (s->docked) {
                sprintf(buf, "%s: original cost: %ld\n", Ship(s), cost);
                notify(playernum, governor, buf);

                sprintf(buf,
                        "         scrap value%s: %d rp's.\n",
                        s->resource ? "(with stockpile) " : "",
                        scrapval);

                notify(playernum, governor, buf);

                /* New code by Kharush. check for STYPE_DHUTTLE added. */
                /* I've removed it, Dhuttle was silly -mfw */

                if (s2->type == OTYPE_FACTORY) {
                    max_resource = Shipdata[s2->type][ABIL_CARGO];
                    max_fuel = Shipdata[s2->type][ABIL_FUELCAP];
                    max_destruct = Shipdata[s2->type][DESTCAP];
                } else {
                    max_resource = s2->max_resource;
                    max_fuel = s2->max_fuel;
                    max_destruct = s2->max_destruct;
                }

                if ((s->whatdest == LEVEL_SHIP)
                    && ((s2->resource + scrapval) > max_resource)
                    && (s2->type != STYPE_SHUTTLE)) {
                    scrapval = max_resource - s2->resource;
                    sprintf(buf,
                            "(There is only room for %d resources.)\n",
                            scrapval);

                    notify(playernum, governor, buf);
                }

                if (s->fuel) {
                    sprintf(buf, "Fuel recover: %.0f.\n", s->fuel);
                    notify(playernum, governor, buf);
                    fuelval = s->fuel;

                    if ((s->whatdest == LEVEL_SHIP)
                        && ((s2->fuel + fuelval) > max_fuel)) {
                        fuelval = max_fuel - s2->fuel;
                        sprintf(buf,
                                "(There is only room for %.2f fuel.)\n",
                                fuelval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    fuelval = 0.0;
                }

                if (s->destruct) {
                    sprintf(buf, "Armament recovery: %d.\n", s->destruct);
                    notify(playernum, governor, buf);
                    destval = s->destruct;

                    if ((s->whatdest == LEVEL_SHIP)
                        && ((s2->destruct + destval) > max_destruct)) {
                        destval = max_destruct - s2->destruct;
                        sprintf(buf,
                                "(There is only room for %d destruct.)\n",
                                destval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    destval = 0;
                }

                if (s->popn + s->troops) {
                    if ((s->whatdest == LEVEL_PLAN)
                        && (sect->owner > 0)
                        && (sect->owner != playernum)) {
                        sprintf(buf,
                                "You don't own this sector; no crew can be recovered.\n");

                        notify(playernum, governor, buf);
                    } else {
                        troopval = s->troops;

                        if (s2->type == OTYPE_FACTORY) {
                            max_mil = Shipdata[s2->type][ABIL_MAXCREW] - s->popn;
                        } else {
                            max_mil = s2->max_crew - s2->popn;
                        }

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->troops + troopval) > max_mil)) {
                            troopval = max_mil - s2->troops;
                            sprintf(buf,
                                    "(There is only room for %d troops.)\n",
                                    troopval);

                            notify(playernum, governor, buf);
                        }

                        crewval = s->popn;

                        if (s2->type == OTYPE_FACTORY) {
                            max_crew = Shipdata[s2->type][ABIL_MAXCREW] - s2->troops;
                        } else {
                            max_crew = s2->max_crew - s2->troops;
                        }

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->popn + crewval) > max_crew)) {
                            crewval = max_crew - s2->popn;
                            sprintf(buf,
                                    "(There is only room for %d crew.)\n",
                                    crewval);

                            notify(playernum, governor, buf);
                        }

                        sprintf(buf,
                                "Population/Troops recover: %d/%d.\n",
                                crewval,
                                troopval);

                        notify(playernum, governor, buf);
                    }
                } else {
                    crewval = 0;
                    troopval = 0;
                }

                if (s->crystals + s->mounted) {
                    if ((s->whatdest == LEVEL_PLAN)
                        && (sect->owner > 0)
                        && (sect->owner != playernum)) {
                        sprintf(buf,
                                "You don't own this sector; no crystals can be recovered.\n");

                        notify(playernum, governor, buf);
                    } else {
                        xtalval = s->crystals + s->mounted;

                        if ((s->whatdest == LEVEL_SHIP)
                            && ((s2->crystals + xtalval) > 127)) {
                            xtalval = 127 - s2->crystals;
                            sprintf(buf,
                                    "(There is only room for %d crystals.)\n",
                                    xtalval);

                            notify(playernum, governor, buf);
                        }

                        sprintf(buf, "Crystal recover: %d.\n", xtalval);
                        notify(playernum, governor, buf);
                    }
                } else {
                    xtalval = 0;
                }
            }

            /* More adjustments needed here for hangar. Maarten */
            if (s->whatorbits == LEVEL_SHIP) {
                s2->hangar -= (unsigned short)s->size;
            }

            if (s->whatorbits == LEVEL_UNIV) {
                deductAPs(playernum, governor, apcount, 0, 1);
            } else {
                deductAPs(playernum, governor, apcount, (int)s->storbits, 0);
            }

            if (docked(s) || inship(s)) {
                s2->crystals += xtalval;
                rcv_fuel(s2, (double)fuelval);
                rcv_destruct(s2, destval);
                rcv_resource(s2, scrapval);
                rcv_troops(s2, troopval, race->mass);
                rcv_popn(s2, crewval, race->mass);

                /*
                 * Check for docking status in case scrapped ship is
                 * landed. Maarten
                 */
                if (s->whatorbits != LEVEL_SHIP) {
                    s2->docked = 0; /* Undock the surviving ship */
                    s2->whatdest = LEVEL_UNIV;
                    s2->destshipno = 0;
                }

                putship(s2);
                free(s2);
            }

            if (s->whatorbits == LEVEL_PLAN) {
                free(planet); /* this has already been allocated */
                getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);

                if (landed(s) || inship(s)) {
                    /*
                     * If colonizing the sector, set sector owner and give a
                     * message it's also nice to check if there is anyone to
                     * colonize
                     */
                    if ((sect->owner == 0)
                        && ((troopval > 0) || (crewval > 0))) {
                        sect->owner = playernum;
                        ++planet->info[playernum - 1].numsectsowned;
                        sprintf(buf,
                                "Sector %d,%d Colonized.\n",
                                s->land_x,
                                s->land_y);

                        notify(playernum, governor, buf);
                    }

                    /* Increase sector's crew and troop count */
                    sect->troops += troopval;
                    sect->popn += crewval;

                    /*
                     * Increase planet's crew, troop, res, tec. count for this
                     * player
                     */
                    planet->info[playernum - 1].popn += crewval;
                    planet->info[playernum - 1].troops += troopval;

                    /*
                     * New code by Kharush. Scrapping does not anymore overflow
                     * stockpiles.
                     */
                    if ((planet->info[playernum - 1].resource + scrapval) <= USHRT_MAX) {
                        planet->info[playernum - 1].resource += scrapval;
                    } else {
                        planet->info[playernum - 1].resource = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d resources.\n",
                                USHRT_MAX - planet->info[playernum - 1].resource);

                        notify(playernum, governor, buf);
                    }

                    if ((playernum->info[playernum - 1].fuel + fuelval) <= USHRT_MAX) {
                        planet->info[playernum - 1].fuel += fuelval;
                    } else {
                        planet->info[playernum - 1].fuel = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d fuel.\n",
                                USHRT_MAX - planet->info[playernum - 1].fuel);

                        notify(playernum, governor, buf);
                    }

                    if ((planet->info[playernum - 1].destruct + destval) <= USHRT_MAX) {
                        planet->info[playernum - 1].destruct += destval;
                    } else {
                        planet->info[playernum - 1].destruct = USHRT_MAX;
                        sprintf(buf,
                                "Planet has room for only %d destruct.\n",
                                USHRT_MAX - planet->info[playernum - 1].destruct);

                        notify(playernum, governor, buf);
                    }

                    /*
                     * Old code
                     *
                     * planet->info[playernum - 1].resource += scrapval;
                     * planet->info[playernum - 1].destruct += destval;
                     * planet->info[playernum - 1].fuel += (int)fuelval;
                     */

                    plant->popn += crewval;
                    planet->info[playernum - 1].crystals += (int)xtalval;
                    putsector(sect, planet, (int)s->land_x, (int)s->land_y);
                    free(sect);
                }

                putplanet(planet, (int)s->storbits, (int)s->pnumorbits);
            }

            kill_ship(playernum, s);
            putship(s);
            free(s);

            if (landed(s)) {
                sprintf(buf, "\nScrapped.\n");
            } else {
                sprintf(buf, "\nDestroyed.\n");
            }

            notify(playernum, governor, buf);
        } else {
            free(s);
        }

        shipno = do_shiplist(&s, &nextshipno);
    }
}
Ejemplo n.º 12
0
void cs(int playernum, int governor, int apcount)
{
    placetype where;
    planettype *planet;
    shiptype *s;
    racetype *race;

    race = races[playernum - 1];

    /* Handle cs used with options */
    if (optn) {
        /* Make new def scope */
        if (!opts['d']) {
            notify(playernum, governor, "Invalid options(s).\n");

            return;
        }

        if (argn == 2) {
            where = Getplace(playernum, governor, args[1], 0);
        } else if (argn == 1) {
            where.level = Dir[playernum - 1][governor].level;
            where.snum = Dir[playernum - 1][governor].snum;
            where.pnum = Dir[playernum - 1][governor].pnum;
            where.shipno = Dir[playernum - 1][governor].shipno;
            where.err = 0;
        } else {
            notify(playernum, governor, "Invalid usage.\n");

            return;
        }

        if (!where.err && (where.level != LEVEL_SHIP)) {
            race->governor[governor].deflevel = where.level;
            race->governor[governor].defsystem = where.snum;
            race->governor[governor].defplanetnum = where.pnum;
            putrace(race);

            sprintf(buf,
                    "New home system is %s\n",
                    Dispplace(playernum, governor, &where));

            notify(playernum, governor, buf);
        } else {
            sprintf(buf, "cs: Bad home system.\n");
            notify(playernum, governor, buf);
        }

        return;
    }

    if (argn == 2) {
        /* chdir to specified scope */
        where = Getplace(playernum, governor, args[1], 0);

        if (where.err) {
            sprintf(buf, "cs: Bad scope.\n");
            notify(playernum, governor, buf);
            Dir[playernum - 1][governor].lasty[0] = 0.0;
            Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];

            return;
        }

        /* Fix lastx, lasty coordinates */
        switch (Dir[playernum - 1][governor].level) {
        case LEVEL_UNIV:
            Dir[playernum - 1][governor].lasty[0] = 0.0;
            Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];

            break;
        case LEVEL_STAR:
            if (where.level == LEVEL_UNIV) {
                Dir[playernum - 1][governor].lastx[1] = Stars[Dir[playernum - 1][governor].snum]->xpos;
                Dir[playernum - 1][governor].lasty[1] = Stars[Dir[playernum - 1][governor].snum]->ypos;
            } else {
                Dir[playernum - 1][governor].lasty[0] = 0.0;
                Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];
            }

            break;
        case LEVEL_PLAN:
            getplanet(&planet,
                      Dir[playernum - 1][governor].snum,
                      Dir[playernum - 1][governor].pnum);

            if ((where.level == LEVEL_STAR)
                && (where.snum == Dir[playernum - 1][governor].snum)) {
                Dir[playernum - 1][governor].lastx[0] = planet->xpos;
                Dir[playernum - 1][governor].lasty[0] = planet->ypos;
            } else if (where.level == LEVEL_UNIV) {
                Dir[playernum - 1][governor].lastx[1] = Stars[Dir[playernum - 1][governor].snum]->xpos + planet->xpos;
                Dir[playernum - 1][governor].lasty[1] = Stars[Dir[playernum - 1][governor].snum]->ypos + planet->ypos;
            } else {
                Dir[playernum - 1][governor].lasty[0] = 0.0;
                Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];
            }

            free(planet);

            break;
        case LEVEL_SHIP:
            getship(&s, Dir[playernum - 1][governor].shipno);

            if (!s->docked) {
                switch (where.level) {
                case LEVEL_UNIV:
                    Dir[playernum - 1][governor].lastx[1] = s->xpos;
                    Dir[playernum - 1][governor].lasty[1] = s->ypos;

                    break;
                case LEVEL_STAR:
                    if ((s->whatorbits >= LEVEL_STAR)
                        && (s->storbits == where.snum)) {
                        /* We are going UP from the ship...change last */
                        Dir[playernum - 1][governor].lastx[0] = s->xpos - Stars[s->storbits]->xpos;
                        Dir[playernum - 1][governor].lasty[0] = s->ypos - Stars[s->storbits]->ypos;
                    } else {
                        Dir[playernum - 1][governor].lasty[0] = 0.0;
                        Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];
                    }

                    break;
                case LEVEL_PLAN:
                    if ((s->whatorbits == LEVEL_PLAN)
                        && (s->storbits == where.snum)
                        && (s->pnumorbits == where.pnum)) {
                        /* Same */
                        getplanet(&planet, (int)s->storbits, (int)s->pnumorbits);
                        Dir[playernum - 1][governor].lastx[0] = s->xpos - Stars[s->storbits]->xpos - planet->xpos;
                        Dir[playernum - 1][governor].lasty[0] = s->ypos - Stars[s->storbits]->ypos - planet->ypos;

                        free(planet);
                    } else {
                        Dir[playernum - 1][governor].lasty[0] = 0.0;
                        Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];
                    }

                    break;
                case LEVEL_SHIP:
                    Dir[playernum - 1][governor].lasty[0] = 0.0;
                    Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];

                    break;
                default:

                    break;
                }
            } else {
                Dir[playernum - 1][governor].lasty[0] = 0.0;
                Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];
            }

            free(s);

            break;
        default:

            break;
        }

        Dir[playernum - 1][governor].level = where.level;
        Dir[playernum - 1][governor].snum = where.snum;
        Dir[playernum - 1][governor].pnum = where.pnum;
        Dir[playernum - 1][governor].shipno = where.shipno;
    } else if (argn == 1) {
        /* chdir to def scope */
        Dir[playernum - 1][governor].level = race->governor[governor].deflevel;
        Dir[playernum - 1][governor].snum = race->governor[governor].defsystem;

        if (Dir[playernum - 1][governor].snum >= Sdata.numstars) {
            Dir[playernum[governor].snum] = Sdata.numstars - 1;
        }

        Dir[playernum - 1][governor].pnum = race->governor[governor].defplanetnum;

        if (Dir[playernum - 1][governor].pnum >= Stars[Dir[playernum - 1][governor].snum]->numplanets) {
            Dir[playernum - 1][governor].pnum = Stars[Dir[playernum - 1][governor].snum]->numplanets - 1;
        }

        Dir[playernum - 1][governor].shipno = 0;
        Dir[playernum - 1][governor].lasty[0] = 0.0;
        Dir[playernum - 1][governor].lastx[0] = Dir[playernum - 1][governor].lasty[0];
        Dir[playernum - 1][governor].lastx[1] = Stars[Dir[playernum - 1][governor].snum]->xpos;
        Dir[playernum - 1][governor].lasty[1] = Stars[Dir[playernum - 1][governor].snum]->ypos;

        return;
    } else {
        sprintf(buf, "cs: Bad scope.\n");
        notify(playernum, governor, buf);
    }
}
Ejemplo n.º 13
0
void orbit(playernum, int governor, int apcount)
{
    int sh;
    int i;
    int iq;
    planettype *p;
    shiptype *s;
    placetype where;
    orbitinfo oi;

    oi.DontDispStars = 0;
    oi.DontDispShips = oi.DontDispStars;
    oi.DontDispPlanets = oi.DontDispShips;
    oi.DontDispNum = -1;

    /* Find options, set flags accordingly */
    if (optn) {
        if (opts['s']) {
            oi.DontDispShips = 1;
        }

        if (opts['S']) {
            oi.Dontdispstars = 1;
        }

        if (opts['p']) {
            oi.DontDispPlanets = 1;
        }

        if (opts['d']) {
            or.DontDispNum = opts['d'];

            if (oi.DontDispNum) {
                /* Make a '1' into a '0' */
                --oi.DontDispNum;
            } else {
                sprintf(buf, "Bad number %d.\n", oi.DontDispNum);
                notify(playernum, governor, buf);
                oi.DontDispNum = -1;
            }
        }
    }

    if (argn == 1) {
        where = Getplace(playernum, governor, ":", 0);

        if (Dir[playernum - 1][governor].level == LEVEL_UNIV) {
            i = 1;
        } else {
            i = 0;
        }

        oi.Lastx = Dir[playernum - 1][governor].lastx[i];
        oi.Lasty = Dir[playernum - 1][governor].lasty[i];
        oi.Zoom = Dir[playernum - 1][governor].zoom[i];
    } else {
        where = Getplace(playernum, governor, args[argn - 1], 0);
        oi.Lasty = 0.0;
        oi.Lastx = oi.Lasty;
        oi.Zoom = 1.0;
    }

    if (where.err) {
        notify(playernum, governor, "Orbit: Error in args.\n");

        return;
    }

    /* Display CSP orbit instead, if the client can understand it */
    if (client_can_understand(playernum, governor, CSP_ORBIT_OUTPUT_INTRO)) {
        csp_orbit(playernum, governor, &oi);

        return;
    }

    /* Orbit type of map */
    notify(playernum, governor, "#");
    race = races[playernum - 1];

    switch (where.level) {
    case LEVEL_UNIV:
        for (i = 0; i < Sdata.numstars; ++i) {
            if (oi.DontdispNum != i) {
                DispStar(playernum,
                         governor,
                         LEVEL_UNIV,
                         Stars[i],
                         (int)race->God,
                         buf,
                         &oi);

                notify(playernum, governor, buf);
            }
        }

        if (!oi.DontDispShips) {
            sh = Sdata.ships;

            while (sh) {
                getship(&s, sh);

                if (oi.DontDispNum != sh) {
                    DispShip(playernum,
                             governor,
                             &where,
                             s,
                             NULL,
                             (int)race->God,
                             buf,
                             &oi);

                    notify(playernum, governor, buf);
                }

                sh = nextship(s);
                free(s);
            }
        }

        break;
    case LEVEL_STAR:
        DispStar(playernum,
                 governor,
                 LEVEL_STAR,
                 Stars[where.snum],
                 (int)race->God,
                 buf,
                 &oi);

        notify(playernum, governor, buf);

        for (i = 0; i < Stars[where.snum]->numplanets; ++i) {
            if (oi.DontDispNum != i) {
                getplanet(&p, (int)where.snum, i);

                DispPlanet(playernum,
                           governor,
                           LEVEL_STAR,
                           p,
                           Stars[where.snum]->pnames[i],
                           race,
                           buf,
                           &oi);

                notify(playernum, governor, buf);
                free(p);
            }
        }

        /*
         * Check to see if you have ships orbiting the star, if so you can see
         * enemy ships
         */
        iq = 0;

        if (race->God) {
            iq = 1;
        } else {
            sh = Stars[where.snum]->ships;

            while (sh && !iq) {
                getship(&s, sh);

                if ((s->owner == playernum)
                    && ((s->type == OTYPE_PROBE) || s->popn)) {
                    /* You are there to sight, need a crew */
                    iq = 1;
                }

                sh = nextship(s);
                free(s);
            }
        }

        if (!oi.DontDispShips) {
            sh = Stars[where].snum->ships;

            while (sh) {
                getship(&s, sh);

                if ((oi.DontDispNum != sh)
                    && ((s->owner == playernum) || (s->type == STYPE_MINEF))) {
                    if ((s->owner == playernum) || (iq == 1)) {
                        DispShip(playernum,
                                 governor,
                                 &where,
                                 s,
                                 NULL,
                                 (int)race->God,
                                 buf,
                                 &oi);

                        notify(playernum, governor, buf);
                    }
                }

                sh = nextship(s);
                free(s);
            }
        }

        break;
    case LEVEL_PLAN:
        getplanet(&p, (int)where.snum, (int)where.pnum);

        DispPlanet(playernum,
                   governor,
                   LEVEL_PLAN,
                   p,
                   Stars[where.snum]->pnames[where.pnum],
                   race,
                   buf,
                   &oi);

        notify(playernum, governor, buf);

        /*
         * Check to see if you have ships landed or orbiting the planet, if so
         * you can see orbiting enemy ships
         */
        iq = 0;
        sh = p->ships;

        while (sh && !iq) {
            getship(&s, sh);

            if ((s->owner == playernum)
                && ((s->type == OTYPE_PROBE) || s->popn)) {
                /* You are there to sight, need a crew */
                iq = 1;
            }

            sh = nextship(s);
            free(s);
        }

        /* End check */
        if (!oi.DontDispShips) {
            sh = p->ships;

            while (sh) {
                getship(&s, sh);

                if (oi.DontDispNum != sh) {
                    if (!landed(s)) {
                        if ((s->owner == playernum) || (iq == 1)) {
                            DispShip(playernum,
                                     governor,
                                     &where,
                                     s,
                                     p,
                                     (int)race->God,
                                     buf,
                                     &oi);

                            notify(playernum, governor, buf);
                        }
                    }
                }

                sh = nextship(s);
                free(s);
            }
        }

        free(p);

        break;
    default:
        notify(playernum, governor, "Bad scope.\n");

        return;
    }

    notify(playernum, governor, "\n");
}
Ejemplo n.º 14
0
/* highlight the captain who is waiting */
static void inl_draft_highlight_down(struct player *k)
{
  getship(&k->p_ship, SCOUT);
  god(k->p_no, "Draft captain, the other captain has the pick, standby.");
}
Ejemplo n.º 15
0
void
plane_sona(struct emp_qelem *plane_list, int x, int y,
	   struct shiplist **head)
{
    struct plnstr *pp;
    struct plchrstr *pcp;
    struct mchrstr *tmcp;
    struct shpstr *targ, s;
    struct natstr *natp;
    struct emp_qelem *qp;
    struct emp_qelem *next;
    struct plist *ip;
    struct sctstr sect;
    int found = 0;
    int range, i, vis;
    int pingrange;
    int vrange;
    int dist;

    getsect(x, y, &sect);
    if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
	return;
    for (qp = plane_list->q_forw; qp != plane_list; qp = next) {
	next = qp->q_forw;
	ip = (struct plist *)qp;
	pp = &ip->plane;
	pcp = ip->pcp;
	if (!(pcp->pl_flags & P_A))	/* if it isn't an ASW plane */
	    continue;
	range = (int)techfact(pp->pln_tech, (100.0 - pln_acc(pp)) / 10.0);
	for (i = 0; getship(i, &s); i++) {
	    targ = &s;
	    if (targ->shp_own == pp->pln_own || targ->shp_own == 0)
		continue;
	    if (on_shiplist(targ->shp_uid, *head))
		continue;
	    tmcp = &mchr[(int)targ->shp_type];
	    if (!(tmcp->m_flags & M_SUB))
		continue;
	    if (!pct_chance(pln_identchance(pp, shp_hardtarget(targ),
					    EF_SHIP)))
		continue;
	    vis = shp_visib(targ);
	    pingrange = MAX(vis, 10) * range / 10;
	    vrange = pingrange * (pp->pln_effic / 200.0);
	    dist = mapdist(targ->shp_x, targ->shp_y, x, y);
	    pingrange = (MAX(pingrange, 2) * targ->shp_effic);
	    pingrange = roundavg(pingrange / 100.0);
	    if (dist > pingrange)
		continue;
	    if (tmcp->m_flags & M_SONAR && targ->shp_own) {
		natp = getnatp(targ->shp_own);
		if (natp->nat_flags & NF_SONAR)
		    wu(0, targ->shp_own,
		       "Sonar ping from %s detected by %s!\n",
		       xyas(x, y, targ->shp_own), prship(targ));
	    }
	    if ((dist > vrange))
		continue;
	    add_shiplist(targ->shp_uid, head);
	    if (!found) {
		pr("Sonar contact in %s\n", xyas(x, y, player->cnum));
		found = 1;
	    }
	    if (relations_with(targ->shp_own, pp->pln_own) < FRIENDLY &&
		!pct_chance(pln_identchance(pp, shp_hardtarget(targ),
					    EF_SHIP)))
		if (!pct_chance(pln_identchance(pp, shp_hardtarget(targ),
						EF_SHIP)))
		    pr("sub #%d %s\n", targ->shp_uid,
		       xyas(targ->shp_x, targ->shp_y, player->cnum));
		else
		    pr("%s %s\n", prship(targ),
		       xyas(targ->shp_x, targ->shp_y, player->cnum));
	    else
		pr("%s %s @ %s\n", cname(targ->shp_own), prship(targ),
		   xyas(targ->shp_x, targ->shp_y, player->cnum));
	}
    }
    if (found)
	pr("\n");
}
Ejemplo n.º 16
0
void do_prompt(int playernum, int governor)
{
    shiptype *s;
    shiptype *s2;

    if (client_can_understand(playernum, governor, CSP_SCOPE_COMMAND)) {
        CSP_prompt(playernum, governor);
    } else {
        if (Dir[playernum - 1][governor].level == LEVEL_UNIV) {
            sprintf(Dir[playernum - 1][governor].prompt,
                    " ( [%d] / )\n",
                    Sdata.AP[playernum - 1]);
        } else if (Dir[playernum - 1][governor].level == LEVEL_STAR) {
            sprintf(Dir[playernum - 1][governor].prompt,
                    " ( [%d] /%s )\n",
                    Stars[Dir[playernum - 1][governor].snum]->AP[playernum - 1],
                    Stars[Dir[playernum - 1][governor].snum]->name);
        } else if (Dir[playernum - 1][governor].level == LEVEL_PLAN) {
            sprintf(Dir[playernum - 1][governor].prompt,
                    " ( [%d] /%s/%s )\n",
                    Stars[Dir[playernum - 1][governor].snum]->AP[playernum - 1],
                    Stars[Dir[playernum - 1][governor].snum]->name,
                    Stars[Dir[playernum - 1][governor].snum]->pnames[Dir[playernum - 1][governor].pnum]);
        } else if (Dir[playernum - 1][governor].level == LEVEL_SHIP) {
            getship(&s, Dir[playernum - 1][governor].shipno);

            switch (s->whatorbits) {
            case LEVEL_UNIV:
                sprintf(Dir[playernum - 1][governor].prompt,
                        " ( [%d] /#%d )\n",
                        Sdata.AP[playernum - 1],
                        Dir[playernum - 1][governor].shipno);

                break;
            case LEVEL_STAR:
                sprintf(Dir[playernum - 1][governor].prompt,
                        " ( [%d] /%s/#%d )\n",
                        Stars[s->storbits]->AP[playernum - 1],
                        Stars[s->storbits]->name,
                        Dir[playernum - 1][governor].shipno);

                break;
            case LEVEL_PLAN:
                sprintf(Dir[playernum - 1][governor].prompt,
                        " ( [%d] /%s/%s/#%d )\n",
                        Stars[s->storbits]->AP[playernum - 1],
                        Stars[s->storbits]->name,
                        Stars[s->storbits]->pnames[Dir[playernum - 1][governor].pnum],
                        Dir[playernum - 1][governor].shipno);

                break;
            case LEVEL_SHIP:
                /*
                 * I put this mess in because of non-functioning prompts when
                 * you are in a ship within a ship, or deeper. I am certain this
                 * can be done more elegantly (a lot more) but I don't feel like
                 * trying that right now. Right now I want it to function.
                 * Maarten
                 */
                getship(&s2, (int)s->destshipno);

                switch (s2->whatorbits) {
                case LEVEL_UNIV:
                    sprintf(Dir[playernum - 1][governor].prompt,
                            " ( [%d] /#%d/#%d )\n",
                            Sdata.AP[playernum - 1],
                            s->destshipno,
                            Dir[playernum - 1][governor].shipno);

                    break;
                case LEVEL_STAR:
                    sprintf(Dir[playernum - 1][governor].prompt,
                            " ( [%d] /%s/#%d/#%d )\n",
                            Stars[s->storbits]->AP[playernum - 1],
                            Stars[s->storbits]->name,
                            s->destshipno,
                            Dir[playernum - 1][governor].shipno);

                    break;
                case LEVEL_PLAN:
                    sprintf(Dir[playernum - 1][governor].prompt,
                            " ( [%d] /%s/%s/#%d/#%d )\n",
                            Stars[s->storbits]->AP[playernum - 1],
                            Stars[s->storbits]->name,
                            Stars[s->storbits]->pnames[Dir[playernum - 1][governor].pnum],
                            s->destshipno,
                            Dir[playernum - 1][governor].shipno);

                    break;
                case LEVEL_SHIP:
                    while (s2->whatorbits == LEVEL_SHIP) {
                        free(s2);
                        getship(&s2, (int)s2->destshipno);
                    }

                    switch (s2->whatorbits) {
                    case LEVEL_UNIV:
                        sprintf(Dir[playernum - 1][governor].prompt,
                                " ( [%d] / /../#%d/#%d )\n",
                                Sdata.AP[playernum - 1],
                                s->destshipno,
                                Dir[playernum - 1][governor].shipno);

                        break;
                    case LEVEL_STAR:
                        sprintf(Dir[playernum - 1][governor].prompt,
                                " ( [%d] /%s /../#%d/#%d )\n",
                                Stars[s->storbits]->AP[playernum - 1],
                                Stars[s->storbits]->name,
                                s->destshipno,
                                Dir[playernum - 1][governor].shipno);

                        break;
                    case LEVEL_PLAN:
                        sprintf(Dir[playernum - 1][governor].prompt,
                                " ( [%d] /%s/%s /../#%d/#%d )\n",
                                Stars[s->storbits]->AP[playernum -1],
                                Stars[s->storbits]->name,
                                Stars[s->storbits]->pnames[Dir[playernum - 1][governor].pnum],
                                s->destshipno,
                                Dir[playernum - 1][governor].shipno);

                        break;
                    default:

                        break;
                    }

                    free(s2);

                    break;
                default:

                    break;
                }
            }

            free(s);
        }
    }
}
Ejemplo n.º 17
0
int main(int argc, char **argv)
{
  int player;
  char buf[1000];
  int c;

  if (argc < 2)
    Usage();
  getpath();

  openmem(0);

  player=atoi(argv[1]);
  if ((player == 0) && (*argv[1] != '0')) {
    c = *argv[1];
    if (c >= 'a' && c <= 'z')
      player = c - 'a' + 10;
    else {
      Usage();
    }
  }
  if (player >= MAXPLAYER) {
    printf("MAXPLAYER is set to %d, and you want %d?\n", 
	   MAXPLAYER, player);
    exit(1);
  }

  /* request to free slot? */
  if (argc > 2) {
    if (*argv[2] == 'F') {
      int pid;
      pid = players[player].p_process;
      players[player].p_disconnect = BADVERSION_DENIED;
      usleep(200000); /* guarantee an update will occur */
      if (players[player].p_status == PFREE) exit(0); /* slot free, he went */
      if (pid != players[player].p_process) exit(0); /* pid changed, he went */
      if (players[player].p_process > 1) { /* p_disconnect must have failed */
	if (kill(players[player].p_process, SIGTERM) == 0)
	  exit(0);
      }
      /* if we have no pid_t, or the pid_t was wrong, free slot */
      freeslot(&players[player]);
      exit(0);
    }
  }

  if (players[player].p_status != PALIVE) {
    if(players[player].p_status != POBSERV) {
      printf("Slot is not alive.\n");
      exit(1);
    }
  }

  if (argc > 2)
    switch (*argv[2]) {
    case 'T': { /* change team */
      int team;
	      
      switch (argv[2][1]) {
      case 'f': team = 1; break;
      case 'r': team = 2; break;
      case 'k': team = 4; break;
      case 'o': team = 8; break;
      default:  team = 0;
      }	    
      change_team_quietly(players[player].p_no, team, players[player].p_team);
    }
    break;
    case 'e': /* eject (GHOSTTIME applies in daemon) */
      sprintf(buf, "GOD->ALL  %s has been ejected from the game.", 
	      players[player].p_longname);		    
      players[player].p_whydead=KQUIT;
      players[player].p_explode=10;
      players[player].p_status=3;
      players[player].p_whodead=0;
      amessage(buf, 0, MALL);
      break;
    case 't': /* teleport */
      switch(argv[2][1]) {
      case 'f':
	p_x_y_set(&players[player], planets[0].pl_x, planets[0].pl_y);
	break;
      case 'r':
	p_x_y_set(&players[player], planets[10].pl_x, planets[10].pl_y);
	break;
      case 'k':
	p_x_y_set(&players[player], planets[20].pl_x, planets[20].pl_y);
	break;
      case 'o':
	p_x_y_set(&players[player], planets[30].pl_x, planets[30].pl_y);
	break;
      case 'c':
	p_x_y_set(&players[player], GWIDTH/2, GWIDTH/2);
	break;
      default:
	printf("Valid teleports: frkoc.\n");
	exit(1);
      }
      break;
    case 's': /* ship type change */
      switch (argv[2][1]) {
      case 'a': refit(&players[player], ASSAULT); break;
      case 'b': refit(&players[player], BATTLESHIP); break;
      case 'c': refit(&players[player], CRUISER); break;
      case 'd': refit(&players[player], DESTROYER); break;
      case 'g': refit(&players[player], SGALAXY); break;
      case 's': refit(&players[player], SCOUT); break;
      case 'o': refit(&players[player], STARBASE); break;
      case 'A': refit(&players[player], ATT); break;
      case 'S': 
	getship(&players[player].p_ship, SCOUT);
	players[player].p_ship.s_torpdamage = 1;
	players[player].p_ship.s_torpfuse = 8;
	players[player].p_ship.s_phaserdamage = 1;
	players[player].p_ship.s_plasmadamage = 1;
	players[player].p_ship.s_plasmaspeed = 1;
	players[player].p_ship.s_plasmaturns = 1;
	players[player].p_ship.s_maxshield = 750;
	break;
      default:
	printf("Valid ship types: abcdgsoAS.\n");
	exit(1);
	break;
      }
      players[player].p_damage = 0;
      players[player].p_shield = players[player].p_ship.s_maxshield;
      players[player].p_wtemp = 0;
      players[player].p_etemp = 0;
      players[player].p_fuel = players[player].p_ship.s_maxfuel;
      if (argv[2][1] == 'o') players[player].p_flags |= PFDOCKOK;
      break;
    case 'p':		/* puck? */
      players[player].p_ship.s_tractstr = 1;
      players[player].p_ship.s_torpdamage = -1;
      players[player].p_ship.s_plasmadamage = -1;
      players[player].p_ship.s_phaserdamage = -1;
      players[player].p_hostile = 0;
      players[player].p_swar = 0;
      players[player].p_war = 0;
      players[player].p_team = 0;	/* indep */
      players[player].p_ship.s_type = SCOUT;
      players[player].p_ship.s_mass = 200;
      players[player].p_ship.s_repair = 30000;
      break;
    case 'S':		/* super ship */
      players[player].p_ship.s_maxshield = 750;
      players[player].p_shield = 750;
      players[player].p_ship.s_maxdamage = 750;
      players[player].p_damage = 0;
      players[player].p_ship.s_maxegntemp = 5000;
      players[player].p_etemp = 0;
      break;
    case 'D':		/* demote, but not beyond ensign */
      if(players[player].p_stats.st_rank == 0)
	players[player].p_stats.st_rank++;

      --players[player].p_stats.st_rank;
      break;
    case 'P':		/* promote, but not beyond admiral */
      if( players[player].p_stats.st_rank < (NUMRANKS - 1) ) 
	++players[player].p_stats.st_rank;
      break;
    case 'k':		/* kill increment */
      if (strlen(argv[2]) > 1)
        players[player].p_kills += atoi(argv[2]+1);
      else
        players[player].p_kills += 1.0;
      break;
    case 'a':		/* army increment */
      if (strlen(argv[2]) > 1) 
	players[player].p_armies = atoi(argv[2]+1);
      else 
	players[player].p_armies += 6;
      break;
    case 'C':		/* clock surrender reset */
      teams[players[player].p_team].te_surrender = 6;
      break;
    case 'h':		/* harm */
      players[player].p_shield = 0;
      players[player].p_damage = players[player].p_ship.s_maxdamage/2;
      break;
    case 'H':           /* hack */
      {
      struct player *me = &players[player];
      /* make independent and hostile to only prior team */
      int team = players[player].p_team;
      players[player].p_hostile = team;
      players[player].p_swar = team;
      players[player].p_war = team;
      players[player].p_team = 0;
      sprintf(players[player].p_mapchars, "%c%c", 
	      teamlet[players[player].p_team], shipnos[player]);
      sprintf(players[player].p_longname, "%s (%s)", 
	      players[player].p_name, players[player].p_mapchars);
      /* cripple */
      players[player].p_shield = 0;
      players[player].p_damage = players[player].p_ship.s_maxdamage/2;
      /* raise shields */
      players[player].p_flags |= PFSHIELD;
      players[player].p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
      /* break tractors and decloak */
      me->p_flags &= ~(PFTRACT | PFPRESS);
      me->p_flags &= ~PFCLOAK;
      /* set speed 0 */
      me->p_desspeed = 0;
      bay_release(me);
      me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
      /* make unable to act */
      players[player].p_flags |= PFTWARP;
      /* show as puck */
      players[player].p_ship.s_type = SCOUT;
      }
      break;
    case 'u':           /* raise shields */
      players[player].p_flags |= PFSHIELD;
      players[player].p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
      break;
    case 'd':           /* lower shields */
      players[player].p_flags &= ~(PFSHIELD);
      break;
    case 'R':		/* robot kill? */
      if (players[player].p_flags & PFROBOT) {
	players[player].p_ship.s_type = STARBASE;
	players[player].p_whydead=KPROVIDENCE;
	players[player].p_explode=10;
	players[player].p_status=3;
	players[player].p_whodead=0;
      }
      break;
    case 'L':		/* starbase loss adjust */
#ifdef LTD_STATS
#ifndef LTD_PER_RACE
      players[player].p_stats.ltd[0][LTD_SB].deaths.total--;
#endif
#else
      players[player].p_stats.st_sblosses--;
#endif
      break;
    case 'r':           /* repair ship */
      p_heal(&players[player]);
      break;
    case 'f':		/* flatten kills / armies */
      players[player].p_kills = 0;
      players[player].p_armies = 0;
      break;
    case 'n':		/* toggle carry flag */
      players[player].p_no_pick = !players[player].p_no_pick;
      sprintf(buf, "GOD->%s  %s %s pick up armies",
              team_code(players[player].p_team),
              players[player].p_longname,
              players[player].p_no_pick ?
                  "is no longer able to" : "can once again");
      amessage(buf, players[player].p_team, MTEAM);
      break;
    default:
      Usage();
    }			/* end switch */
  else {
    sprintf(buf, "GOD->ALL  %s was utterly obliterated.", 
	    players[player].p_longname);
    players[player].p_ship.s_type=STARBASE;
    players[player].p_whydead=KPROVIDENCE;
    players[player].p_explode=10;
    players[player].p_status=3;
    players[player].p_whodead=0;
    amessage(buf, 0, MALL);
  }
  return 0;
}
Ejemplo n.º 18
0
int
pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
{
    struct plchrstr *pcp;
    struct plnstr *pp;
    int load, needed;
    struct lndstr land;
    struct shpstr ship;
    struct sctstr sect;
    i_type itype;
    short *item;
    int own;
    int abandon_needed;

    pp = &plp->plane;
    pcp = plp->pcp;
    if (pp->pln_ship >= 0) {
	getship(pp->pln_ship, &ship);
	plp->pstage = ship.shp_pstage;
	item = ship.shp_item;
	own = ship.shp_own;
    } else if (pp->pln_land >= 0) {
	getland(pp->pln_land, &land);
	plp->pstage = land.lnd_pstage;
	item = land.lnd_item;
	own = land.lnd_own;
    } else {
	getsect(pp->pln_x, pp->pln_y, &sect);
	plp->pstage = sect.sct_pstage;
	item = sect.sct_item;
	own = sect.sct_oldown;
    }
    if (pcp->pl_fuel > item[I_PETROL]) {
	pr("%s not enough petrol there!\n", prplane(pp));
	return -1;
    }
    item[I_PETROL] -= pcp->pl_fuel;
    load = pln_load(pp);
    itype = I_NONE;
    switch (mission) {
    case 's':		/* strategic bomb */
    case 'p':		/* pinpoint bomb */
	itype = I_SHELL;
	break;
    case 't':		/* transport */
	if (!(pcp->pl_flags & P_C) || !ip)
	    break;
	itype = ip->i_uid;
	load *= 2;
	break;
    case 'm':		/* mine */
	if ((pcp->pl_flags & P_MINE) == 0)
	    break;
	itype = I_SHELL;
	load *= 2;
	break;
    case 'd':		/* drop */
	if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
	    break;
	itype = ip->i_uid;
	if (pcp->pl_flags & P_V)
	    load *= 2;
	break;
    case 'a':		/* paradrop */
	if (!(pcp->pl_flags & P_P))
	    break;
	itype = I_MILIT;
	if (pcp->pl_flags & P_V)
	    load *= 2;
	break;
    case 'r':		/* reconnaissance */
    case 'e':		/* escort */
	load = 0;
	break;
    case 'i':		/* missile interception */
	if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
			|| !(pcp->pl_flags & (P_N | P_O))))
	    break;
	if (load)
	    itype = I_SHELL;
	break;
    default:
	CANT_REACH();
	load = 0;
    }

    if (itype != I_NONE) {
	needed = load / ichr[itype].i_lbs;
	if (needed <= 0) {
	    pr("%s can't contribute to mission\n", prplane(pp));
	    return -1;
	}
	if (nuk_on_plane(pp) >= 0) {
	    if (mission == 's' || mission == 't')
		needed = 0;
	    else {
		pr("%s can't fly this mission"
		   " while it is carrying a nuclear weapon",
		   prplane(pp));
		return -1;
	    }
	}
	if (itype == I_CIVIL && pp->pln_own != own) {
	    pr("You don't control those civilians!\n");
	    return -1;
	}
#if 0
	/* Supply is broken somewhere, so don't use it for now */
	if (itype == I_SHELL && item[itype] < needed)
	    item[itype] += supply_commod(plp->plane.pln_own,
					 plp->plane.pln_x,
					 plp->plane.pln_y,
					 I_SHELL, needed);
#endif
	if (pp->pln_ship >= 0 || pp->pln_land >= 0)
	    abandon_needed = 0;
	else
	    abandon_needed = !!would_abandon(&sect, itype, needed, NULL);
	if (item[itype] < needed + abandon_needed) {
	    pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
	    return -1;
	}
	item[itype] -= needed;
	plp->load = needed;
    }

    if (pp->pln_ship >= 0) {
	if (pp->pln_own != ship.shp_own) {
	    wu(0, ship.shp_own,
	       "%s %s prepares for takeoff from ship %s\n",
	       cname(pp->pln_own), prplane(pp), prship(&ship));
	}
	putship(ship.shp_uid, &ship);
    } else if (pp->pln_land >= 0) {
	if (pp->pln_own != land.lnd_own) {
	    wu(0, land.lnd_own,
	       "%s %s prepares for takeoff from unit %s\n",
	       cname(pp->pln_own), prplane(pp), prland(&land));
	}
	putland(land.lnd_uid, &land);
    } else {
	if (pp->pln_own != sect.sct_own) {
	    wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
	       cname(pp->pln_own), prplane(pp),
	       xyas(sect.sct_x, sect.sct_y, sect.sct_own));
	}
	putsect(&sect);
    }
    return 0;
}
Ejemplo n.º 19
0
int
pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
{
    struct shpstr ship;
    struct lndstr land;
    struct sctstr sect;
    struct plchrstr *pcp = plchr + pp->pln_type;

    if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
	noisy = 0;

    if (pp->pln_ship >= 0) {
	/* ship: needs to be own or allied, efficient */
	if (!getship(pp->pln_ship, &ship)) {
	    CANT_REACH();
	    return 0;
	}
	if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
	    if (noisy)
		pr("(note) An ally does not own the ship %s is on\n",
		   prplane(pp));
	    return 0;
	}
	if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
	    return 0;

    } else if (pp->pln_land >= 0) {
	/* land: needs to be own or allied, efficient, not embarked */
	if (!getland(pp->pln_land, &land)) {
	    CANT_REACH();
	    return 0;
	}
	if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
	    if (noisy)
		pr("(note) An ally does not own the unit %s is on\n",
		   prplane(pp));
	    return 0;
	}
	if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
	    return 0;
	if (land.lnd_ship >= 0 || land.lnd_land >= 0)
	    return 0;

    } else {
	/* sector: needs to be own or allied, efficient airfield */
	if (!getsect(pp->pln_x, pp->pln_y, &sect)) {
	    CANT_REACH();
	    return 0;
	}

	if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
	    if (noisy)
		pr("(note) An ally does not own the sector %s is in\n",
		   prplane(pp));
	    return 0;
	}
	/* need airfield unless VTOL */
	if ((pcp->pl_flags & P_V) == 0) {
	    if (sect.sct_type != SCT_AIRPT) {
		if (noisy)
		    pr("%s not at airport\n", prplane(pp));
		return 0;
	    }
	    if (sect.sct_effic < 40) {
		if (noisy)
		    pr("%s is not 40%% efficient, %s can't take off from there.\n",
		       xyas(sect.sct_x, sect.sct_y, player->cnum),
		       prplane(pp));
		return 0;
	    }
	    if (!oneway && sect.sct_effic < 60) {
		if (noisy)
		    pr("%s is not 60%% efficient, %s can't land there.\n",
		       xyas(sect.sct_x, sect.sct_y, player->cnum),
		       prplane(pp));
		return 0;
	    }
	}
    }

    return 1;
}
Ejemplo n.º 20
0
void
pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
	    int cno)
{
    struct emp_qelem *qp;
    struct plist *plp;
    int amt;
    struct sctstr sect;
    struct shpstr ship;
    int there;
    int max;
    int pstage;

    if (!ip)
	return;
    if (cno < 0) {
	getsect(tx, ty, &sect);
	if (!sect.sct_own) {
	    if (sect.sct_type == SCT_WATER)
		pr("Your %s sink like a rock!\n", ip->i_name);
	    else
		pr("Your %s vanish without a trace.\n", ip->i_name);
	    return;
	}
	if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
	    pr("You don't own %s!  Cargo jettisoned...\n",
	       xyas(tx, ty, player->cnum));
	    return;
	}
	if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
	    pr("%s is occupied.  Your civilians suffer from identity crisis and die.\n",
	       xyas(tx, ty, player->cnum));
	    return;
	}
	there = sect.sct_item[ip->i_uid];
	max = ITEM_MAX;
	pstage = sect.sct_pstage;
    } else {
	getship(cno, &ship);
	there = ship.shp_item[ip->i_uid];
	max = mchr[ship.shp_type].m_item[ip->i_uid];
	pstage = ship.shp_pstage;
    }

    amt = 0;
    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
	plp = (struct plist *)qp;
	amt += plp->load;
	if (plp->load
	    && plp->pstage == PLG_INFECT && pstage == PLG_HEALTHY)
	    pstage = PLG_EXPOSED;
    }

    there += amt;
    if (there > max) {
	pr("%d excess %s discarded\n", there - max, ip->i_name);
	amt -= there - max;
	there = max;
    }
    pr("%d %s landed safely", amt, ip->i_name);
    if (cno < 0) {
	sect.sct_item[ip->i_uid] = there;
	sect.sct_pstage = pstage;
	if (sect.sct_own != player->cnum)
	    wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
	       cname(player->cnum), amt, ip->i_name,
	       xyas(tx, ty, sect.sct_own));
	pr(" at %s\n", xyas(tx, ty, player->cnum));
	putsect(&sect);
    } else {
	ship.shp_item[ip->i_uid] = there;
	ship.shp_pstage = pstage;
	if (ship.shp_own != player->cnum)
	    wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
	       cname(player->cnum), amt, ip->i_name, ship.shp_uid);
	pr(" on carrier #%d\n", ship.shp_uid);
	putship(ship.shp_uid, &ship);
    }
}
Ejemplo n.º 21
0
static int
tend_land(struct shpstr *tenderp, char *units)
{
    struct nstr_item lni;
    struct nstr_item targets;
    struct shpstr target;
    struct lndstr land;
    char buf[1024];

    if (!snxtitem(&lni, EF_LAND, units, NULL))
	return RET_SYN;

    while (nxtitem(&lni, &land)) {
	if (!player->owner)
	    continue;
	if (land.lnd_ship != tenderp->shp_uid) {
	    pr("%s is not on %s!\n", prland(&land), prship(tenderp));
	    continue;
	}
	if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) {
	    pr("%s does not have \"assault\" capability and can't be tended\n",
	       prland(&land));
	    continue;
	}
	if (!snxtitem(&targets, EF_SHIP,
		      player->argp[4], "Ship to be tended? "))
	    return RET_FAIL;
	if (!check_ship_ok(tenderp) || !check_land_ok(&land))
	    return RET_SYN;
	while (nxtitem(&targets, &target)) {
	    if (!player->owner
		&& relations_with(target.shp_own, player->cnum) < FRIENDLY)
		continue;
	    if (target.shp_uid == tenderp->shp_uid)
		continue;
	    if (tenderp->shp_x != target.shp_x ||
		tenderp->shp_y != target.shp_y)
		continue;

	    /* Fit unit on ship */
	    getship(target.shp_uid, &target);

	    if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
		(!((mchr[(int)target.shp_type].m_flags & M_SUPPLY) &&
		   (!(mchr[(int)target.shp_type].m_flags & M_SUB))))) {
		pr("You can only load light units onto ships,\n"
		   "unless the ship is a non-sub supply ship\n"
		   "%s not tended\n", prland(&land));
		continue;
	    }

	    if ((mchr[(int)target.shp_type].m_flags & M_SUB) &&
		(lchr[(int)land.lnd_type].l_flags & L_SPY) &&
		!mchr[(int)target.shp_type].m_nland) {
		if (shp_nland(&target) > 1) {
		    pr("%s doesn't have room for more than two spy units!\n",
		       prship(&target));
		    continue;
		}
	    } else if (shp_nland(&target) >= mchr[target.shp_type].m_nland) {
		if (mchr[(int)target.shp_type].m_nland)
		    pr("%s doesn't have room for any more land units!\n",
		       prship(&target));
		else
		    pr("%s doesn't carry land units!\n", prship(&target));
		continue;
	    }
	    pr("%s transferred from %s to %s\n",
	       prland(&land), prship(tenderp), prship(&target));
	    sprintf(buf, "loaded on your %s at %s",
		    prship(&target), xyas(target.shp_x, target.shp_y,
					  target.shp_own));
	    gift(target.shp_own, player->cnum, &land, buf);
	    land.lnd_ship = target.shp_uid;
	    land.lnd_harden = 0;
	    putland(land.lnd_uid, &land);
	    expose_ship(tenderp, &target);
	    putship(target.shp_uid, &target);
	    putship(tenderp->shp_uid, tenderp);
	}
    }
    return 0;
}
Ejemplo n.º 22
0
void DispShip(int playernum,
              int governor,
              placetype *where,
              shiptype *ship,
              planettype *pl,
              int god,
              char *string,
              orbitinfo *oi)
{
    int x;
    int y;
    int wm;
    int stand;
    shiptype *aship;
    planettype *apl;
    double xt;
    double yt;
    double slope;

    if (!ship->alive) {
        return;
    }

    *string = '\0';

    switch (where->level) {
    case LEVEL_PLAN:
        x = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->xpos - (Stars[where->snum]->xpos + pl->xpos) - oi->Lastx)) / (PLORBITSIZE * oi->Zoom)));
        y = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->ypos - (Stars[where->snum]->ypos + pl->ypos) - oi->Lasty)) / (PLORBITSIZE * oi->zoom)));

        break;
    case LEVEL_STAR:
        x = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->xpos - Stars[where->snum]->xpos - oi->Lastx)) / (SYSTEMSIZE * oi->Zoom)));
        y = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->ypos - Stars[where->snum]->ypos - oi->Lasty)) / (SYSTEMSIZE * oi->Zoom)));

        break;
    case LEVEL_UNIV:
        x = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->xpos - oi->Lastx)) / (UNIVSIZE * oi->Zoom)));
        y = (int)(ORBIT_SCALE + ((ORBIT_SCALE * (ship->ypos - oi->Lasty)) / (UNIVSIZE * oi->zoom)));

        break;
    default:
        notify(playernum, governor, "WHOA! Error in DispShip.\n");

        return;
    }

#ifdef USE_VN
    int n;
    int xa;
    int ya;
    float fac;
#endif

    switch (ship->type) {
    case STYPE_MIRROR:
        if (ship->special.aimed_at.level == LEVEL_STAR) {
            xt = Stars[ship->special.aimed_at.snum]->xpos;
            yt = Stars[ship->special.aimed_at.snum]->ypos;
        } else if (ship->special.aimed_at.level == LEVEL_PLAN) {
            if ((where->level == LEVEL_PLAN)
                && (ship->special.aimed_at.pnum == where->pnum)) {
                /* Same planet */
                xt = Stars[ship->special.aimed_at.snum]->xpos + pl->xpos;
                yt = Stars[ship->special.aimed_at.snum]->ypos + pl->ypos;
            } else {
                /* Different planet */
                getplanet(&apl, (int)where->snum, (int)where->pnum);
                xt = Stars[ship->special.aimed_at.snum]->xpos + apl->xpos;
                yt = Stars[ship->special.aimed_at.snum]->ypos + apl->ypos;
                free(apl);
            }
        } else if (ship->special.aimed_at.level == LEVEL_SHIP) {
            if (getship(&aship, (int)ship->special.aimed_at.shipno)) {
                xt = aship->xpos;
                yt = aship->ypos;
                free(aship);
            } else {
                yt = 0.0;
                xt = yt;
            }
        } else {
            yt = 0.0;
            xt = yt;
        }

        wm = 0;

        if (xt == ship->xpos) {
            if (yt > ship->ypos) {
                wm = 5;
            } else {
                wm = 1;
            }
        } else {
            slope = (yt - ship->ypos) / (xt - ship->xpos);

            if (yt == ship->ypos) {
                if (xt > ship->xpos) {
                    wm = 3;
                } else {
                    wm = 7;
                }
            } else if (yt > ship->ypos) {
                if (slope < -2.414) {
                    wm = 5;
                }

                if (slope > -2.414) {
                    wm = 6;
                }

                if (slope > -0.414) {
                    wm = 7;
                }

                if (slope > 0.000) {
                    wm = 3;
                }

                if (slope > 0.414) {
                    wm = 4;
                }

                if (slope > 2.414) {
                    wm = 5;
                }
            } else if (yt < ship->ypos) {
                if (slope < -2.414) {
                    wm = 1;
                }

                if (slope > -2.414) {
                    wm = 2;
                }

                if (slope > -0.414) {
                    wm = 3;
                }

                if (slope > 0.000) {
                    wm = 7;
                }

                if (slope > 0.414) {
                    wm = 8;
                }

                if (slope > 2.414) {
                    wm = 1;
                }
            }
        }

        /* Magnification */
        if ((x >= 0) && (y >= 0)) {
            if (race->governor[governor].toggle.color) {
                sprintf(string,
                        "%c %d %d %d %c %c %d;",
                        (char)(ship->owner + '?'),
                        x,
                        y,
                        wm,
                        Shipltrs[ship->type],
                        (char)(ship->owner + '?'),
                        ship->number);
            } else {
                if (ship->owner == race->governor[governor].toggle.highlight) {
                    stand = 1;
                } else {
                    stand = 0;
                }

                sprintf(string,
                        "%d %d %d %d %c %d %d;",
                        stand,
                        x,
                        y,
                        wm,
                        Shipltrs[ship->type],
                        stand,
                        ship->number);
            }
        }

        break;
    case OTYPE_CANIST:
    case OTYPE_GREEN:

        break;

#ifdef USE_VN
    case OTYPE_VN:
        wm = 0;

        /* Make a cloud of Von Neumann machines */
        if ((ship->whatorbits != LEVEL_UNIV)
            || (ship->owner == playernum)
            || god) {
            fac = ship->number /
                ((ship->whatorbits == LEVEL_UNIV ? 100.0
                  : (ship->whatorbits == LEVEL_STAR ? 30.0
                     : 4.0)) * oi->Zoom);

            for (n = 1; (n <= ship->number) && (n < 267); ++n) {
                xa = int_rand(x - (int)fac, x + (int)fac);
                ya = int_rand(y - (int)fac, y + (int)fac);

                if ((xa >= 0) && (ya >= 0)) {
                    if (race->governor[governor].toggle.color) {
                        sprintf(temp,
                                "%c %d %d %d %c %c %d;",
                                (char)(ship->owner + 48),
                                xa,
                                ya,
                                wm,
                                Shipltrs[ship->type],
                                (char)(ship->owner + 48),
                                ship->number);
                    } else {
                        if (ship->owner == race->governor[governor].toggle.highlight) {
                            stand = 1;
                        } else {
                            stand = 0;
                        }

                        sprintf(temp,
                                "%d %d %d %d %c %d %d;",
                                stand,
                                xa,
                                ya,
                                wm,
                                Shipltrs[ship->type],
                                stand,
                                ship->number);
                    }

                    strcat(string, temp);
                }
            }
        }

        break;
#endif
    default:
        /* Make sure ship is not cloaked if not ours */
        if ((ship->owner != playernum) && ship->cloaked) {
            return;
        }

        /* Other ships can only be seen when in system */
        wm = 0;

        if ((ship->whatorbits != LEVEL_UNIV)
            || ((ship->owner == playernum) || god)) {
            if ((x >= 0) && (y >= 0)) {
                if (race->governor[governor].toggle.color) {
                    sprintf(string,
                            "%c %d %d %d %c %c %d;",
                            (char)(ship->owner + '?'),
                            x,
                            y,
                            wm,
                            Shipltrs[ship->type],
                            (char)(ship->owner + '?'),
                            ship->number);
                } else {
                    if (ship->owner == race->governor[governor].toggle.highlight) {
                        stand = 1;
                    } else {
                        stand = 0;
                    }

                    sprintf(string,
                            "%d %d %d %d %c %d %d;",
                            stand,
                            x,
                            y,
                            wm,
                            Shipltrs[ship->type],
                            stand,
                            ship->number);
                }
            }
        }

        break;
    }
}
Ejemplo n.º 23
0
int
main(int argc, char **argv)
{
    int     team, s_type;
    char   *dpyname = NULL;
    int     usage = 0;
    int     err = 0;
    char   *name, *ptr, *cp;
    struct passwd *pwent;
    int     passive = 0;
    int     xpmopt = 1;
    int     useORopt = 0;
    int     useCookieOpt = 0;
    int     dontUseCookieOpt = 0;
/*    char *defaultsFile=NULL;*/

    pseudo[0] = defpasswd[0] = '\0';

    name = *argv++;
    argc--;
    if ((ptr = strrchr(name, '/')) != NULL)
	name = ptr + 1;
    while (*argv) {
	if (**argv != '-') {
	    serverName = *argv;	/* don't abort argument processing */
	    argv++;
	    argc--;
	} else {
	    ++*argv;

	    argc--;
	    ptr = *argv++;
	    while (*ptr) {
		switch (*ptr) {
		case 'C':	/* character name */
		    (void) strncpy(pseudo, *argv, sizeof(pseudo));
		    argv++;
		    argc--;
		    break;

		case 'P':	/* authorization password */
		    (void) strncpy(defpasswd, *argv, sizeof(defpasswd));
		    {
			int     i;
			for (i = 0; (*argv)[i]; i++)
			    (*argv)[i] = 0;
		    }
		    argv++;
		    argc--;
		    break;

		case 'u':
		    usage++;
		    break;
		case 's':
		    if (*argv) {
			xtrekPort = atoi(*argv);
			passive = 1;
			argv++;
			argc--;
		    }
		    break;
		case 'p':
		    if (*argv) {
			xtrekPort = atoi(*argv);
			argv++;
			argc--;
		    }
		    break;
		case 'd':
		    dpyname = *argv;
		    argc--;
		    argv++;
		    break;
		case 'm':
		    usemeta = 1;
		    break;
		case 'h':
		    serverName = *argv;
		    argc--;
		    argv++;
		    break;

		case 't':
		    title = *argv;
		    argc--;
		    argv++;
		    break;
		case 'r':
		    defaultsFile = *argv;
		    argv++;
		    argc--;
		    break;
#ifdef AUTHORIZE
		case 'o':
		    RSA_Client = -1;
		    break;
		case 'R':
		    RSA_Client = -2;
		    break;
#else
		case 'o':
		case 'R':
		    printf("This client does not have binary authorization.\n");
		    break;
#endif
		case 'e':
#ifdef AUTHORIZE
		    checkExpire(1);
#else
		    printf("This client does not RSA verify and will not expire.\n");
#endif
		    exit(0);
		    break;
		case 'f':	/* list ftp sites */
		    fprintf(stderr, "\n\
The newest version of the Paradise client can be found at:\n\
      ftp.netrek.org  in /pub/netrek/paradise/bin/\n");
		    exit(0);
		case 'G':
		    if (*argv) {
			ghoststart++;
			ghost_pno = atoi(*argv);
			printf("Emergency restart being attempted...\n");
			argv++;
			argc--;
		    }
		    break;
		case '2':	/* force paradise */
		    paradise = 1;
		    break;
		case 'F':	/* File playback */
		    if (*argv) {
			playFile = strdup(*argv);
			playback = 1;
			argv++;
			argc--;
		    }
		    break;
		case 'x':
		    xpmopt = 0;
		    break;
		case 'k':		/* cookie mode [BDyess] */
		    useCookieOpt = 1;
		    break;
		case 'K':		/* no-cookies :( [BDyess] */
		    dontUseCookieOpt = 1;
		    break;
		case 'v':
		    verbose_image_loading = 1;
		    break;
		case 'O':		/* turn on GXor image drawing [BDyess]*/
		    useORopt = 1;	
		    break;
                case 'c': 	/* dump .paradiserc defaults [BDyess] */
		    dump_defaults = 1;
		    break;
		default:
		    fprintf(stderr, "%s: unknown option '%c'\n", name, *ptr);
		    err++;
		    break;
		}
		ptr++;
	    }
	}
    }

    inittrigtables();

    initStars();		/* moved from redraw.c at KAO\'s suggestion */

    if (usage || err) {
	printUsage(name);
#ifdef AUTHORIZE
	checkExpire(1);
#endif
	exit(0);
	/* exit(err); Exits from checkExpire */
    }
    defaultsFile = initDefaults(defaultsFile);

    if(xpmopt) xpm = 1;
    else xpm = booleanDefault("xpm",xpm);
    if(xpm) printf("XPM mode enabled.\n");
    /* command line option overrides .paradiserc value [BDyess] */
    if(useORopt) useOR = 1;
    else useOR = booleanDefault("useOR",useOR);
    if(useOR) printf("OR mode enabled.\n");
    if(useOR || !xpm) cookie = 0;	/* default no-cookies unless in XPM
    					   mode w/out OR [BDyess] */
					/* note: need a milk mode :) */
    if(useCookieOpt) cookie = 1;
    else if(dontUseCookieOpt) cookie = 0;
    else cookie = booleanDefault("cookie",cookie);
    if(cookie) printf("Cookie mode enabled.\n");

#ifdef AUTHORIZE
    if (RSA_Client != -1)
	checkExpire(0);
#endif

    /* compatability */
    if (argc > 0)
	serverName = argv[0];

    srandom(getpid() + time((long *) 0));

    if(playback || booleanDefault("playback",0)) {
        defNickName = "playback";
	usemeta=0;
        serverName = "playback";
    } else
    {
        if (serverName) {
	    char    temp[80], *s;
	    sprintf(temp, "server.%s", serverName);
	    if ((s = stringDefault(temp,NULL))) {
		printf("Using nickname \"%s\" for server %s\n", serverName, s);
		defNickName = serverName;
		serverName = s;
		defFlavor = stringDefault("flavor",NULL);
	    }
	}
	if (!serverName) {
	    serverName = stringDefault("server",NULL);
        }
	if (!serverName && !passive) {
	    serverName = DEFAULT_SERVER;
	    usemeta = 1;		/* no server specified, show the menu */
	}
	if (passive)
	    serverName = "passive";	/* newwin gets a wrong title otherwise */

	if (xtrekPort < 0)
	    xtrekPort = intDefault("port", -1);
	if (xtrekPort < 0)
	    xtrekPort = DEFAULT_PORT;
    } /* playback */
    build_default_configuration();

    metaserverAddress = stringDefault("metaserver",
				      "metaserver.netrek.org");
    if (usemeta)
	openmeta();

    W_Initialize(dpyname);

    metaFork = booleanDefault("metaFork", metaFork);
    /* do the metawindow thang */
    if (usemeta) {
	metawindow();
	metainput();
	if (metaFork)
	    W_Initialize(dpyname);
	newwin(dpyname, name);
    } else

	/* this creates the necessary x windows for the game */
	newwin(dpyname, name);

    /* open memory...? */
    openmem();
    if (!startPlayback())
    {
	if (!passive) {
	    serverName = callServer(xtrekPort, serverName);
	} else {
	    connectToServer(xtrekPort);
	}
    }
    sendFeature("FEATURE_PACKETS", 'S', 1, 0, 0);

    timeStart = time(NULL);
    findslot();

    /* sets all the settings from defaults file (.xtrekrc probably) */
    resetDefaults();

#ifdef UNIX_SOUND
    init_sound();
    play_sound(SND_PARADISE);
#endif

    mapAll();
/*    signal(SIGINT, SIG_IGN);*/
    signal(SIGCHLD, reaper);

    /* Get login name */
    if ((pwent = getpwuid(getuid())) != NULL)
	(void) strncpy(login, pwent->pw_name, sizeof(login));
    else
	(void) strncpy(login, "Bozo", sizeof(login));
    login[sizeof(login) - 1] = '\0';

    if (pseudo[0] == '\0') {
	char *freeme;
	strncpy(pseudo, freeme = stringDefault("name",login), sizeof(pseudo));
	free(freeme);
    }
    pseudo[sizeof(pseudo) - 1] = '\0';

    if (defpasswd[0] == '\0') {
	char buf[100];  /* added password by character name -JR */
	sprintf(buf,"password.%s",pseudo);
	if((cp = stringDefault(buf,NULL)) || (cp = stringDefault("password",NULL)))
	    (void) strncpy(defpasswd, cp, sizeof(defpasswd));
    }
    defpasswd[sizeof(defpasswd) - 1] = '\0';

    /*
       sendLoginReq("Gray Lensman", "hh", "sfd", 0); loginAccept = -1; while
       (loginAccept == -1) { socketPause(1,0); readFromServer(); }
    */
    getname(pseudo, defpasswd);
    loggedIn = 1;

    /*
       Set p_hostile to hostile, so if keeppeace is on, the guy starts off
       hating everyone (like a good fighter should)
    */
    me->p_hostile = (1 << number_of_teams) - 1;

    redrawTstats();

    me->p_planets = 0;
    me->p_genoplanets = 0;
    me->p_armsbomb = 0;
    me->p_genoarmsbomb = 0;
    /* Set up a reasonable default */
    me->p_whydead = KNOREASON;
    me->p_teami = -1;
    s_type = defaultShip(CRUISER);	/* from rlb7h 11/15/91 TC */

    if (booleanDefault("netStats", 1))
	startPing();		/* tell the server that we support pings */

    /*
       hack to make galaxy class ships work.  This could be more elegant, but
       the configuration code would have to be modified quite a bit, since
       the client doesn't know if it's on a paradise server until after it
       connects, and it needs the configuration info before it connects.
    */
    init_galaxy_class();

    initkeymap(-1);		/* needs to have ship types initialized -JR */

    setjmp(env);		/* Reentry point of game */

    if (ghoststart) {
	int     i;

	ghoststart = 0;

	for (i = -1; i < 5; i++)
	    if (teaminfo[i].letter == me->p_mapchars[0])
		break;

	me->p_teami = i;

	if (me->p_damage > me->p_ship->s_maxdamage) {
	    me->p_status = POUTFIT;
	} else
	    me->p_status = PALIVE;
    } else
	me->p_status = POUTFIT;

    while (1) {
	switch (me->p_status) {
	case POUTFIT:
	case PTQUEUE:
	    /* give the player the motd and find out which team he wants */
	    new_entrywindow(&team, &s_type);
	    allowPlayerlist = 1;
	    if (W_IsMapped(playerw))
		playerlist();

	    if (!playback)
		if (team == -1) {
		    W_DestroyWindow(w);
		    sendByeReq();
		    sleep(1);
		    printf("OK, bye!\n");
		    EXIT(0);
		}
	    sendVersion();
	    myship = getship(myship->s_type);

	    currentship = myship->s_type;

	    /*
	       sendOptionsPacket(); this would totally blast any flags you
	       had on the server
	    */

	    redrawall = 1;
	    enter();
	    calibrate_stats();
	    W_ClearWindow(w);
	    /*
	       for (i = 0; i < NSIG; i++) { signal(i, SIG_IGN); }
	    */

	    me->p_status = PALIVE;	/* Put player in game */

#ifdef UNIX_SOUND
            kill_sound ();
#endif
            
	    hockeyInit();

	    if (showStats)	/* Default showstats are on. */
		W_MapWindow(statwin);
	    if (showNewStats)	/* default showNewStats are off. [BDyess] */
	        W_MapWindow(newstatwin);

	    if (tryUdp && commMode != COMM_UDP) {
		sendUdpReq(COMM_UDP);
	    }

	    if (tryShort) {
		sendShortReq(SPK_VON);
		tryShort = 0;	/* only try it once */
	    }
	    /* Send request for a full update */
	    if (askforUpdate) {
		if(recv_short)
		    sendShortReq(SPK_SALL);
		else
		    sendUdpReq(COMM_UPDATE);
	    }
	    sendUpdatePacket(1000000 / updateSpeed);

	    W_Deiconify(baseWin);

	    break;
	case PALIVE:
	case PEXPLODE:
	case PDEAD:
	case POBSERVE:

	    /* Get input until the player quits or dies */
	    input();
	    W_ClearWindow(mapw);
	    break;
	default:
	    printf("client has p_status=%d.  how strange\n", me->p_status);
	    me->p_status = POUTFIT;
	}
    }

    /* NOTREACHED */
}
Ejemplo n.º 24
0
int
boar(void)
{
    struct combat off[1];	/* boarding ship or sector */
    struct combat def[1];	/* defending ship */
    struct emp_qelem olist;	/* boarding units */
    struct emp_qelem dlist;	/* defending units */
    int ototal;			/* total boarding strength */
    int a_engineer = 0;		/* boarder engineers are present */
    int a_spy = 0;		/* the best boarder scout */
    struct shpstr ship;		/* for retreating */
    struct sctstr sect;
    struct lndstr land;
    struct nstr_item ni;
    int foundland, def_uid;
    natid def_own;
    char *p;
    char buf[1024];

    att_combat_init(def, EF_SHIP);
    /*
     * Collect input from the boarder
     */

    /* What are we boarding? */
    p = getstarg(player->argp[1], "Victim ship #?  ", buf);
    if (!p || (def->shp_uid = atoi(p)) < 0)
	return RET_SYN;

    /*
     * Ask the boarder what he wants to board with
     */

    if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf)))
	return RET_SYN;
    if (issector(p)) {
	att_combat_init(off, EF_SECTOR);
	if (!sarg_xy(p, &off->x, &off->y))
	    return RET_SYN;
	getsect(off->x, off->y, &sect);
	if (sect.sct_own != player->cnum) {
	    pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum));
	    return RET_SYN;
	}
	if (sect.sct_mobil <= 0) {
	    /* Look for land units with mobility */
	    snxtitem_xy(&ni, EF_LAND, off->x, off->y);
	    foundland = 0;
	    while (nxtitem(&ni, &land)) {
		if (land.lnd_own != player->cnum)
		    continue;
		if (land.lnd_ship >= 0 || land.lnd_land >= 0)
		    continue;
		if (land.lnd_mobil <= 0)
		    continue;
		/* Only land units with assault can board */
		if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT))
		    continue;
		foundland = 1;
	    }
	    if (!foundland) {
		pr("You don't have any mobility (sector or land units) in %s!\n",
		   xyas(off->x, off->y, player->cnum));
		return RET_SYN;
	    }
	}
    } else {
	att_combat_init(off, EF_SHIP);
	if ((off->shp_uid = atoi(p)) < 0)
	    return RET_SYN;
    }
    if (att_abort(A_BOARD, off, def)) {
	pr("Board aborted\n");
	return RET_OK;
    }

    /* Fire at the attacking ship */

    att_approach(off, def);
    if (att_abort(A_BOARD, off, def)) {
	pr("Board aborted\n");
	att_empty_attack(A_BOARD, 0, def);
	return RET_OK;
    }

    /* Show what we're boarding */
    att_show(def);

    /* Ask the player what he wants to board with */

    att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer);
    if (att_abort(A_BOARD, off, def)) {
	pr("Board aborted\n");
	att_empty_attack(A_BOARD, 0, def);
	return att_free_lists(&olist, NULL);
    }

    ototal = att_get_offense(A_BOARD, off, &olist, def);
    if (att_abort(A_BOARD, off, def)) {
	pr("Board aborted\n");
	att_empty_attack(A_BOARD, 0, def);
	return att_free_lists(&olist, NULL);
    }

    /*
     * We have now got all the answers from the boarder.  From this point
     * forward, we can assume that this battle is the _only_ thing
     * happening in the game.
     */

    /* Get the real defense */

    att_get_defense(&olist, def, &dlist, a_spy, ototal);

    /*
     * Death, carnage, and destruction.
     */

    /*
     * Careful: when the fight sinks the ship, put_combat() clobbers
     * *def (see FIXME there).
     */
    def_uid = def->shp_uid;
    def_own = def->own;
    if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) {
	getship(def_uid, &ship);
	if (ship.shp_rflags & RET_BOARDED) {
	    retreat_ship(&ship, def_own, 'u');
	    putship(def_uid, &ship);
	}
    }

    return RET_OK;
}
Ejemplo n.º 25
0
/* highlight the captain with the up */
static void inl_draft_highlight_up(struct player *k)
{
  getship(&k->p_ship, BATTLESHIP);
  god(k->p_no, "Draft captain, your turn to pick a player.");
}
Ejemplo n.º 26
0
int
msl_launch(struct plnstr *pp, int type, char *what, coord x, coord y,
	   natid victim, int *sublaunchp)
{
    struct shpstr ship;
    struct nukstr nuke;
    int sublaunch = 0;
    char *base, *in_or_at, *from;

    mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n",
	prplane(pp),
	cname(victim),
	what,
	type != EF_SECTOR ? "in " : "",
	xyas(x, y, pp->pln_own));
    if (pp->pln_ship >= 0) {
	getship(pp->pln_ship, &ship);
	base = prship(&ship);
	in_or_at = " in ";
	if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
	    sublaunch = 1;
	    from = "in hatch";
	} else
	    from = "on deck";
    } else {
	if (pp->pln_harden > 0) {
	    base = "missile silo";
	    in_or_at = " at ";
	    from = "in silo";
	} else {
	    base = in_or_at = "";
	    from = "on launch pad";
	}
    }
    mpr(pp->pln_own, "\tLaunching from %s%s%s\n",
	base, in_or_at, xyas(pp->pln_x, pp->pln_y, pp->pln_own));

    CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED);
    pp->pln_flags |= PLN_LAUNCHED;
    putplane(pp->pln_uid, pp);

    if (chance((0.05 + (100 - pp->pln_effic) / 100.0)
	       * (1 - techfact(pp->pln_tech, 1.0)))) {
	mpr(pp->pln_own, "KABOOOOM!  Missile explodes %s!\n", from);
	if (getnuke(nuk_on_plane(pp), &nuke)) {
	    mpr(pp->pln_own, "%s lost!\n", prnuke(&nuke));
	    nuke.nuk_effic = 0;
	    putnuke(nuke.nuk_uid, &nuke);
	}
#if 0
	/*
	 * Disabled for now, because it breaks callers that call
	 * msl_launch() for each member of a list of planes, created
	 * by msl_sel() or perform_mission().  Damage to the base can
	 * damage other planes.  Any copies of them in the list become
	 * stale.  When msl_launch() modifies and writes back such a
	 * stale copy, the damage gets wiped out, triggering a seqno
	 * oops.
	 */
	if (chance(0.33)) {
	    struct sctstr sect;
	    int dam;

	    dam = pln_damage(pp, 'p', NULL) / 2;
	    if (pp->pln_ship >= 0) {
		shipdamage(&ship, dam);
		putship(ship.shp_uid, &ship);
	    } else {
		mpr(pp->pln_own, "Explosion damages %s %d%%\n",
		    xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam);
		getsect(pp->pln_x, pp->pln_y, &sect);
		sectdamage(&sect, dam);
		putsect(&sect);
	    }
	}
#endif
	return -1;
    }

    mpr(pp->pln_own, "\tSHWOOOOOSH!  Missile launched!\n");

    if (type != EF_PLANE)
	mpr(victim, "Incoming %s missile sighted at %s...\n",
	    sublaunch ? "sub-launched" : cname(pp->pln_own),
	    xyas(x, y, victim));

    if (type == EF_SECTOR || type == EF_LAND) {
	if (msl_abm_intercept(pp, x, y, sublaunch))
	    return -1;
    }
    if (type == EF_SHIP) {
	if (shp_missile_defense(x, y, pp->pln_own, pln_def(pp))) {
	    return -1;
	}
    }

    if (sublaunchp)
	*sublaunchp = sublaunch;
    return 0;
}
Ejemplo n.º 27
0
/* everybody else */
static void inl_draft_highlight_off(struct player *k)
{
  getship(&k->p_ship, CRUISER);
}
Ejemplo n.º 28
0
int
detonate(struct nukstr *np, coord x, coord y, int airburst)
{
    int nuketype = np->nuk_type;
    struct nchrstr *ncp;
    struct plnstr plane;
    struct sctstr sect;
    struct shpstr ship;
    struct lndstr land;
    struct nukstr nuke;
    natid own;
    int type;
    int damage;
    int fallout;
    int rad;
    struct nstr_sect ns;
    struct nstr_item ni;
    int changed = 0;

    pr("Releasing RV's for %s detonation...\n",
       airburst ? "airburst" : "groundburst");

    getsect(x, y, &sect);
    ncp = &nchr[nuketype];
    kaboom(x, y, ncp->n_blast);
    rad = ncp->n_blast;
    if (!airburst)
        rad = rad * 2 / 3;
    if (sect.sct_type == SCT_WATER)
        rad = 0;     /* Nukes falling on water affect only 1 sector */
    np->nuk_effic = 0;
    putnuke(np->nuk_uid, np);

    snxtsct_dist(&ns, x, y, rad);
    while (nxtsct(&ns, &sect)) {
        own = sect.sct_own;
        type = sect.sct_type;
        if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
            continue;
        if (type == SCT_SANCT) {
            pr("bounced off %s\n", xyas(ns.x, ns.y, player->cnum));
            mpr(own, "%s nuclear device bounced off %s\n",
                cname(player->cnum), xyas(ns.x, ns.y, own));
            nreport(player->cnum, N_NUKE, own, 1);
            continue;
        }
        sect_damage(&sect, damage);
        if (opt_FALLOUT) {
            fallout = sect.sct_fallout;
            if (ncp->n_flags & N_NEUT)
                fallout += damage * 30;
            else
                fallout += damage * 3;
            sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
        }
        if (damage > 100) {
            sect.sct_oldown = 0;
            sect.sct_own = 0;
            if (type == SCT_WATER || type == SCT_BSPAN ||
                    type == SCT_BTOWER) {
                if (type != SCT_WATER) {
                    pr("left nothing but water in %s\n",
                       xyas(ns.x, ns.y, player->cnum));
                    if (own != player->cnum)
                        mpr(own,
                            "%s nuclear device left nothing but water in %s\n",
                            cname(player->cnum), xyas(ns.x, ns.y, own));
                    sect.sct_newtype = SCT_WATER;
                    sect.sct_type = SCT_WATER;
                }
            } else {
                sect.sct_newtype = SCT_WASTE;
                sect.sct_type = SCT_WASTE;
                pr("turned %s into a radioactive wasteland\n",
                   xyas(ns.x, ns.y, player->cnum));
                if (own != player->cnum)
                    mpr(own,
                        "%s nuclear device turned %s into a radioactive wasteland\n",
                        cname(player->cnum), xyas(ns.x, ns.y, own));
            }
            changed |= map_set(player->cnum, sect.sct_x, sect.sct_y,
                               dchr[sect.sct_type].d_mnem, 0);
        } else {
            pr("did %d%% damage in %s\n",
               damage, xyas(ns.x, ns.y, player->cnum));
            if (own != player->cnum)
                mpr(own, "%s nuclear device did %d%% damage in %s\n",
                    cname(player->cnum), damage, xyas(ns.x, ns.y, own));
        }
        (void)putsect(&sect);
        if (type != SCT_WATER)
            nreport(player->cnum, N_NUKE, own, 1);
    }

    if (changed)
        writebmap(player->cnum);

    snxtitem_dist(&ni, EF_PLANE, x, y, rad);
    while (nxtitem(&ni, &plane)) {
        if ((own = plane.pln_own) == 0)
            continue;
        if (plane.pln_flags & PLN_LAUNCHED)
            continue;
        damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
        if (damage <= 0)
            continue;
        if (plane.pln_ship >= 0) {
            /* Are we on a sub? */
            getship(plane.pln_ship, &ship);

            if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
                struct sctstr sect1;

                /* Should we damage this sub? */
                getsect(ship.shp_x, ship.shp_y, &sect1);

                if (sect1.sct_type == SCT_BSPAN ||
                        sect1.sct_type == SCT_BTOWER ||
                        sect1.sct_type == SCT_WATER) {
                    /* Ok, we're not in a harbor or trapped
                       inland.  Now, did we get pasted
                       directly? */
                    if (ship.shp_x != x || ship.shp_y != y) {
                        /* Nope, so don't mess with it */
                        continue;
                    }
                }
            }
        }
        planedamage(&plane, damage);
        if (own == player->cnum) {
            pr("%s at %s reports %d%% damage\n",
               prplane(&plane),
               xyas(plane.pln_x, plane.pln_y, player->cnum), damage);
        } else {
            mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
                cname(player->cnum), damage,
                prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
        }
        putplane(ni.cur, &plane);
    }

    snxtitem_dist(&ni, EF_LAND, x, y, rad);
    while (nxtitem(&ni, &land)) {
        if ((own = land.lnd_own) == 0)
            continue;
        if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
            continue;

        if (land.lnd_ship >= 0) {
            /* Are we on a sub? */
            getship(land.lnd_ship, &ship);

            if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
                struct sctstr sect1;

                /* Should we damage this sub? */
                getsect(ship.shp_x, ship.shp_y, &sect1);

                if (sect1.sct_type == SCT_BSPAN ||
                        sect1.sct_type == SCT_BTOWER ||
                        sect1.sct_type == SCT_WATER) {
                    /* Ok, we're not in a harbor or trapped
                       inland.  Now, did we get pasted
                       directly? */
                    if (ship.shp_x != x || ship.shp_y != y) {
                        /* Nope, so don't mess with it */
                        continue;
                    }
                }
            }
        }
        land_damage(&land, damage);
        if (own == player->cnum) {
            pr("%s at %s reports %d%% damage\n",
               prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum),
               damage);
        } else {
            mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
                cname(player->cnum), damage,
                prland(&land), xyas(land.lnd_x, land.lnd_y, own));
        }
        putland(land.lnd_uid, &land);
    }

    snxtitem_dist(&ni, EF_SHIP, x, y, rad);
    while (nxtitem(&ni, &ship)) {
        if ((own = ship.shp_own) == 0)
            continue;
        if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
            continue;
        if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
            struct sctstr sect1;

            /* Should we damage this sub? */
            getsect(ship.shp_x, ship.shp_y, &sect1);

            if (sect1.sct_type == SCT_BSPAN ||
                    sect1.sct_type == SCT_BTOWER ||
                    sect1.sct_type == SCT_WATER) {
                /* Ok, we're not in a harbor or trapped
                   inland.  Now, did we get pasted
                   directly? */
                if (ship.shp_x != x || ship.shp_y != y) {
                    /* Nope, so don't mess with it */
                    continue;
                }
            }
        }
        ship_damage(&ship, damage);
        if (own == player->cnum) {
            pr("%s at %s reports %d%% damage\n",
               prship(&ship), xyas(ship.shp_x, ship.shp_y, player->cnum),
               damage);
        } else {
            mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
                cname(player->cnum), damage, prship(&ship),
                xyas(ship.shp_x, ship.shp_y, own));
        }
        putship(ship.shp_uid, &ship);
    }

    snxtitem_dist(&ni, EF_NUKE, x, y, rad);
    while (nxtitem(&ni, &nuke)) {
        if ((own = nuke.nuk_own) == 0)
            continue;
        if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
            continue;
        if (!pct_chance(damage))
            continue;
        nuke.nuk_effic = 0;
        if (own == player->cnum) {
            pr("%s at %s destroyed\n",
               prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, player->cnum));
        } else {
            mpr(own, "%s nuclear device destroyed %s at %s\n",
                cname(player->cnum), prnuke(&nuke),
                xyas(nuke.nuk_x, nuke.nuk_y, own));
        }
        putnuke(ni.cur, &nuke);
    }

    return nukedamage(ncp, 0, airburst);
}
Ejemplo n.º 29
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;
            }
        }
Ejemplo n.º 30
0
struct Enemy *
get_nearest()
{
    int pcount = 0;
    register int i;
    register struct player *j;
    int intruder = 0;
    int tdist;
    double dx, dy;
    double vxa, vya, l;	/* Used for trap shooting */
    double vxt, vyt;
    double vxs, vys;
    double dp;

    /* Find an enemy */
    ebuf.e_info = me->p_no;
    ebuf.e_dist = GWIDTH + 1;

    pcount = 0;  /* number of human players in game */

    if (target >= 0) {
	j = &players[target];
	if (!(me->p_war & j->p_team))
	    declare_war(players[target].p_team, 0); /* make sure we're at war 7/31/91 TC */

	/* We have an enemy */
	/* Get his range */
	dx = j->p_x - me->p_x;
	dy = j->p_y - me->p_y;
	tdist = hypot(dx, dy);

	if (j->p_status != POUTFIT) { /* ignore target if outfitting */
	    ebuf.e_info = target;
	    ebuf.e_dist = tdist;
	    ebuf.e_flags &= ~(E_INTRUDER);
	}
	
	/* need a loop to find hostile ships */
	/* within tactical range */

	for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
	    if ((j->p_status != PALIVE) || (j == me) ||
		((j->p_flags & PFROBOT) && (!hostile)))
		continue;
	    else
		pcount++;	/* Other players in the game */
	    if ((j->p_war & me->p_team) ||
		(me->p_war & j->p_team)) {
		/* We have an enemy */
		/* Get his range */
		dx = j->p_x - me->p_x;
		dy = j->p_y - me->p_y;
		tdist = hypot(dx, dy);
		
		/* if target's teammate is too close, mark as nearest */

		if ((tdist < ebuf.e_dist) && (tdist < 15000)) {
		    ebuf.e_info = i;
		    ebuf.e_dist = tdist;
		    ebuf.e_flags &= ~(E_INTRUDER);
		}
	    }			/* end if */
	}			/* end for */
    }
    else {			/* no target */
	/* avoid dead slots, me, other robots (which aren't hostile) */
	for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
	    if ((j->p_status != PALIVE) || (j == me) ||
		((j->p_flags & PFROBOT) && (!hostile)) ||
                (j->p_flags & PFPRACTR))
		continue;
	    else
		pcount++;	/* Other players in the game */
	    if ((j->p_war & me->p_team) || 
		(me->p_war & j->p_team)) {
		/* We have an enemy */
		/* Get his range */
		dx = j->p_x - me->p_x;
		dy = j->p_y - me->p_y;
		tdist = hypot(dx, dy);
		
		/* Check to see if ship is in our space. */
		switch (me->p_team) {
		  case FED:
		    intruder = ((j->p_x < GWIDTH/2) && (j->p_y > GWIDTH/2));
		    break;
		  case ROM:
		    intruder = ((j->p_x < GWIDTH/2) && (j->p_y < GWIDTH/2));
		    break;
		  case KLI:
		    intruder = ((j->p_x > GWIDTH/2) && (j->p_y < GWIDTH/2));
		    break;
		  case ORI:
		    intruder = ((j->p_x > GWIDTH/2) && (j->p_y > GWIDTH/2));
		    break;
		}
		
		if (tdist < ebuf.e_dist) {
		    ebuf.e_info = i;
		    ebuf.e_dist = tdist;
		    if (intruder)
			ebuf.e_flags |= E_INTRUDER;
		    else
			ebuf.e_flags &= ~(E_INTRUDER);
		}
	    }			/* end if */
	}			/* end for */
    }				/* end else */
    if (pcount == 0) {
	return NOENEMY;    /* no players in game */
    } else if (ebuf.e_info == me->p_no) {
	return 0;			/* no hostile players in the game */
    } else {
	j = &players[ebuf.e_info];

	/* Get torpedo course to nearest enemy */
	ebuf.e_flags &= ~(E_TSHOT);

	vxa = (j->p_x - me->p_x);
	vya = (j->p_y - me->p_y);
	l = hypot(vxa, vya);	/* Normalize va */
	if (l!=0) {
	    vxa /= l;
	    vya /= l;
	}
	vxs = (Cos[j->p_dir] * j->p_speed) * WARP1;
	vys = (Sin[j->p_dir] * j->p_speed) * WARP1;
	dp = vxs * vxa + vys * vya;	/* Dot product of (va vs) */
	dx = vxs - dp * vxa;
	dy = vys - dp * vya;
	l = hypot(dx, dy);      /* Determine how much speed is required */
        dp = (float) (me->p_ship.s_torpspeed * WARP1);
        l = (dp * dp - l * l);
        if (l > 0) {
	    double he_x, he_y, area;

	    /* Only shoot if within distance */
	    he_x = j->p_x + Cos[j->p_dir] * j->p_speed * 50 * WARP1;
	    he_y = j->p_y + Sin[j->p_dir] * j->p_speed * 50 * WARP1;
	    area = 50 * me->p_ship.s_torpspeed * WARP1;
	    if (hypot(he_x - me->p_x, he_y - me->p_y) < area) {
		l=sqrt(l);
		vxt = l * vxa + dx;
		vyt = l * vya + dy;
		ebuf.e_flags |= E_TSHOT;
		ebuf.e_tcourse = getcourse((int) vxt + me->p_x, (int) vyt + me->p_y);
	    }
	}

	/* Get phaser shot status */
	if (ebuf.e_dist < 0.8 * phrange)
		ebuf.e_flags |= E_PSHOT;
	else
		ebuf.e_flags &= ~(E_PSHOT);

	/* Get tractor/pressor status */
	if (ebuf.e_dist < trrange)
		ebuf.e_flags |= E_TRACT;
	else
		ebuf.e_flags &= ~(E_TRACT);


	/* get his phaser range */
	ebuf.e_phrange = PHASEDIST * j->p_ship.s_phaserdamage / 100;

	/* get course info */
	ebuf.e_course = getcourse(j->p_x, j->p_y);
	ebuf.e_edir = j->p_dir;
	ebuf.e_hisflags = j->p_flags;
	ebuf.e_tractor = j->p_tractor;
	/*
	if (debug)
	    ERROR(1,( "Set course to enemy is %d (%d)\n",
		    (int)ebuf.e_course, 
		    (int) ebuf.e_course * 360 / 256));
	*/

	/* check to polymorph */

	if ((polymorphic) && (j->p_ship.s_type != me->p_ship.s_type) &&
	    (j->p_ship.s_type != ATT)) { /* don't polymorph to ATT 4/8/92 TC */
	    extern int config();
	    int old_shield;
	    int old_damage;
	    old_shield = me->p_ship.s_maxshield;
	    old_damage = me->p_ship.s_maxdamage;
	    
	    getship(&(me->p_ship), j->p_ship.s_type);
	    config();
	    if (me->p_speed > me->p_ship.s_maxspeed)
		me->p_speed = me->p_ship.s_maxspeed;
	    me->p_shield = (me->p_shield * (float)me->p_ship.s_maxshield)
		/(float)old_shield;
	    me->p_damage = (me->p_damage * (float)me->p_ship.s_maxdamage)
		/(float)old_damage;
	}

	return &ebuf;
    }
}