subs: Factor lnd_check_one_mines() out of lnd_check_mines()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
b0221b9d2f
commit
5ce7419ef7
1 changed files with 25 additions and 17 deletions
|
@ -660,37 +660,45 @@ contains_engineer(struct emp_qelem *list)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
lnd_check_one_mines(struct ulist *llp, int with_eng)
|
||||||
|
{
|
||||||
|
struct sctstr sect;
|
||||||
|
|
||||||
|
getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
|
||||||
|
if (SCT_LANDMINES(§) == 0)
|
||||||
|
return 0;
|
||||||
|
if (relations_with(sect.sct_oldown, llp->unit.land.lnd_own) == ALLIED)
|
||||||
|
return 0;
|
||||||
|
if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
|
||||||
|
lnd_hit_mine(&llp->unit.land);
|
||||||
|
sect.sct_mines--;
|
||||||
|
putsect(§);
|
||||||
|
putland(llp->unit.land.lnd_uid, &llp->unit.land);
|
||||||
|
if (!llp->unit.land.lnd_own)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
lnd_check_mines(struct emp_qelem *land_list)
|
lnd_check_mines(struct emp_qelem *land_list)
|
||||||
{
|
{
|
||||||
struct emp_qelem *qp;
|
struct emp_qelem *qp;
|
||||||
struct emp_qelem *next;
|
struct emp_qelem *next;
|
||||||
struct ulist *llp;
|
struct ulist *llp;
|
||||||
struct sctstr sect;
|
|
||||||
int stopping = 0;
|
int stopping = 0;
|
||||||
int with_eng = contains_engineer(land_list);
|
int with_eng = contains_engineer(land_list);
|
||||||
|
|
||||||
for (qp = land_list->q_back; qp != land_list; qp = next) {
|
for (qp = land_list->q_back; qp != land_list; qp = next) {
|
||||||
next = qp->q_back;
|
next = qp->q_back;
|
||||||
llp = (struct ulist *)qp;
|
llp = (struct ulist *)qp;
|
||||||
getsect(llp->unit.land.lnd_x, llp->unit.land.lnd_y, §);
|
if (lnd_check_one_mines(llp, with_eng)) {
|
||||||
if (SCT_LANDMINES(§) == 0)
|
|
||||||
continue;
|
|
||||||
if (relations_with(sect.sct_oldown, llp->unit.land.lnd_own)
|
|
||||||
== ALLIED)
|
|
||||||
continue;
|
|
||||||
if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
|
|
||||||
lnd_hit_mine(&llp->unit.land);
|
|
||||||
sect.sct_mines--;
|
|
||||||
putsect(§);
|
|
||||||
putland(llp->unit.land.lnd_uid, &llp->unit.land);
|
|
||||||
if (!llp->unit.land.lnd_own) {
|
|
||||||
stopping = 1;
|
stopping = 1;
|
||||||
emp_remque(qp);
|
emp_remque(qp);
|
||||||
free(qp);
|
free(qp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return stopping;
|
return stopping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue