void pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip) { struct emp_qelem *qp; struct emp_qelem *next; struct plist *plp; struct plnstr *pp; for (qp = list->q_forw; qp != list; qp = next) { next = qp->q_forw; plp = (struct plist *)qp; pp = &plp->plane; getplane(pp->pln_uid, pp); if ((pp->pln_flags & PLN_LAUNCHED) || pln_equip(plp, ip, mission) < 0) { emp_remque(qp); free(qp); continue; } pp->pln_flags |= PLN_LAUNCHED; pp->pln_mobil -= pln_mobcost(dist, pp, mission); putplane(pp->pln_uid, pp); pr("%s equipped\n", prplane(pp)); } }
/* * remove cc bytes from ioqueue ioq * free memory, dequeue io elements * which are no longer used. */ static int removecc(struct ioqueue *ioq, int cc) { struct io *io; struct emp_qelem *qp; int nbytes, there, remain; nbytes = 0; remain = cc; while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) { io = (struct io *)qp; there = io->nbytes - io->offset; if (there < 0) { /* error */ emp_remque(&io->queue); free(io); continue; } if (remain >= there) { /* not enough or exact; free entry */ nbytes += there; remain -= there; emp_remque(&io->queue); free(io->data); free(io); } else { /* too much; increment offset */ io->offset += remain; nbytes += remain; remain = 0; } if (remain <= 0) break; } ioq->cc -= nbytes; return nbytes; }
void ioq_drain(struct ioqueue *ioq) { struct emp_qelem *qp; struct io *io; while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) { io = (struct io *)qp; emp_remque(&io->queue); free(io->data); free(io); } ioq->cc = 0; }
struct player * player_delete(struct player *lp) { struct player *back; if (lp->iop) { /* it's a real player */ io_close(lp->iop, player->curup + login_grace_time); lp->iop = NULL; } back = (struct player *)lp->queue.q_back; if (back) emp_remque(&lp->queue); free(lp); /* XXX may need to free bigmap here */ return back; }
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, §); 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); }
static void switch_leader(struct emp_qelem *list, char *arg) { int uid = arg ? atoi(arg) : -1; struct emp_qelem *qp, *save; struct ulist *ulp; if (QEMPTY(list)) return; save = qp = list->q_back; do { emp_remque(qp); emp_insque(qp, list); qp = list->q_back; ulp = (struct ulist *)qp; if (ulp->unit.gen.uid == uid || uid == -1) break; } while (list->q_back != save); }
static int msl_intercept(struct plnstr *msl, struct sctstr *sp, int sublaunch, struct emp_qelem *irvlist, char *att_name, char *def_name, int news_item) { struct plnstr *pp; struct emp_qelem *intlist; struct emp_qelem intfoo; struct emp_qelem *qp; struct emp_qelem *next; struct plist *ip; int icount = 0; short destroyed; char *who = sublaunch ? "" : cname(msl->pln_own); intlist = &intfoo; emp_initque(intlist); /* First choose interceptors belonging to the target sector */ /* only allow two defense missiles per missile attack */ for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) { next = qp->q_forw; ip = (struct plist *)qp; pp = &ip->plane; if (pp->pln_own != sp->sct_own) continue; if (mission_pln_equip(ip, NULL, 'i') < 0) { emp_remque(qp); free(qp); continue; } /* got one interceptor, delete from irv_list and * add to int_list. */ emp_remque(qp); emp_insque(qp, intlist); putplane(pp->pln_uid, pp); icount++; } /* only allow two defense missiles per missile attack */ for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) { next = qp->q_forw; ip = (struct plist *)qp; pp = &ip->plane; if (mission_pln_equip(ip, NULL, 'i') < 0) { emp_remque(qp); free(qp); continue; } /* got one interceptor, delete from irv_list and * add to int_list. */ emp_remque(qp); emp_insque(qp, intlist); putplane(pp->pln_uid, pp); icount++; } /* Now, clean out the queue */ while (!QEMPTY(irvlist)) { qp = irvlist->q_forw; emp_remque(qp); free(qp); } if (icount == 0) { mpr(sp->sct_own, "No %ss launched to intercept.\n", def_name); return 0; } /* attempt to destroy incoming missile */ destroyed = 0; while (!destroyed && !QEMPTY(intlist)) { qp = intlist->q_forw; ip = (struct plist *)qp; pp = &ip->plane; mpr(msl->pln_own, "%s %s launched in defense!\n", cname(pp->pln_own), def_name); if (sp->sct_own == pp->pln_own) { mpr(sp->sct_own, "%s launched to intercept %s %s!\n", def_name, who, att_name); } else { mpr(sp->sct_own, "%s launched an %s to intercept the %s %s!\n", cname(pp->pln_own), def_name, who, att_name); mpr(pp->pln_own, "%s launched to intercept %s %s arcing towards %s territory!\n", def_name, who, att_name, cname(sp->sct_own)); } if (msl_launch(pp, EF_PLANE, att_name, sp->sct_x, sp->sct_y, msl->pln_own, NULL) >= 0 && msl_hit(pp, pln_def(msl), EF_PLANE, 0, 0, 0, msl->pln_own)) { mpr(msl->pln_own, "%s destroyed by %s %s!\n", att_name, cname(pp->pln_own), def_name); mpr(sp->sct_own, "%s %s intercepted!\n", who, att_name); if (sp->sct_own != pp->pln_own) mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name); if (sublaunch) nreport(pp->pln_own, news_item, 0, 1); else nreport(pp->pln_own, news_item, msl->pln_own, 1); destroyed = 1; } /* zap the missile */ pp->pln_effic = 0; putplane(pp->pln_uid, pp); emp_remque(qp); free(qp); } /* Clean out what is left in the list */ while (!QEMPTY(intlist)) { qp = intlist->q_forw; emp_remque(qp); free(qp); } if (destroyed) return 1; if (icount) { mpr(msl->pln_own, "%s made it through %s defenses!\n", att_name, def_name); mpr(sp->sct_own, "%s made it through %s defenses!\n", att_name, def_name); } return 0; }