X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=src%2Flib%2Fsubs%2Fmission.c;h=cc802e53ff9fb0064aff845edfdf8c2db0209ecf;hp=c92f9cdbc9e8e6ad59f5e8c0451fa36a36c9aff9;hb=9b7adfbe;hpb=5f263a7753dc728809ff85c993af975f6c76e61e diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index c92f9cdbc..cc802e53f 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -57,14 +57,14 @@ #include "prototypes.h" #include "optlist.h" -struct airport{ - struct emp_qelem queue; - coord x,y; - natid own; +struct airport { + struct emp_qelem queue; + coord x, y; + natid own; }; -s_char *mission_name(short int mission); -s_char *nameofitem(s_char *buf, struct genitem *gp, int type); +s_char *mission_name(short int mission); +s_char *nameofitem(s_char *buf, struct genitem *gp, int type); /* * Interdict commodities & transported planes @@ -72,60 +72,60 @@ s_char *nameofitem(s_char *buf, struct genitem *gp, int type); int ground_interdict(coord x, coord y, natid victim, s_char *s) { - register int cn; - int dam=0, newdam, rel; - struct genlist mi[MAXNOC]; - int z; - - bzero((s_char *)mi,sizeof(mi)); - for(z=1;z HOSTILE) - continue; - - if (QEMPTY(&mi[cn].queue)) - continue; - - newdam = perform_mission(x,y,victim,&mi[cn].queue, - MI_INTERDICT,s,SECT_HARDTARGET); - dam += newdam; - if (newdam) - mpr(victim, "%s interdiction mission does %d damage!\n", - cname(cn), newdam); - } - if (dam) { - collateral_damage(x,y,dam, 0); - } - return dam; + register int cn; + int dam = 0, newdam, rel; + struct genlist mi[MAXNOC]; + int z; + + bzero((s_char *)mi, sizeof(mi)); + for (z = 1; z < MAXNOC; z++) + emp_initque((struct emp_qelem *)&mi[z]); + + build_mission_list(mi, x, y, MI_INTERDICT, victim); + + for (cn = 1; cn < MAXNOC; cn++) { + rel = getrel(getnatp(cn), victim); + if (rel > HOSTILE) + continue; + + if (QEMPTY(&mi[cn].queue)) + continue; + + newdam = perform_mission(x, y, victim, &mi[cn].queue, + MI_INTERDICT, s, SECT_HARDTARGET); + dam += newdam; + if (newdam) + mpr(victim, "%s interdiction mission does %d damage!\n", + cname(cn), newdam); + } + if (dam) { + collateral_damage(x, y, dam, 0); + } + return dam; } int collateral_damage(coord x, coord y, int dam, struct emp_qelem *list) { - extern double collateral_dam; - int coll; - struct sctstr sect; - - if (!dam) - return 0; - - getsect(x,y,§); - if (sect.sct_own) { - coll = ldround((double)dam * collateral_dam, 1); - if (coll == 0) - return 0; - mpr(sect.sct_own, "%s takes %d%% collateral damage\n", - xyas(x,y,sect.sct_own), coll); - sectdamage(§, coll, list); - putsect(§); - return coll; - } + extern double collateral_dam; + int coll; + struct sctstr sect; + + if (!dam) return 0; + + getsect(x, y, §); + if (sect.sct_own) { + coll = ldround((double)dam * collateral_dam, 1); + if (coll == 0) + return 0; + mpr(sect.sct_own, "%s takes %d%% collateral damage\n", + xyas(x, y, sect.sct_own), coll); + sectdamage(§, coll, list); + putsect(§); + return coll; + } + return 0; } int @@ -136,7 +136,7 @@ only_subs(struct emp_qelem *list) struct genitem *gp; struct mchrstr *mcp; - for(qp = list->q_forw; qp != list; qp = qp->q_forw) { + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { glp = (struct genlist *)qp; gp = (struct genitem *)glp->thing; @@ -157,54 +157,55 @@ only_subs(struct emp_qelem *list) * */ int -unit_interdict(coord x, coord y, natid victim, s_char *s, int hardtarget, int mission) +unit_interdict(coord x, coord y, natid victim, s_char *s, int hardtarget, + int mission) { - register int cn; - int dam=0, newdam; - struct genlist mi[MAXNOC]; - int z; - int osubs; + register int cn; + int dam = 0, newdam; + struct genlist mi[MAXNOC]; + int z; + int osubs; - bzero((s_char *)mi,sizeof(mi)); - for(z=1;z= FRIENDLY) - continue; - } else if (getrel(getnatp(cn),victim) > HOSTILE) - continue; - - if (QEMPTY(&mi[cn].queue)) - continue; - - osubs = only_subs(&mi[cn].queue); - newdam = perform_mission(x,y,victim,&mi[cn].queue, - mission,s,hardtarget); - dam += newdam; - if (newdam) { - /* If only subs responded, then we don't know who's - subs they are */ - if (osubs) { - mpr(victim, - "Enemy interdiction mission does %d damage!\n", - newdam); - } else { - mpr(victim, - "%s interdiction mission does %d damage!\n", - cname(cn), newdam); - } - } - } - if (dam) { - collateral_damage(x,y,dam, 0); - } - return dam; + for (cn = 1; cn < MAXNOC; cn++) { + if (cn == victim) + continue; + if (mission == MI_SINTERDICT) { + if (getrel(getnatp(cn), victim) >= FRIENDLY) + continue; + } else if (getrel(getnatp(cn), victim) > HOSTILE) + continue; + + if (QEMPTY(&mi[cn].queue)) + continue; + + osubs = only_subs(&mi[cn].queue); + newdam = perform_mission(x, y, victim, &mi[cn].queue, + mission, s, hardtarget); + dam += newdam; + if (newdam) { + /* If only subs responded, then we don't know who's + subs they are */ + if (osubs) { + mpr(victim, + "Enemy interdiction mission does %d damage!\n", + newdam); + } else { + mpr(victim, + "%s interdiction mission does %d damage!\n", + cname(cn), newdam); + } + } + } + if (dam) { + collateral_damage(x, y, dam, 0); + } + return dam; } /* @@ -213,19 +214,19 @@ unit_interdict(coord x, coord y, natid victim, s_char *s, int hardtarget, int mi int off_support(coord x, coord y, natid victim, natid actee) { - int dam=0; - struct genlist mi[MAXNOC]; - int z; + int dam = 0; + struct genlist mi[MAXNOC]; + int z; - bzero((s_char *)mi,sizeof(mi)); - for(z=1;zown == 0) - continue; + if (gp->own == 0) + continue; - if (gp->mobil < 1) - continue; + if (gp->mobil < 1) + continue; - if ((gp->mission != mission) && (mission != MI_SINTERDICT)) - continue; - - if ((gp->mission != mission) && (mission == MI_SINTERDICT) && - (gp->mission != MI_INTERDICT)) - continue; - - relat = getrel(getnatp(gp->own), victim); - if (mission == MI_SINTERDICT) { - if (relat >= FRIENDLY) - continue; - else if (type != EF_PLANE && relat > HOSTILE) - continue; - } else if (relat > HOSTILE) - continue; - - dist = mapdist(x, y, gp->opx, gp->opy); - - radius = gp->radius; - if (mission != MI_RESERVE) /* XXX */ - oprange(gp,type,&radius); - - if (dist > radius) - continue; - - /* Ok, it is within the operations range. */ - /* Now check from where the object actually is */ - dist = mapdist(x, y, gp->x, gp->y); - radius = 999; - oprange(gp, type, &radius); - if (dist > radius) - continue; - /* Ok, the object can get to where the x,y is */ - - if (opt_SLOW_WAR) { - if (mission != MI_AIR_DEFENSE) { - getsect(x,y,(s_char *)§); - if (getrel(getnatp(gp->own), sect.sct_own) > AT_WAR) { - - /* - * If the player->owner of the unit isn't at war - * with the victim, and doesn't own the - * sect being acted upon, and isn't the - * old player->owner of that sect, bounce them. - */ - if (sect.sct_type != SCT_WATER && - sect.sct_own != gp->own && - sect.sct_oldown != gp->own) - continue; - } - } + if ((gp->mission != mission) && (mission != MI_SINTERDICT)) + continue; + + if ((gp->mission != mission) && (mission == MI_SINTERDICT) && + (gp->mission != MI_INTERDICT)) + continue; + + relat = getrel(getnatp(gp->own), victim); + if (mission == MI_SINTERDICT) { + if (relat >= FRIENDLY) + continue; + else if (type != EF_PLANE && relat > HOSTILE) + continue; + } else if (relat > HOSTILE) + continue; + + dist = mapdist(x, y, gp->opx, gp->opy); + + radius = gp->radius; + if (mission != MI_RESERVE) /* XXX */ + oprange(gp, type, &radius); + + if (dist > radius) + continue; + + /* Ok, it is within the operations range. */ + /* Now check from where the object actually is */ + dist = mapdist(x, y, gp->x, gp->y); + radius = 999; + oprange(gp, type, &radius); + if (dist > radius) + continue; + /* Ok, the object can get to where the x,y is */ + + if (opt_SLOW_WAR) { + if (mission != MI_AIR_DEFENSE) { + getsect(x, y, (s_char *)§); + if (getrel(getnatp(gp->own), sect.sct_own) > AT_WAR) { + + /* + * If the player->owner of the unit isn't at war + * with the victim, and doesn't own the + * sect being acted upon, and isn't the + * old player->owner of that sect, bounce them. + */ + if (sect.sct_type != SCT_WATER && + sect.sct_own != gp->own && + sect.sct_oldown != gp->own) + continue; } + } + } - glp = (struct genlist *) malloc(sizeof(struct genlist)); - bzero((s_char *)glp,sizeof(struct genlist)); - glp->x = gp->x; - glp->y = gp->y; - glp->type = type; - switch(type){ - case EF_LAND: glp->cp = (s_char *)&lchr[(int)gp->type]; - break; - case EF_SHIP: glp->cp = (s_char *)&mchr[(int)gp->type]; - break; - case EF_PLANE: glp->cp = (s_char *)&plchr[(int)gp->type]; - break; - } - glp->thing = (s_char *)malloc(size); - bcopy(block,glp->thing,size); - emp_insque(&glp->queue, &mi[gp->own].queue); - } + glp = (struct genlist *)malloc(sizeof(struct genlist)); + bzero((s_char *)glp, sizeof(struct genlist)); + glp->x = gp->x; + glp->y = gp->y; + glp->type = type; + switch (type) { + case EF_LAND: + glp->cp = (s_char *)&lchr[(int)gp->type]; + break; + case EF_SHIP: + glp->cp = (s_char *)&mchr[(int)gp->type]; + break; + case EF_PLANE: + glp->cp = (s_char *)&plchr[(int)gp->type]; + break; + } + glp->thing = (s_char *)malloc(size); + bcopy(block, glp->thing, size); + emp_insque(&glp->queue, &mi[gp->own].queue); + } } void find_escorts(coord x, coord y, natid cn, struct emp_qelem *escorts) { - struct nstr_item ni; - struct plist *plp; - struct plnstr plane; - int dist; - - snxtitem_all(&ni,EF_PLANE); - while(nxtitem(&ni, (s_char *)&plane)){ - if (plane.pln_own != cn) - continue; - - if (plane.pln_mission != MI_ESCORT) - continue; - - dist = mapdist(x,y,plane.pln_x,plane.pln_y); - - if (dist > ((int)((float)plane.pln_range/2.0)) ) - continue; - - plp = (struct plist *) malloc(sizeof(struct plist)); - bzero((s_char *)plp,sizeof(struct plist)); - plp->pcp = &plchr[(int)plane.pln_type]; - bcopy((s_char *)&plane,(s_char *)&plp->plane,sizeof(struct plnstr)); - emp_insque(&plp->queue, escorts); - } + struct nstr_item ni; + struct plist *plp; + struct plnstr plane; + int dist; + + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own != cn) + continue; + + if (plane.pln_mission != MI_ESCORT) + continue; + + dist = mapdist(x, y, plane.pln_x, plane.pln_y); + + if (dist > ((int)((float)plane.pln_range / 2.0))) + continue; + + plp = (struct plist *)malloc(sizeof(struct plist)); + bzero((s_char *)plp, sizeof(struct plist)); + plp->pcp = &plchr[(int)plane.pln_type]; + bcopy((s_char *)&plane, (s_char *)&plp->plane, + sizeof(struct plnstr)); + emp_insque(&plp->queue, escorts); + } } int -perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, int mission, s_char *s, int hardtarget) +perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, + int mission, s_char *s, int hardtarget) { - extern int land_max_interdiction_range; - extern int ship_max_interdiction_range; - s_char *mission_name(short int mission), *nameofitem(s_char *buf, struct genitem *gp, int type); - struct emp_qelem *qp, missiles, bombers, escorts, airp, b, e; - struct emp_qelem *newqp; - struct genlist *glp; - struct plist *plp; - struct genitem *gp; - struct lndstr *lp; - struct shpstr *sp; - struct sctstr sect; - struct lchrstr *lcp; - struct mchrstr *mcp; - struct plchrstr *pcp; - int dam=0,dam2, mission_flags, tech; - natid plane_owner = 0; - int gun,shell,md, air_dam=0; - double range2, prb, range, mobcost, hitchance; - extern int torpedo_damage; - - getsect(x,y,§); - - emp_initque(&missiles); - emp_initque(&bombers); - emp_initque(&escorts); - emp_initque(&airp); - - for(qp = list->q_forw; qp != list; qp = qp->q_forw){ - glp = (struct genlist *)qp; - gp = (struct genitem *)glp->thing; - - md = mapdist(x,y,gp->x,gp->y); - - if (glp->type == EF_LAND){ - lp = (struct lndstr *)glp->thing; - lcp = (struct lchrstr *)glp->cp; - - if (lp->lnd_effic < LAND_MINFIREEFF) - continue; - - if (mission == MI_SINTERDICT) - continue; - - if ((mission == MI_INTERDICT) && - (md > land_max_interdiction_range)) - continue; - - if (md > (lp->lnd_frg / 2)) - continue; - - if (lnd_getmil(lp) < 1) - continue; - - range = techfact((int)lp->lnd_tech, - (double)lp->lnd_frg / 2.0); - range2 = (double)roundrange(range); - - if (md > range2) - continue; - - shell = getvar(V_SHELL, (s_char *)lp, EF_LAND); - gun = getvar(V_GUN, (s_char *)lp, EF_LAND); - if (shell == 0 || gun == 0) - continue; - - if (has_supply(lp)){ - use_supply(lp); - putland(lp->lnd_uid, lp); - dam2 = ldround(landunitgun(lp->lnd_effic, lp->lnd_dam, gun, - lp->lnd_ammo, shell),1); - if (sect.sct_type == SCT_WATER){ - double dam3 = (double)dam2; - if (chance(((double)lp->lnd_acc)/100.0)) - dam2=ldround((dam3/2.0),1); - } - dam += dam2; - if (sect.sct_type == SCT_WATER) - nreport(lp->lnd_own,N_SHP_SHELL,victim,1); - else - nreport(lp->lnd_own,N_SCT_SHELL,victim,1); - wu(0,lp->lnd_own, - "%s fires at %s %s at %s\n", - prland(lp), cname(victim), - s, xyas(x,y,lp->lnd_own)); - - mpr(victim, "%s %s fires at you at %s\n", - cname(lp->lnd_own), prland(lp), - xyas(x,y,victim)); - } - }else if (glp->type == EF_SHIP){ - sp = (struct shpstr *)glp->thing; - mcp = (struct mchrstr *)glp->cp; - - if (sp->shp_effic < 60) - continue; - if (sp->shp_frnge == 0) - continue; - if (((mission == MI_INTERDICT) || - (mission == MI_SINTERDICT)) && - (md > ship_max_interdiction_range)) - continue; - if (getvar(V_MILIT, (s_char *)sp, EF_SHIP) < 1) - continue; + extern int land_max_interdiction_range; + extern int ship_max_interdiction_range; + s_char *mission_name(short int mission), *nameofitem(s_char *buf, + struct genitem + *gp, int type); + struct emp_qelem *qp, missiles, bombers, escorts, airp, b, e; + struct emp_qelem *newqp; + struct genlist *glp; + struct plist *plp; + struct genitem *gp; + struct lndstr *lp; + struct shpstr *sp; + struct sctstr sect; + struct lchrstr *lcp; + struct mchrstr *mcp; + struct plchrstr *pcp; + int dam = 0, dam2, mission_flags, tech; + natid plane_owner = 0; + int gun, shell, md, air_dam = 0; + double range2, prb, range, mobcost, hitchance; + extern int torpedo_damage; + + getsect(x, y, §); + + emp_initque(&missiles); + emp_initque(&bombers); + emp_initque(&escorts); + emp_initque(&airp); + + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + glp = (struct genlist *)qp; + gp = (struct genitem *)glp->thing; + + md = mapdist(x, y, gp->x, gp->y); + + if (glp->type == EF_LAND) { + lp = (struct lndstr *)glp->thing; + lcp = (struct lchrstr *)glp->cp; + + if (lp->lnd_effic < LAND_MINFIREEFF) + continue; + + if (mission == MI_SINTERDICT) + continue; + + if ((mission == MI_INTERDICT) && + (md > land_max_interdiction_range)) + continue; + + if (md > (lp->lnd_frg / 2)) + continue; + + if (lnd_getmil(lp) < 1) + continue; + + range = techfact((int)lp->lnd_tech, (double)lp->lnd_frg / 2.0); + range2 = (double)roundrange(range); + + if (md > range2) + continue; + + shell = getvar(V_SHELL, (s_char *)lp, EF_LAND); + gun = getvar(V_GUN, (s_char *)lp, EF_LAND); + if (shell == 0 || gun == 0) + continue; + + if (has_supply(lp)) { + use_supply(lp); + putland(lp->lnd_uid, lp); + dam2 = ldround(landunitgun(lp->lnd_effic, lp->lnd_dam, gun, + lp->lnd_ammo, shell), 1); + if (sect.sct_type == SCT_WATER) { + double dam3 = (double)dam2; + if (chance(((double)lp->lnd_acc) / 100.0)) + dam2 = ldround((dam3 / 2.0), 1); + } + dam += dam2; + if (sect.sct_type == SCT_WATER) + nreport(lp->lnd_own, N_SHP_SHELL, victim, 1); + else + nreport(lp->lnd_own, N_SCT_SHELL, victim, 1); + wu(0, lp->lnd_own, + "%s fires at %s %s at %s\n", + prland(lp), cname(victim), s, xyas(x, y, lp->lnd_own)); + + mpr(victim, "%s %s fires at you at %s\n", + cname(lp->lnd_own), prland(lp), xyas(x, y, victim)); + } + } else if (glp->type == EF_SHIP) { + sp = (struct shpstr *)glp->thing; + mcp = (struct mchrstr *)glp->cp; + + if (sp->shp_effic < 60) + continue; + if (sp->shp_frnge == 0) + continue; + if (((mission == MI_INTERDICT) || + (mission == MI_SINTERDICT)) && + (md > ship_max_interdiction_range)) + continue; + if (getvar(V_MILIT, (s_char *)sp, EF_SHIP) < 1) + continue; /* if ((mcp->m_flags & M_SUB) && (sect.sct_type != SCT_WATER)) continue; */ - if (mission == MI_SINTERDICT){ - if (!(mcp->m_flags & M_SONAR)) - continue; - if (!(mcp->m_flags & M_DCH) && - !(mcp->m_flags & M_SUBT)) - continue; - range2 = techfact(sp->shp_tech, - (double)mcp->m_vrnge); - range2 *= (double)sp->shp_effic / 200.0; - if (md > range2) - continue; - /* can't look all the time */ - if (chance(0.5)) - continue; - } - if (mcp->m_flags & M_SUB){ + if (mission == MI_SINTERDICT) { + if (!(mcp->m_flags & M_SONAR)) + continue; + if (!(mcp->m_flags & M_DCH) && !(mcp->m_flags & M_SUBT)) + continue; + range2 = techfact(sp->shp_tech, (double)mcp->m_vrnge); + range2 *= (double)sp->shp_effic / 200.0; + if (md > range2) + continue; + /* can't look all the time */ + if (chance(0.5)) + continue; + } + if (mcp->m_flags & M_SUB) { /* If we aren't shooting at "subs" or "ships" don't fire at all from a sub. */ - if (*s != 's') - continue; - if (sp->shp_mobil < (s_char)0) - continue; - gun = getvar(V_GUN,(s_char *)sp,EF_SHIP); - if (gun < 1) - continue; - shell = getvar(V_SHELL,(s_char *)sp,EF_SHIP); - if (shell < 3) - shell += supply_commod(sp->shp_own, - sp->shp_x,sp->shp_y,I_SHELL, - 3-shell); - if (shell < 3) - continue; - - range = sp->shp_effic* techfact(sp->shp_tech, - ((double)sp->shp_frnge)) / 100.0; - - range2 = (double)roundrange(range); - if (md > range) - continue; - - if (!line_of_sight((s_char **)0, x, y, - gp->x, gp->y)) - continue; - putvar(V_SHELL,shell-3,(s_char *)sp,EF_SHIP); - mobcost = sp->shp_effic * 0.01 * sp->shp_speed; - mobcost = (480.0/(mobcost + - techfact(sp->shp_tech, mobcost))); - sp->shp_mobil -= mobcost; - putship(sp->shp_uid,sp); - hitchance = DTORP_HITCHANCE(md, sp->shp_visib); - - wu(0,sp->shp_own, - "%s locking on %s %s in %s\n", - prship(sp),cname(victim),s, - xyas(x,y,sp->shp_own)); - wu(0,sp->shp_own, - "\tEffective torpedo range is %.1f\n", range); - wu(0,sp->shp_own, - "\tWhooosh... Hitchance = %d%%\n", - (int)(hitchance*100)); - - if (hitchance < 1.0 && !chance(hitchance)) { - wu(0,sp->shp_own, - "\tMissed\n"); - mpr(victim, "Incoming torpedo sighted @ %s missed (whew)!\n", - xyas(x,y,victim)); - continue; - } - wu(0,sp->shp_own, - "\tBOOM!...\n"); - dam2 = TORP_DAMAGE(); - - dam += dam2; - nreport(victim,N_TORP_SHIP,sp->shp_own,1); - wu(0,sp->shp_own, - "\tTorpedo hit %s %s for %d damage\n", - cname(victim),s,dam2); - - mpr(victim, - "Incoming torpedo sighted @ %s hits and does %d damage!\n", - xyas(x,y,victim), dam2); - }else{ - range = techfact(sp->shp_tech, - (double)mcp->m_frnge/2.0); - range2 = (double)roundrange(range); - if (md > range2) - continue; - gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); - gun = min(gun, sp->shp_glim); - shell = getvar(V_SHELL, (s_char *)sp, EF_SHIP); - if (shell < gun) - shell += supply_commod(sp->shp_own, - sp->shp_x,sp->shp_y,I_SHELL, - gun-shell); - gun = min(gun, shell); - gun = min(gun,(int)((float)getvar(V_MILIT, - (s_char *)sp,EF_SHIP)/2.0)); - if (gun ==0) - continue; - gun = max(gun,1); - dam2 = seagun(sp->shp_effic,gun); - if ( range2 == 0.0 ) - prb = 1.0; - else - prb = ((double)md) / range2; - prb *= prb; - if (chance(prb)) - dam2 = (int)((float)dam2/2.0); - dam += dam2; - if (sect.sct_type == SCT_WATER) - nreport(sp->shp_own,N_SHP_SHELL,victim,1); - else - nreport(sp->shp_own,N_SCT_SHELL,victim,1); - wu(0,sp->shp_own, - "%s fires at %s %s at %s\n", - prship(sp), - cname(victim), s, - xyas(x,y,sp->shp_own)); - - mpr(victim, "%s fires at you at %s\n", - cname(sp->shp_own), prship(sp), - xyas(x,y,victim)); - - putvar(V_SHELL,shell-gun,(s_char *)sp, EF_SHIP); - putship(sp->shp_uid,sp); - } - }else if (glp->type == EF_PLANE) { - pcp = (struct plchrstr *)glp->cp; - if (pcp->pl_flags & P_M) - /* units have their own missile interdiction */ - if (hardtarget != SECT_HARDTARGET || - pcp->pl_flags & P_MAR) - continue; - - /* save planes for later */ - plp = (struct plist *)malloc(sizeof(struct plist)); - - bzero((s_char *)plp,sizeof(struct plist)); - plp->pcp = pcp; - bcopy(glp->thing, (s_char *)&plp->plane, - sizeof(struct plnstr)); - if (plp->pcp->pl_flags & P_M) - emp_insque(&plp->queue, &missiles); - else - emp_insque(&plp->queue, &bombers); - plane_owner = plp->plane.pln_own; - } - } - if (!QEMPTY(&missiles)) { - /* I arbitrarily chose 100 mindam -KHS */ - dam += msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100, "sector", victim, mission); - qp=missiles.q_forw; - while(qp != (&missiles)){ - qp=qp->q_forw; - free(qp); - } - } - - if (QEMPTY(&bombers)) { - qp=list->q_forw; - while(qp != list){ - glp = (struct genlist *)qp; - qp=qp->q_forw; - - free(glp->thing); - free((s_char *)glp); - } - return dam; - } - /* - * If there are planes performing an - * interdict or support mission, find - * some escorts for them, if possible. - * Up to 2 per bomber, if possible. - */ - find_escorts(x,y,plane_owner,&escorts); - - if (mission == MI_SINTERDICT) - mission_pln_sel(&bombers,P_T|P_A,0,hardtarget); - else - mission_pln_sel(&bombers,P_T,P_A,SECT_HARDTARGET); - - mission_pln_sel(&escorts,P_ESC|P_F,0,SECT_HARDTARGET); - - for(qp = bombers.q_forw; qp != (&bombers); qp = qp->q_forw){ - plp = (struct plist *)qp; - if (!find_airport(&airp,plp->plane.pln_x,plp->plane.pln_y)) - add_airport(&airp,plp->plane.pln_x, - plp->plane.pln_y); - } - - for(qp = airp.q_forw; qp != (&airp); qp = qp->q_forw){ - struct airport *air; - s_char pp[512]; - - air = (struct airport *)qp; - md = mapdist(x,y,air->x,air->y); - - emp_initque(&b); - emp_initque(&e); - - /* Split off the bombers at this base into b */ - divide(&bombers,&b,air->x,air->y); - - /* Split off the escorts at this base into e */ - divide(&escorts,&e,air->x,air->y); - - tech = 0; - mission_flags = 0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - - mission_flags = mission_pln_arm(&b,air->x,air->y,2*md,'p',0, - 0,mission_flags,&tech); - - if (QEMPTY(&b)){ - continue; - } - - mission_flags = mission_pln_arm(&e,air->x,air->y,2*md,'p',0, - P_F|P_ESC,mission_flags,&tech); - - BestAirPath(pp, air->x, air->y, x, y); - wu(0, plane_owner, "Flying %s mission from %s\n", - mission_name(mission), xyas(air->x, air->y, plane_owner)); - if (air->own && (air->own != plane_owner)) { - wu(0, air->own, "%s is flying %s mission from %s\n", - cname(plane_owner), mission_name(mission), - xyas(air->x, air->y, air->own)); + if (*s != 's') + continue; + if (sp->shp_mobil < (s_char)0) + continue; + gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); + if (gun < 1) + continue; + shell = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + if (shell < 3) + shell += supply_commod(sp->shp_own, + sp->shp_x, sp->shp_y, I_SHELL, + 3 - shell); + if (shell < 3) + continue; + + range = sp->shp_effic * techfact(sp->shp_tech, + ((double)sp->shp_frnge)) / + 100.0; + + range2 = (double)roundrange(range); + if (md > range) + continue; + + if (!line_of_sight((s_char **)0, x, y, gp->x, gp->y)) + continue; + putvar(V_SHELL, shell - 3, (s_char *)sp, EF_SHIP); + mobcost = sp->shp_effic * 0.01 * sp->shp_speed; + mobcost = (480.0 / (mobcost + + techfact(sp->shp_tech, mobcost))); + sp->shp_mobil -= mobcost; + putship(sp->shp_uid, sp); + hitchance = DTORP_HITCHANCE(md, sp->shp_visib); + + wu(0, sp->shp_own, + "%s locking on %s %s in %s\n", + prship(sp), cname(victim), s, xyas(x, y, sp->shp_own)); + wu(0, sp->shp_own, + "\tEffective torpedo range is %.1f\n", range); + wu(0, sp->shp_own, + "\tWhooosh... Hitchance = %d%%\n", + (int)(hitchance * 100)); + + if (hitchance < 1.0 && !chance(hitchance)) { + wu(0, sp->shp_own, "\tMissed\n"); + mpr(victim, + "Incoming torpedo sighted @ %s missed (whew)!\n", + xyas(x, y, victim)); + continue; } - - ac_encounter(&b,&e,air->x,air->y,pp,mission_flags,0, 0, 0); - - if (!QEMPTY(&b)) - air_dam += air_damage(&b,x,y,mission,victim,s,hardtarget); - - pln_put(&b); - pln_put(&e); - } - - if (air_dam > 0){ - dam += air_dam; + wu(0, sp->shp_own, "\tBOOM!...\n"); + dam2 = TORP_DAMAGE(); + + dam += dam2; + nreport(victim, N_TORP_SHIP, sp->shp_own, 1); + wu(0, sp->shp_own, + "\tTorpedo hit %s %s for %d damage\n", + cname(victim), s, dam2); + + mpr(victim, + "Incoming torpedo sighted @ %s hits and does %d damage!\n", + xyas(x, y, victim), dam2); + } else { + range = techfact(sp->shp_tech, (double)mcp->m_frnge / 2.0); + range2 = (double)roundrange(range); + if (md > range2) + continue; + gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); + gun = min(gun, sp->shp_glim); + shell = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + if (shell < gun) + shell += supply_commod(sp->shp_own, + sp->shp_x, sp->shp_y, I_SHELL, + gun - shell); + gun = min(gun, shell); + gun = min(gun, (int)((float)getvar(V_MILIT, + (s_char *)sp, + EF_SHIP) / 2.0)); + if (gun == 0) + continue; + gun = max(gun, 1); + dam2 = seagun(sp->shp_effic, gun); + if (range2 == 0.0) + prb = 1.0; + else + prb = ((double)md) / range2; + prb *= prb; + if (chance(prb)) + dam2 = (int)((float)dam2 / 2.0); + dam += dam2; if (sect.sct_type == SCT_WATER) - nreport(plane_owner,N_SHP_BOMB,victim,1); + nreport(sp->shp_own, N_SHP_SHELL, victim, 1); else - nreport(plane_owner,N_SCT_BOMB,victim,1); - } - - /* free up all this memory */ - qp=list->q_forw; - while(qp != list){ - glp = (struct genlist *)qp; - qp=qp->q_forw; - - free(glp->thing); - free((s_char *)glp); + nreport(sp->shp_own, N_SCT_SHELL, victim, 1); + wu(0, sp->shp_own, + "%s fires at %s %s at %s\n", + prship(sp), cname(victim), s, xyas(x, y, sp->shp_own)); + + mpr(victim, "%s fires at you at %s\n", + cname(sp->shp_own), prship(sp), xyas(x, y, victim)); + + putvar(V_SHELL, shell - gun, (s_char *)sp, EF_SHIP); + putship(sp->shp_uid, sp); + } + } else if (glp->type == EF_PLANE) { + pcp = (struct plchrstr *)glp->cp; + if (pcp->pl_flags & P_M) + /* units have their own missile interdiction */ + if (hardtarget != SECT_HARDTARGET || pcp->pl_flags & P_MAR) + continue; + + /* save planes for later */ + plp = (struct plist *)malloc(sizeof(struct plist)); + + bzero((s_char *)plp, sizeof(struct plist)); + plp->pcp = pcp; + bcopy(glp->thing, (s_char *)&plp->plane, + sizeof(struct plnstr)); + if (plp->pcp->pl_flags & P_M) + emp_insque(&plp->queue, &missiles); + else + emp_insque(&plp->queue, &bombers); + plane_owner = plp->plane.pln_own; } - - qp = escorts.q_forw; - while(qp != (&escorts)){ - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + } + if (!QEMPTY(&missiles)) { + /* I arbitrarily chose 100 mindam -KHS */ + dam += + msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100, + "sector", victim, mission); + qp = missiles.q_forw; + while (qp != (&missiles)) { + qp = qp->q_forw; + free(qp); } - - qp=bombers.q_forw; - while(qp != (&bombers)){ - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + } + + if (QEMPTY(&bombers)) { + qp = list->q_forw; + while (qp != list) { + glp = (struct genlist *)qp; + qp = qp->q_forw; + + free(glp->thing); + free((s_char *)glp); } - return dam; + } + /* + * If there are planes performing an + * interdict or support mission, find + * some escorts for them, if possible. + * Up to 2 per bomber, if possible. + */ + find_escorts(x, y, plane_owner, &escorts); + + if (mission == MI_SINTERDICT) + mission_pln_sel(&bombers, P_T | P_A, 0, hardtarget); + else + mission_pln_sel(&bombers, P_T, P_A, SECT_HARDTARGET); + + mission_pln_sel(&escorts, P_ESC | P_F, 0, SECT_HARDTARGET); + + for (qp = bombers.q_forw; qp != (&bombers); qp = qp->q_forw) { + plp = (struct plist *)qp; + if (!find_airport(&airp, plp->plane.pln_x, plp->plane.pln_y)) + add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y); + } + + for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) { + struct airport *air; + s_char pp[512]; + + air = (struct airport *)qp; + md = mapdist(x, y, air->x, air->y); + + emp_initque(&b); + emp_initque(&e); + + /* Split off the bombers at this base into b */ + divide(&bombers, &b, air->x, air->y); + + /* Split off the escorts at this base into e */ + divide(&escorts, &e, air->x, air->y); + + tech = 0; + mission_flags = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + + mission_flags = mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', 0, + 0, mission_flags, &tech); + + if (QEMPTY(&b)) { + continue; + } + + mission_flags = mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', 0, + P_F | P_ESC, mission_flags, &tech); + + BestAirPath(pp, air->x, air->y, x, y); + wu(0, plane_owner, "Flying %s mission from %s\n", + mission_name(mission), xyas(air->x, air->y, plane_owner)); + if (air->own && (air->own != plane_owner)) { + wu(0, air->own, "%s is flying %s mission from %s\n", + cname(plane_owner), mission_name(mission), + xyas(air->x, air->y, air->own)); + } + + ac_encounter(&b, &e, air->x, air->y, pp, mission_flags, 0, 0, 0); + + if (!QEMPTY(&b)) + air_dam += + air_damage(&b, x, y, mission, victim, s, hardtarget); + + pln_put(&b); + pln_put(&e); + } + + if (air_dam > 0) { + dam += air_dam; + if (sect.sct_type == SCT_WATER) + nreport(plane_owner, N_SHP_BOMB, victim, 1); + else + nreport(plane_owner, N_SCT_BOMB, victim, 1); + } + + /* free up all this memory */ + qp = list->q_forw; + while (qp != list) { + glp = (struct genlist *)qp; + qp = qp->q_forw; + + free(glp->thing); + free((s_char *)glp); + } + + qp = escorts.q_forw; + while (qp != (&escorts)) { + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } + + qp = bombers.q_forw; + while (qp != (&bombers)) { + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } + + return dam; } int cando(int mission, int type) { - switch (mission){ - case MI_ESCORT: - if (type == EF_PLANE) - return 1; - return 0; - case MI_AIR_DEFENSE: - if (type == EF_PLANE) - return 1; - return 0; - case MI_SINTERDICT: - if ((type == EF_PLANE) || (type == EF_SHIP)) - return 1; - return 0; - case MI_INTERDICT: - return 1; - case MI_SUPPORT: - case MI_OSUPPORT: - case MI_DSUPPORT: - if (type == EF_PLANE) - return 1; - return 0; - case MI_RESERVE: - if (type == EF_LAND) - return 1; - return 0; - } - + switch (mission) { + case MI_ESCORT: + if (type == EF_PLANE) + return 1; + return 0; + case MI_AIR_DEFENSE: + if (type == EF_PLANE) + return 1; + return 0; + case MI_SINTERDICT: + if ((type == EF_PLANE) || (type == EF_SHIP)) + return 1; return 0; + case MI_INTERDICT: + return 1; + case MI_SUPPORT: + case MI_OSUPPORT: + case MI_DSUPPORT: + if (type == EF_PLANE) + return 1; + return 0; + case MI_RESERVE: + if (type == EF_LAND) + return 1; + return 0; + } + + return 0; } -s_char *nameofitem(s_char *buf, struct genitem *gp, int type) +s_char * +nameofitem(s_char *buf, struct genitem *gp, int type) { - switch(type){ - case EF_SHIP: - return prship((struct shpstr *)gp); - break; - case EF_PLANE: - return prplane((struct plnstr *)gp); - break; - case EF_LAND: - return prland((struct lndstr *)gp); - } - return NULL; + switch (type) { + case EF_SHIP: + return prship((struct shpstr *)gp); + break; + case EF_PLANE: + return prplane((struct plnstr *)gp); + break; + case EF_LAND: + return prland((struct lndstr *)gp); + } + return NULL; } -s_char *mission_short_name(int mission) +s_char * +mission_short_name(int mission) { - switch (mission){ - case MI_INTERDICT: return "interdict"; - case MI_SUPPORT: return "support "; - case MI_OSUPPORT: return "offensive"; - case MI_DSUPPORT: return "defensive"; - case MI_RESERVE: return "reserve "; - case MI_ESCORT: return "escort "; - case MI_SINTERDICT: return "interdict"; - case MI_AIR_DEFENSE: return "air def "; - default: return " "; - } + switch (mission) { + case MI_INTERDICT: + return "interdict"; + case MI_SUPPORT: + return "support "; + case MI_OSUPPORT: + return "offensive"; + case MI_DSUPPORT: + return "defensive"; + case MI_RESERVE: + return "reserve "; + case MI_ESCORT: + return "escort "; + case MI_SINTERDICT: + return "interdict"; + case MI_AIR_DEFENSE: + return "air def "; + default: + return " "; + } } -s_char *mission_name(short int mission) +s_char * +mission_name(short int mission) { - switch (mission){ - case MI_INTERDICT: return "an interdiction"; - case MI_SUPPORT: return "a support"; - case MI_OSUPPORT: return "a offensive support"; - case MI_DSUPPORT: return "a defensive support"; - case MI_RESERVE: return "a reserve"; - case MI_ESCORT: return "an escort"; - case MI_SINTERDICT: return "a sub interdiction"; - case MI_AIR_DEFENSE: return "an air defense"; - } - return "a mysterious"; + switch (mission) { + case MI_INTERDICT: + return "an interdiction"; + case MI_SUPPORT: + return "a support"; + case MI_OSUPPORT: + return "a offensive support"; + case MI_DSUPPORT: + return "a defensive support"; + case MI_RESERVE: + return "a reserve"; + case MI_ESCORT: + return "an escort"; + case MI_SINTERDICT: + return "a sub interdiction"; + case MI_AIR_DEFENSE: + return "an air defense"; + } + return "a mysterious"; } void show_mission(int type, struct nstr_item *np) { - int size, first=1, radius; - s_char *block; - struct genitem *gp; - s_char buf[128]; + int size, first = 1, radius; + s_char *block; + struct genitem *gp; + s_char buf[128]; - size = max(sizeof(struct lndstr),sizeof(struct plnstr)); - size = max(size,sizeof(struct shpstr)); - block = (s_char *)malloc(size); + size = max(sizeof(struct lndstr), sizeof(struct plnstr)); + size = max(size, sizeof(struct shpstr)); + block = (s_char *)malloc(size); + + while (nxtitem(np, block)) { + gp = (struct genitem *)block; + if (!player->owner || gp->own == 0) + continue; - while (nxtitem(np, block)) { - gp = (struct genitem *)block; - if (!player->owner || gp->own == 0) - continue; - - if (first){ - pr("Thing x,y op-sect rad mission\n"); - first=0; - } - pr("%-25s", nameofitem(buf, gp,type)); - pr(" %7s", xyas(gp->x,gp->y,player->cnum)); - if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT || - gp->mission == MI_OSUPPORT || - gp->mission == MI_DSUPPORT || - gp->mission == MI_AIR_DEFENSE){ - radius = 999; - oprange(gp,type,&radius); - pr(" %7s", xyas(gp->opx,gp->opy,player->cnum)); - if (radius < gp->radius) - pr(" %4d", radius); - else - pr(" %4d", gp->radius); - }else if (gp->mission == MI_RESERVE){ - struct sctstr sect; - int plus=2; - - getsect(gp->x,gp->y,§); - if ((sect.sct_type == SCT_HEADQ) && - (sect.sct_effic >= 60)) - plus++; - - if (((struct lndstr *)block)->lnd_rad_max == 0) - plus = 0; - else - plus += ((struct lndstr *)block)->lnd_rad_max; - pr(" %7s", xyas(gp->x,gp->y,player->cnum)); - pr(" %4d", plus); - }else if (gp->mission == MI_ESCORT){ - pr(" "); - pr(" %4d", (int) - ((float)((struct plnstr *)block)->pln_range/2.0) - ); - }else - pr(" "); - if (gp->mission) - pr(" is on %s mission\n", - mission_name(gp->mission)); - else - pr(" has no mission.\n"); - } + if (first) { + pr("Thing x,y op-sect rad mission\n"); + first = 0; + } + pr("%-25s", nameofitem(buf, gp, type)); + pr(" %7s", xyas(gp->x, gp->y, player->cnum)); + if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT || + gp->mission == MI_OSUPPORT || + gp->mission == MI_DSUPPORT || gp->mission == MI_AIR_DEFENSE) { + radius = 999; + oprange(gp, type, &radius); + pr(" %7s", xyas(gp->opx, gp->opy, player->cnum)); + if (radius < gp->radius) + pr(" %4d", radius); + else + pr(" %4d", gp->radius); + } else if (gp->mission == MI_RESERVE) { + struct sctstr sect; + int plus = 2; + + getsect(gp->x, gp->y, §); + if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60)) + plus++; + + if (((struct lndstr *)block)->lnd_rad_max == 0) + plus = 0; + else + plus += ((struct lndstr *)block)->lnd_rad_max; + pr(" %7s", xyas(gp->x, gp->y, player->cnum)); + pr(" %4d", plus); + } else if (gp->mission == MI_ESCORT) { + pr(" "); + pr(" %4d", (int) + ((float)((struct plnstr *)block)->pln_range / 2.0) + ); + } else + pr(" "); + if (gp->mission) + pr(" is on %s mission\n", mission_name(gp->mission)); + else + pr(" has no mission.\n"); + } } int oprange(struct genitem *gp, int type, int *radius) { - double techfact(int, double); - int range; - struct shpstr ship; - struct lndstr land; - struct plnstr plane; - - switch (type){ - case EF_SHIP: - getship(gp->uid,&ship); - range = ldround(techfact(gp->tech, - (double)ship.shp_frnge / 2.0),1); - break; - case EF_LAND: - getland(gp->uid,&land); - range = ldround(techfact((int)land.lnd_tech, - (double)land.lnd_frg / 2.0),1); - break; - case EF_PLANE: - getplane(gp->uid,&plane); - /* missiles go one way, so we can use all the range */ - if (plchr[(int)plane.pln_type].pl_flags & P_M) - range = plane.pln_range; - else - range = ldround((double)plane.pln_range/2.0,1);; - break; - } - - if ((*radius) > range) - *radius = range; - - return range; + double techfact(int, double); + int range; + struct shpstr ship; + struct lndstr land; + struct plnstr plane; + + switch (type) { + case EF_SHIP: + getship(gp->uid, &ship); + range = ldround(techfact(gp->tech, + (double)ship.shp_frnge / 2.0), 1); + break; + case EF_LAND: + getland(gp->uid, &land); + range = ldround(techfact((int)land.lnd_tech, + (double)land.lnd_frg / 2.0), 1); + break; + case EF_PLANE: + getplane(gp->uid, &plane); + /* missiles go one way, so we can use all the range */ + if (plchr[(int)plane.pln_type].pl_flags & P_M) + range = plane.pln_range; + else + range = ldround((double)plane.pln_range / 2.0, 1);; + break; + } + + if ((*radius) > range) + *radius = range; + + return range; } /* @@ -988,189 +1006,191 @@ oprange(struct genitem *gp, int type, int *radius) * the mission from the plane list. */ void -mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, int hardtarget) +mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, + int hardtarget) { - struct emp_qelem *qp, *next; - struct plnstr *pp; - struct shpstr ship; - struct lndstr land; - struct sctstr sect; - struct plchrstr *pcp; - struct plist *plp; - register int y, bad, bad1; - unsigned int x; - - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *)qp; - pp = &plp->plane; - pcp = plp->pcp; - - if (pp->pln_effic < 40){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - - if (pp->pln_mobil < 1) { - emp_remque(qp); - free((s_char *)qp); - continue; - } + struct emp_qelem *qp, *next; + struct plnstr *pp; + struct shpstr ship; + struct lndstr land; + struct sctstr sect; + struct plchrstr *pcp; + struct plist *plp; + register int y, bad, bad1; + unsigned int x; + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + pp = &plp->plane; + pcp = plp->pcp; + + if (pp->pln_effic < 40) { + emp_remque(qp); + free((s_char *)qp); + continue; + } - if (opt_MARKET) { - if (ontradingblock(EF_PLANE, (int *)pp)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } + if (pp->pln_mobil < 1) { + emp_remque(qp); + free((s_char *)qp); + continue; + } - bad=0; - bad1=0; - if (wantflags) { - for(x=0;xpl_flags & y) != y){ - switch(y){ - case P_F: - case P_ESC: bad1=2; - break; - case P_E: - case P_L: - case P_K: bad1=1; - break; - default: bad=1; - } - } - } - if (bad){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (bad1 == 2){ - if ((pcp->pl_flags & P_ESC) || - (pcp->pl_flags & P_F)) - bad1=0; - } - if (bad1 == 1){ - if ((pcp->pl_flags & P_E) || - (pcp->pl_flags & P_K) || - (pcp->pl_flags & P_L)) - bad1=0; - } - if (bad1){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - bad=0; - bad1=0; - if (nowantflags) { - for(x=0;xpl_flags & y) == y) - bad=1; - } - if (bad){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - if (pp->pln_ship >= 0) { - if (!getship(pp->pln_ship, &ship)){ - shipsunk: - pp->pln_effic = 0; - putplane(pp->pln_uid, pp); - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (!can_be_on_ship(pp->pln_uid,ship.shp_uid)) { - goto shipsunk; - } - if (ship.shp_effic < SHIP_MINEFF){ - goto shipsunk; - } - /* Can't fly off of ships < 50%, or non-owned or non-allied ships */ - if ((ship.shp_effic < 50) || - ((ship.shp_own != pp->pln_own) && - (getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED))) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - if (pp->pln_land >= 0) { - if (!getland(pp->pln_land, &land)){ - landdead: - pp->pln_effic = 0; - putplane(pp->pln_uid, pp); - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (!(pcp->pl_flags & P_E)) - goto landdead; - if (land.lnd_effic < LAND_MINEFF) - goto landdead; - - /* Can't fly off of units < 50%, or non-owned or non-allied units */ - if ((land.lnd_effic < 50) || - ((land.lnd_own != pp->pln_own) && - (getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED))) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - - /* Can't fly off units in ships or other units */ - if ((land.lnd_ship >= 0) || (land.lnd_land >= 0)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - /* Now, check the sector status if not on a plane or unit */ - if ((pp->pln_ship < 0) && (pp->pln_land < 0)) { - /* If we can't get the sector, we can't check it, and can't fly */ - if (!getsect(pp->pln_x, pp->pln_y, §)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* First, check allied status */ - /* Can't fly from non-owned sectors or non-allied sectors */ - if ((sect.sct_own != pp->pln_own) && - (getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* non-vtol plane */ - if ((pcp->pl_flags & P_V) == 0) { - if ((sect.sct_type != SCT_AIRPT) || (sect.sct_effic < 40)) { - emp_remque(qp); - free((s_char *)qp); - continue; + if (opt_MARKET) { + if (ontradingblock(EF_PLANE, (int *)pp)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + + bad = 0; + bad1 = 0; + if (wantflags) { + for (x = 0; x < sizeof(wantflags) * 8; x++) { + y = (1 << x); + if ((wantflags & y) == y) + if ((pcp->pl_flags & y) != y) { + switch (y) { + case P_F: + case P_ESC: + bad1 = 2; + break; + case P_E: + case P_L: + case P_K: + bad1 = 1; + break; + default: + bad = 1; } } + } + if (bad) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (bad1 == 2) { + if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F)) + bad1 = 0; + } + if (bad1 == 1) { + if ((pcp->pl_flags & P_E) || + (pcp->pl_flags & P_K) || (pcp->pl_flags & P_L)) + bad1 = 0; + } + if (bad1) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + bad = 0; + bad1 = 0; + if (nowantflags) { + for (x = 0; x < sizeof(nowantflags) * 8; x++) { + y = (1 << x); + if ((nowantflags & y) == y) + if ((pcp->pl_flags & y) == y) + bad = 1; + } + if (bad) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + if (pp->pln_ship >= 0) { + if (!getship(pp->pln_ship, &ship)) { + shipsunk: + pp->pln_effic = 0; + putplane(pp->pln_uid, pp); + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (!can_be_on_ship(pp->pln_uid, ship.shp_uid)) { + goto shipsunk; + } + if (ship.shp_effic < SHIP_MINEFF) { + goto shipsunk; + } + /* Can't fly off of ships < 50%, or non-owned or non-allied ships */ + if ((ship.shp_effic < 50) || + ((ship.shp_own != pp->pln_own) && + (getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED))) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + if (pp->pln_land >= 0) { + if (!getland(pp->pln_land, &land)) { + landdead: + pp->pln_effic = 0; + putplane(pp->pln_uid, pp); + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (!(pcp->pl_flags & P_E)) + goto landdead; + if (land.lnd_effic < LAND_MINEFF) + goto landdead; + + /* Can't fly off of units < 50%, or non-owned or non-allied units */ + if ((land.lnd_effic < 50) || + ((land.lnd_own != pp->pln_own) && + (getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED))) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + + /* Can't fly off units in ships or other units */ + if ((land.lnd_ship >= 0) || (land.lnd_land >= 0)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + /* Now, check the sector status if not on a plane or unit */ + if ((pp->pln_ship < 0) && (pp->pln_land < 0)) { + /* If we can't get the sector, we can't check it, and can't fly */ + if (!getsect(pp->pln_x, pp->pln_y, §)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + /* First, check allied status */ + /* Can't fly from non-owned sectors or non-allied sectors */ + if ((sect.sct_own != pp->pln_own) && + (getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + /* non-vtol plane */ + if ((pcp->pl_flags & P_V) == 0) { + if ((sect.sct_type != SCT_AIRPT) || (sect.sct_effic < 40)) { + emp_remque(qp); + free((s_char *)qp); + continue; } - if (pcp->pl_flags & P_A) { - if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } + } + } + if (pcp->pl_flags & P_A) { + if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } - putplane(pp->pln_uid, pp); - } + putplane(pp->pln_uid, pp); + } } /* @@ -1178,166 +1198,168 @@ mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, int hard * */ int -mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, int mission, struct ichrstr *ip, int flags, int mission_flags, int *tech) +mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, + int mission, struct ichrstr *ip, int flags, + int mission_flags, int *tech) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *plp; - - if (*tech == 0) - *tech = 9999; - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *) qp; - - if (plp->plane.pln_x != x) - continue; - if (plp->plane.pln_y != y) - continue; - - if (mission_pln_equip(plp, ip, flags, mission) < 0) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (flags & (P_S|P_I)) { - if(plp->pcp->pl_flags & P_S) - mission_flags |= P_S; - if(plp->pcp->pl_flags & P_I) - mission_flags |= P_I; - } - if (*tech > plp->plane.pln_tech) - *tech = plp->plane.pln_tech; - if (!(plp->pcp->pl_flags & P_H)) - /* no stealth on this mission */ - mission_flags &= ~P_H; - if (!(plp->pcp->pl_flags & P_X)) - /* no stealth on this mission */ - mission_flags &= ~P_X; - if (!(plp->pcp->pl_flags & P_A)) { - /* no asw on this mission */ - mission_flags &= ~P_A; - } - if (!(plp->pcp->pl_flags & P_MINE)) { - /* no asw on this mission */ - mission_flags &= ~P_MINE; - } - - /* - * Mob costs for missions are 1/2 normal - * Not anymore. :) - */ + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *plp; + + if (*tech == 0) + *tech = 9999; + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + + if (plp->plane.pln_x != x) + continue; + if (plp->plane.pln_y != y) + continue; + + if (mission_pln_equip(plp, ip, flags, mission) < 0) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (flags & (P_S | P_I)) { + if (plp->pcp->pl_flags & P_S) + mission_flags |= P_S; + if (plp->pcp->pl_flags & P_I) + mission_flags |= P_I; + } + if (*tech > plp->plane.pln_tech) + *tech = plp->plane.pln_tech; + if (!(plp->pcp->pl_flags & P_H)) + /* no stealth on this mission */ + mission_flags &= ~P_H; + if (!(plp->pcp->pl_flags & P_X)) + /* no stealth on this mission */ + mission_flags &= ~P_X; + if (!(plp->pcp->pl_flags & P_A)) { + /* no asw on this mission */ + mission_flags &= ~P_A; + } + if (!(plp->pcp->pl_flags & P_MINE)) { + /* no asw on this mission */ + mission_flags &= ~P_MINE; + } + + /* + * Mob costs for missions are 1/2 normal + * Not anymore. :) + */ /* plp->plane.pln_mobil -= pln_mobcost(dist,&plp->plane,flags)/2;*/ - plp->plane.pln_mobil -= pln_mobcost(dist,&plp->plane,flags); + plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags); - } - return mission_flags; + } + return mission_flags; } int -mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission) +mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, + s_char mission) { - register struct plchrstr *pcp; - struct plnstr *pp; - int needed; - struct lndstr land; - struct shpstr ship; - struct sctstr sect; - int type; - s_char *ptr; - int item; - int rval; - int vec[I_MAX+1]; - - pp = &plp->plane; - pcp = plp->pcp; - if (pp->pln_ship >= 0) { - getship(pp->pln_ship, &ship); - type = EF_SHIP; - ptr = (s_char *) &ship; - } else - if (pp->pln_land >= 0) { - getland(pp->pln_land, &land); - type = EF_LAND; - ptr = (s_char *) &land; - } else { - getsect(pp->pln_x, pp->pln_y, §); - type = EF_SECTOR; - ptr = (s_char *) § - } - getvec(VT_ITEM, vec, ptr, type); - if (pcp->pl_fuel > vec[I_PETROL]) { - return -1; - } - vec[I_PETROL] -= pcp->pl_fuel; - rval = 0; - if (!(flags & P_F)) { - item = 0; - needed = 0; - switch (mission) { - case 's': - case 'p': - if (pp->pln_nuketype == -1) { - item = I_SHELL; - needed = pp->pln_load; - } - break; - case 't': - if ((pcp->pl_flags & P_C) == 0 || ip == 0) - break; - item = ip - ichr; - needed = (pp->pln_load * 2) / ip->i_lbs; - break; - case 'd': - if ((pcp->pl_flags & P_C) == 0 || ip == 0) - break; - item = ip - ichr; - needed = (pp->pln_load * 2) / ip->i_lbs; - break; - case 'a': - if ((pcp->pl_flags & (P_V|P_C)) == 0) - break; - item = I_MILIT; - needed = pp->pln_load / ip->i_lbs; - break; - case 'n': - if (pp->pln_nuketype == -1) - rval = -1; - break; - case 'i': /* missile interception */ - if (pp->pln_load) { - item = I_SHELL; - needed = pp->pln_load; - } - break; - default: - break; - } - if (rval < 0 || (item && needed <= 0)) { - return -1; - } - if ((vec[item] < needed) && (item == I_SHELL)) - vec[item] += supply_commod(plp->plane.pln_own, - plp->plane.pln_x,plp->plane.pln_y, - I_SHELL,needed); - if (vec[item] < needed) { - return -1; - } else { - vec[item] -= needed; - } - if (item == I_SHELL && (mission == 's' || mission == 'p')) - plp->bombs = needed; - else - plp->misc = needed; - } - putvec(VT_ITEM, vec, ptr, type); - if (type == EF_SHIP) - putship(ship.shp_uid,&ship); - else if (type == EF_LAND) - putland(land.lnd_uid,&land); - else - putsect(§); - return rval; + register struct plchrstr *pcp; + struct plnstr *pp; + int needed; + struct lndstr land; + struct shpstr ship; + struct sctstr sect; + int type; + s_char *ptr; + int item; + int rval; + int vec[I_MAX + 1]; + + pp = &plp->plane; + pcp = plp->pcp; + if (pp->pln_ship >= 0) { + getship(pp->pln_ship, &ship); + type = EF_SHIP; + ptr = (s_char *)&ship; + } else if (pp->pln_land >= 0) { + getland(pp->pln_land, &land); + type = EF_LAND; + ptr = (s_char *)&land; + } else { + getsect(pp->pln_x, pp->pln_y, §); + type = EF_SECTOR; + ptr = (s_char *)§ + } + getvec(VT_ITEM, vec, ptr, type); + if (pcp->pl_fuel > vec[I_PETROL]) { + return -1; + } + vec[I_PETROL] -= pcp->pl_fuel; + rval = 0; + if (!(flags & P_F)) { + item = 0; + needed = 0; + switch (mission) { + case 's': + case 'p': + if (pp->pln_nuketype == -1) { + item = I_SHELL; + needed = pp->pln_load; + } + break; + case 't': + if ((pcp->pl_flags & P_C) == 0 || ip == 0) + break; + item = ip - ichr; + needed = (pp->pln_load * 2) / ip->i_lbs; + break; + case 'd': + if ((pcp->pl_flags & P_C) == 0 || ip == 0) + break; + item = ip - ichr; + needed = (pp->pln_load * 2) / ip->i_lbs; + break; + case 'a': + if ((pcp->pl_flags & (P_V | P_C)) == 0) + break; + item = I_MILIT; + needed = pp->pln_load / ip->i_lbs; + break; + case 'n': + if (pp->pln_nuketype == -1) + rval = -1; + break; + case 'i': /* missile interception */ + if (pp->pln_load) { + item = I_SHELL; + needed = pp->pln_load; + } + break; + default: + break; + } + if (rval < 0 || (item && needed <= 0)) { + return -1; + } + if ((vec[item] < needed) && (item == I_SHELL)) + vec[item] += supply_commod(plp->plane.pln_own, + plp->plane.pln_x, plp->plane.pln_y, + I_SHELL, needed); + if (vec[item] < needed) { + return -1; + } else { + vec[item] -= needed; + } + if (item == I_SHELL && (mission == 's' || mission == 'p')) + plp->bombs = needed; + else + plp->misc = needed; + } + putvec(VT_ITEM, vec, ptr, type); + if (type == EF_SHIP) + putship(ship.shp_uid, &ship); + else if (type == EF_LAND) + putland(land.lnd_uid, &land); + else + putsect(§); + return rval; } /* @@ -1346,33 +1368,33 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char missi int find_airport(struct emp_qelem *airp, coord x, coord y) { - struct emp_qelem *qp; - struct airport *a; + struct emp_qelem *qp; + struct airport *a; - for (qp = airp->q_forw; qp != airp; qp = qp->q_forw){ - a = (struct airport *)qp; - if ((a->x == x) && (a->y == y)) - return 1; - } + for (qp = airp->q_forw; qp != airp; qp = qp->q_forw) { + a = (struct airport *)qp; + if ((a->x == x) && (a->y == y)) + return 1; + } - return 0; + return 0; } /* #*# This needs to be changed to include acc's -KHS */ void add_airport(struct emp_qelem *airp, coord x, coord y) { - struct airport *a; - struct sctstr sect; + struct airport *a; + struct sctstr sect; - a = (struct airport *)malloc(sizeof(struct airport)); + a = (struct airport *)malloc(sizeof(struct airport)); - a->x = x; - a->y = y; - getsect(x,y,§); - a->own = sect.sct_own; + a->x = x; + a->y = y; + getsect(x, y, §); + a->own = sect.sct_own; - emp_insque((struct emp_qelem *)a,airp); + emp_insque((struct emp_qelem *)a, airp); } /* @@ -1382,122 +1404,116 @@ add_airport(struct emp_qelem *airp, coord x, coord y) void divide(struct emp_qelem *l1, struct emp_qelem *l2, coord x, coord y) { - struct emp_qelem *qp, *next; - struct plist *plp; + struct emp_qelem *qp, *next; + struct plist *plp; - for (qp = l1->q_forw; qp != l1; qp = next){ - next = qp->q_forw; - plp = (struct plist *)qp; + for (qp = l1->q_forw; qp != l1; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; - if (plp->plane.pln_x != x) - continue; - if (plp->plane.pln_y != y) - continue; + if (plp->plane.pln_x != x) + continue; + if (plp->plane.pln_y != y) + continue; - emp_remque(qp); - emp_insque(qp,l2); - } + emp_remque(qp); + emp_insque(qp, l2); + } } int -air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, natid victim, s_char *s, int hardtarget) +air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, + natid victim, s_char *s, int hardtarget) { - struct emp_qelem *qp; - struct plist *plp; - struct plnstr *pp; - int newdam,dam=0; - int hitchance; - int nukedam; - - for(qp = bombers->q_forw; qp != bombers; qp = qp->q_forw){ - plp = (struct plist *)qp; - pp = &plp->plane; - - if ((mission == MI_SINTERDICT) && !(plp->pcp->pl_flags & P_A)) - continue; - - if (!plp->bombs) - continue; + struct emp_qelem *qp; + struct plist *plp; + struct plnstr *pp; + int newdam, dam = 0; + int hitchance; + int nukedam; - newdam = 0; - if (plp->pcp->pl_flags & P_A) { - if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { - wu(0,pp->pln_own, - "\t%s detects sub movement in %s\n", - prplane(pp), xyas(x,y,pp->pln_own)); - continue; - } - if (getrel(getnatp(pp->pln_own),victim) > HOSTILE) { - wu(0,pp->pln_own, - "\t%s tracks %s %s at %s\n", - prplane(pp), - cname(victim), s, xyas(x,y,pp->pln_own)); - continue; - } - wu(0,pp->pln_own, - "\t%s depth-charging %s %s in %s\n", - prplane(pp), - cname(victim), - s, - xyas(x,y,pp->pln_own)); - } else { - wu(0,pp->pln_own, - "\t%s pinbombing %s %s in %s\n", - prplane(pp), - cname(victim), - s, - xyas(x,y,pp->pln_own)); - } - hitchance = pln_hitchance(pp, hardtarget, EF_SHIP); - if (plp->plane.pln_nuketype != -1) - hitchance = 100; - else if (hardtarget != SECT_HARDTARGET) - wu(0,pp->pln_own,"\t\t%d%% hitchance...", hitchance); - /* Always calculate damage */ - if (roll(100) <= hitchance) { - newdam = pln_damage(&plp->plane,x,y,'p',&nukedam, 1); - if (nukedam) { - if (mission == MI_INTERDICT) { - wu(0,pp->pln_own, - "\t\tnuclear warhead does %d damage to %s %s\n", - prplane(pp), - nukedam, cname(victim), s); - dam += nukedam; - } - } else { - wu(0,pp->pln_own, - "\t\thit %s %s for %d damage\n", - cname(victim), s, newdam); - dam += newdam; - } - } else { - newdam = pln_damage(&plp->plane,x,y,'p',&nukedam, 0); - wu(0,pp->pln_own,"missed\n"); - if (mission == MI_SINTERDICT) { - mpr(victim, - "RUMBLE... your sub in %s hears a depth-charge explode nearby\n", - xyas(x,y,victim)); - } else if (*s == 's') { - mpr(victim, - "SPLASH! Bombs miss your %s in %s\n", - s, xyas(x,y,victim)); - } else { - mpr(victim, "SPLAT! Bombs miss your %s in %s\n", - s, xyas(x, y, victim)); - } - /* Now, even though we missed, the bombs - land somewhere. */ - collateral_damage(x, y, newdam, bombers); - } - - /* use up missiles */ - if (plp->pcp->pl_flags & P_M) { - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; + for (qp = bombers->q_forw; qp != bombers; qp = qp->q_forw) { + plp = (struct plist *)qp; + pp = &plp->plane; + + if ((mission == MI_SINTERDICT) && !(plp->pcp->pl_flags & P_A)) + continue; + + if (!plp->bombs) + continue; + + newdam = 0; + if (plp->pcp->pl_flags & P_A) { + if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { + wu(0, pp->pln_own, + "\t%s detects sub movement in %s\n", + prplane(pp), xyas(x, y, pp->pln_own)); + continue; + } + if (getrel(getnatp(pp->pln_own), victim) > HOSTILE) { + wu(0, pp->pln_own, + "\t%s tracks %s %s at %s\n", + prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own)); + continue; + } + wu(0, pp->pln_own, + "\t%s depth-charging %s %s in %s\n", + prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own)); + } else { + wu(0, pp->pln_own, + "\t%s pinbombing %s %s in %s\n", + prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own)); + } + hitchance = pln_hitchance(pp, hardtarget, EF_SHIP); + if (plp->plane.pln_nuketype != -1) + hitchance = 100; + else if (hardtarget != SECT_HARDTARGET) + wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance); + /* Always calculate damage */ + if (roll(100) <= hitchance) { + newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1); + if (nukedam) { + if (mission == MI_INTERDICT) { + wu(0, pp->pln_own, + "\t\tnuclear warhead does %d damage to %s %s\n", + prplane(pp), nukedam, cname(victim), s); + dam += nukedam; } - } + } else { + wu(0, pp->pln_own, + "\t\thit %s %s for %d damage\n", + cname(victim), s, newdam); + dam += newdam; + } + } else { + newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0); + wu(0, pp->pln_own, "missed\n"); + if (mission == MI_SINTERDICT) { + mpr(victim, + "RUMBLE... your sub in %s hears a depth-charge explode nearby\n", + xyas(x, y, victim)); + } else if (*s == 's') { + mpr(victim, + "SPLASH! Bombs miss your %s in %s\n", + s, xyas(x, y, victim)); + } else { + mpr(victim, "SPLAT! Bombs miss your %s in %s\n", + s, xyas(x, y, victim)); + } + /* Now, even though we missed, the bombs + land somewhere. */ + collateral_damage(x, y, newdam, bombers); + } - return dam; + /* use up missiles */ + if (plp->pcp->pl_flags & P_M) { + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_own = 0; + } + } + + return dam; } /* @@ -1506,41 +1522,42 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, natid victi * sector. If so, do air combat */ int -air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct emp_qelem *esc_list) +air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, + struct emp_qelem *esc_list) { - int dam=0,cn; - int mission_flags, tech, combat=0, rel, dist, z; - struct emp_qelem *qp, interceptors, airp, i, empty, *next; - struct plist *plp; - struct genlist *glp; - struct genitem *gp; - struct genlist mi[MAXNOC]; - s_char path[512]; - int count; - int tcount; - + int dam = 0, cn; + int mission_flags, tech, combat = 0, rel, dist, z; + struct emp_qelem *qp, interceptors, airp, i, empty, *next; + struct plist *plp; + struct genlist *glp; + struct genitem *gp; + struct genlist mi[MAXNOC]; + s_char path[512]; + int count; + int tcount; + count = 0; for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) count++; for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) count++; - - bzero((s_char *)mi,sizeof(mi)); + + bzero((s_char *)mi, sizeof(mi)); for (z = 1; z < MAXNOC; z++) emp_initque((struct emp_qelem *)&mi[z]); - - build_mission_list_type(mi,x,y,MI_AIR_DEFENSE,EF_PLANE,victim); - + + build_mission_list_type(mi, x, y, MI_AIR_DEFENSE, EF_PLANE, victim); + for (cn = 1; cn < MAXNOC; cn++) { /* Check our relations */ - rel = getrel(getnatp(cn),victim); - + rel = getrel(getnatp(cn), victim); + if (rel > HOSTILE) continue; - + if (QEMPTY(&mi[cn].queue)) continue; - + /* Ok, make a list of all the interceptors. Note that this *copies* the * list from the mission creation. This list must be deleted later. */ emp_initque(&interceptors); @@ -1550,15 +1567,15 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct glp = (struct genlist *)qp; gp = (struct genitem *)glp->thing; plp = (struct plist *)qp; - - dist = mapdist(x,y,gp->x,gp->y); - + + dist = mapdist(x, y, gp->x, gp->y); + plp = (struct plist *)malloc(sizeof(struct plist)); - bzero((s_char *)plp,sizeof(struct plist)); + bzero((s_char *)plp, sizeof(struct plist)); plp->pcp = (struct plchrstr *)glp->cp; bcopy(glp->thing, (s_char *)&plp->plane, sizeof(struct plnstr)); - + /* missiles go one way, so we can use all the range */ if (!(plp->pcp->pl_flags & P_M)) dist *= 2; @@ -1569,18 +1586,19 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct } emp_insque(&plp->queue, &interceptors); } - + /* Remove those who cannot go */ - mission_pln_sel(&interceptors,P_F,0,SECT_HARDTARGET); - + mission_pln_sel(&interceptors, P_F, 0, SECT_HARDTARGET); + if (QEMPTY(&interceptors)) continue; - + /* Now, delete all the extras, but delete the first ones, not the last ones, so - * that the higher numbered planes go into battle (they should be the better ones + * that the higher numbered planes go into battle (they should be the better ones * at fighting, if all went well.) */ tcount = 0; - for (qp = interceptors.q_forw; qp != (&interceptors); qp = qp->q_forw) + for (qp = interceptors.q_forw; qp != (&interceptors); + qp = qp->q_forw) tcount++; tcount -= (count * 2); /* Just in case there are more incoming than we have */ @@ -1599,27 +1617,28 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct /* Now, make a list of all the airports these planes are coming from */ emp_initque(&airp); - for (qp = interceptors.q_forw ; qp != (&interceptors); qp = qp->q_forw) { + for (qp = interceptors.q_forw; qp != (&interceptors); + qp = qp->q_forw) { plp = (struct plist *)qp; - if (!find_airport(&airp,plp->plane.pln_x, plp->plane.pln_y)) - add_airport(&airp,plp->plane.pln_x, plp->plane.pln_y); + if (!find_airport(&airp, plp->plane.pln_x, plp->plane.pln_y)) + add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y); } - + /* Now, fly them out one airport at a time */ for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) { - struct airport *air; - + struct airport *air; + air = (struct airport *)qp; - dist = mapdist(x,y,air->x,air->y); - + dist = mapdist(x, y, air->x, air->y); + emp_initque(&i); - + /* Split off the interceptors at this base into i */ divide(&interceptors, &i, air->x, air->y); - + tech = 0; mission_flags = 0; - mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_X; /* stealth (shhh) */ /* gets turned off if not all choppers */ mission_flags |= P_H; sam_intercept(bomb_list, &i, cn, victim, x, y, 0); @@ -1635,8 +1654,9 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct pln_put(&i); continue; } - mission_flags = mission_pln_arm(&i,air->x,air->y,2*dist,'r',0, - P_F,mission_flags,&tech); + mission_flags = + mission_pln_arm(&i, air->x, air->y, 2 * dist, 'r', 0, P_F, + mission_flags, &tech); /* Did we run out of interceptors? */ if (QEMPTY(&i)) @@ -1648,47 +1668,47 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct pln_put(&i); continue; } - + BestAirPath(path, air->x, air->y, x, y); wu(0, cn, "Flying %s mission from %s\n", - mission_name(MI_AIR_DEFENSE), - xyas(air->x, air->y, cn)); + mission_name(MI_AIR_DEFENSE), xyas(air->x, air->y, cn)); if (air->own && (air->own != cn)) { wu(0, air->own, "%s is flying %s mission from %s\n", cname(cn), mission_name(MI_AIR_DEFENSE), xyas(air->x, air->y, air->own)); } - + /* Now, fly the planes to the sector */ emp_initque(&empty); ac_encounter(&i, &empty, air->x, air->y, - path, mission_flags,1, bomb_list, esc_list); - + path, mission_flags, 1, bomb_list, esc_list); + /* If none made it, continue */ if (QEMPTY(&i)) continue; - + /* Some made it, so now they get to try to fight. */ /* Intercept the escorts first */ combat = 0; - if (!QEMPTY(esc_list)){ + if (!QEMPTY(esc_list)) { mpr(victim, "%s air defense planes intercept!\n", cname(cn)); ac_combat_headers(victim, cn); - ac_airtoair(esc_list,&i,air->own); + ac_airtoair(esc_list, &i, air->own); combat = 1; } /* Now intercept the bombers */ if (!QEMPTY(bomb_list)) { if (!combat) { - mpr(victim, "%s air defense planes intercept!\n", cname(cn)); + mpr(victim, "%s air defense planes intercept!\n", + cname(cn)); ac_combat_headers(victim, cn); } ac_airtoair(bomb_list, &i, air->own); PR(cn, "\n"); PR(victim, "\n"); } - + pln_put(&i); } } @@ -1707,6 +1727,3 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct return dam; } - - -