void player_init(void) { emp_initque(&Players); init_player_commands(); player_socket = tcp_listen(*listen_addr ? listen_addr : NULL, loginport, &player_addrlen); }
void msl_sel(struct emp_qelem *list, coord x, coord y, natid victim, int wantflags, int nowantflags, int mission) { struct plchrstr *pcp; struct plnstr plane; struct plist *irv; struct nstr_item ni; emp_initque(list); snxtitem_all(&ni, EF_PLANE); while (nxtitem(&ni, &plane)) { if (!plane.pln_own) continue; pcp = &plchr[(int)plane.pln_type]; if (!(pcp->pl_flags & P_M)) continue; if (wantflags && (pcp->pl_flags & wantflags) != wantflags) continue; if (nowantflags && pcp->pl_flags & nowantflags) continue; if (mission && plane.pln_mission != mission) continue; if (mission && plane.pln_radius < mapdist(x, y, plane.pln_opx, plane.pln_opy)) continue; if (relations_with(plane.pln_own, victim) >= NEUTRAL) continue; /* missiles go one way, so we can use all the range */ if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y)) continue; if (plane.pln_mobil <= 0) continue; if (plane.pln_effic < 100) continue; if (opt_MARKET) { if (ontradingblock(EF_PLANE, &plane)) continue; } if (!pln_airbase_ok(&plane, 1, 0)) continue; /* got a valid interceptor */ irv = malloc(sizeof(*irv)); irv->load = 0; irv->pstage = PLG_HEALTHY; irv->pcp = &plchr[(int)plane.pln_type]; irv->plane = plane; emp_insque(&irv->queue, list); } }
struct ioqueue * ioq_create(int size) { struct ioqueue *ioq; ioq = malloc(sizeof(struct ioqueue)); emp_initque(&ioq->list.queue); ioq->list.nbytes = 0; ioq->list.offset = 0; ioq->list.size = 0; ioq->list.data = NULL; ioq->bufsize = size; ioq->cc = 0; return ioq; }
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; }
void pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap, int ap_to_target, int rangemult, int wantflags, int nowantflags) { struct plnstr plane; int range; struct plchrstr *pcp; struct plist *plp; emp_initque(list); while (nxtitem(ni, &plane)) { /* * It would be nice to let deities fly foreign planes, but * much of the code assumes that only the plane's owner can * fly it. */ if (!plane.pln_own || plane.pln_own != player->cnum) continue; if (plane.pln_mobil <= 0) continue; if (plane.pln_effic < 40) { pr("%s not efficient enough (must be 40%%)\n", prplane(&plane)); continue; } if (!pln_capable(&plane, wantflags, nowantflags)) continue; if (opt_MARKET) { if (ontradingblock(EF_PLANE, &plane)) { pr("plane #%d inelligible - it's for sale.\n", plane.pln_uid); continue; } } range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y); if (range > 4) { pr("%s too far from assembly point\n", prplane(&plane)); continue; } range += ap_to_target; range *= rangemult; pcp = &plchr[(int)plane.pln_type]; if (plane.pln_range < range) { pr("%s out of range (%d:%d)\n", prplane(&plane), plane.pln_range, range); continue; } if (!pln_airbase_ok(&plane, rangemult != 2, 1)) continue; pr("%s standing by\n", prplane(&plane)); plane.pln_mission = 0; putplane(plane.pln_uid, &plane); plp = malloc(sizeof(struct plist)); plp->load = 0; plp->pstage = PLG_HEALTHY; plp->pcp = pcp; plp->plane = plane; emp_insque(&plp->queue, list); } }