Inline get_land()'s "first time" case into its callers

ask_olist() and get_dlist() called get_land() with llp->chrp still
null, which made it initialize parts of llp instead of performing its
usual integrity check.  att_reacting_units() had the initialization
inline.  Change the other two to match, and simplify get_land().  No
functional change.
This commit is contained in:
Markus Armbruster 2010-01-02 08:53:25 +01:00
parent ef7ea8934f
commit b824495bad

View file

@ -1107,8 +1107,11 @@ ask_olist(int combat_mode, struct combat *off, struct combat *def,
memset(llp, 0, sizeof(struct ulist)); memset(llp, 0, sizeof(struct ulist));
emp_insque(&llp->queue, olist); emp_insque(&llp->queue, olist);
llp->mobil = mobcost; llp->mobil = mobcost;
if (!get_land(combat_mode, def, land.lnd_uid, llp, 0)) getland(land.lnd_uid, &llp->unit.land);
continue; llp->x = llp->unit.land.lnd_x;
llp->y = llp->unit.land.lnd_y;
llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *a_spyp) if (lnd_spyval(&land) > *a_spyp)
*a_spyp = lnd_spyval(&land); *a_spyp = lnd_spyval(&land);
if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER) if (((struct lchrstr *)llp->chrp)->l_flags & L_ENGINEER)
@ -1234,8 +1237,11 @@ get_dlist(struct combat *def, struct emp_qelem *list, int a_spy,
memset(llp, 0, sizeof(struct ulist)); memset(llp, 0, sizeof(struct ulist));
emp_insque(&llp->queue, list); emp_insque(&llp->queue, list);
llp->supplied = lnd_supply_all(&land); llp->supplied = lnd_supply_all(&land);
if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1)) getland(land.lnd_uid, &llp->unit.land);
continue; llp->x = llp->unit.land.lnd_x;
llp->y = llp->unit.land.lnd_y;
llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type];
llp->eff = llp->unit.land.lnd_effic;
if (lnd_spyval(&land) > *d_spyp) if (lnd_spyval(&land) > *d_spyp)
*d_spyp = lnd_spyval(&land); *d_spyp = lnd_spyval(&land);
} }
@ -1348,43 +1354,37 @@ get_land(int combat_mode, struct combat *def, int uid, struct ulist *llp,
getland(uid, lp); getland(uid, lp);
if (!llp->chrp) { /* first time */ if (lp->lnd_effic < LAND_MINEFF) {
llp->x = llp->unit.land.lnd_x; sprintf(buf, "was destroyed and is no longer a part of the %s",
llp->y = llp->unit.land.lnd_y; att_mode[combat_mode]);
llp->chrp = (struct empobj_chr *)&lchr[(int)llp->unit.land.lnd_type]; lnd_delete(llp, buf);
} else { /* not first time */ return 0;
if (lp->lnd_effic < LAND_MINEFF) { }
sprintf(buf, "was destroyed and is no longer a part of the %s", if (victim_land) {
if (lp->lnd_x != def->x || lp->lnd_y != def->y) {
lnd_delete(llp,
"left to go fight another battle and is no longer a part of the defense");
return 0;
}
} else {
if (lp->lnd_own != player->cnum) {
sprintf(buf,
"was destroyed and is no longer a part of the %s",
att_mode[combat_mode]); att_mode[combat_mode]);
lnd_delete(llp, buf); lnd_delete(llp, buf);
return 0; return 0;
} }
if (victim_land) { if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) {
if (lp->lnd_x != def->x || lp->lnd_y != def->y) { sprintf(buf,
lnd_delete(llp, "left to fight another battle and is no longer a part of the %s",
"left to go fight another battle and is no longer a part of the defense"); att_mode[combat_mode]);
return 0; lnd_delete(llp, buf);
} return 0;
} else { }
if (lp->lnd_own != player->cnum) { if (lp->lnd_effic < llp->eff) {
sprintf(buf, sprintf(buf, "damaged from %d%% to %d%%",
"was destroyed and is no longer a part of the %s", llp->eff, lp->lnd_effic);
att_mode[combat_mode]); lnd_print(llp, buf);
lnd_delete(llp, buf);
return 0;
}
if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) {
sprintf(buf,
"left to fight another battle and is no longer a part of the %s",
att_mode[combat_mode]);
lnd_delete(llp, buf);
return 0;
}
if (lp->lnd_effic < llp->eff) {
sprintf(buf, "damaged from %d%% to %d%%",
llp->eff, lp->lnd_effic);
lnd_print(llp, buf);
}
} }
} }
llp->eff = llp->unit.land.lnd_effic; llp->eff = llp->unit.land.lnd_effic;