tend: Factor can_tend_to() out of tend(), tend_land()
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
18f3b84390
commit
333cd7d6d3
1 changed files with 23 additions and 18 deletions
|
@ -41,6 +41,7 @@
|
||||||
#include "plague.h"
|
#include "plague.h"
|
||||||
#include "ship.h"
|
#include "ship.h"
|
||||||
|
|
||||||
|
static int can_tend_to(struct shpstr *, struct shpstr *);
|
||||||
static void expose_ship(struct shpstr *s1, struct shpstr *s2);
|
static void expose_ship(struct shpstr *s1, struct shpstr *s2);
|
||||||
static int tend_land(struct shpstr *tenderp, char *units);
|
static int tend_land(struct shpstr *tenderp, char *units);
|
||||||
|
|
||||||
|
@ -134,23 +135,15 @@ tend(void)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
total = 0;
|
total = 0;
|
||||||
while (nxtitem(&targets, &target)) {
|
while (nxtitem(&targets, &target)) {
|
||||||
if (!player->owner
|
|
||||||
&& relations_with(target.shp_own, player->cnum) < FRIENDLY)
|
|
||||||
continue;
|
|
||||||
if (target.shp_uid == tender.shp_uid)
|
|
||||||
continue;
|
|
||||||
if (tender.shp_x != target.shp_x ||
|
|
||||||
tender.shp_y != target.shp_y)
|
|
||||||
continue;
|
|
||||||
if (ip->i_uid == I_CIVIL && tender.shp_own != target.shp_own)
|
if (ip->i_uid == I_CIVIL && tender.shp_own != target.shp_own)
|
||||||
continue;
|
continue;
|
||||||
ontarget = target.shp_item[ip->i_uid];
|
|
||||||
vbase = &mchr[(int)target.shp_type];
|
|
||||||
maxtarget = vbase->m_item[ip->i_uid];
|
|
||||||
if (amt < 0) {
|
if (amt < 0) {
|
||||||
/* take from target and give to tender */
|
/* take from target and give to tender */
|
||||||
if (!player->owner)
|
if (!player->owner)
|
||||||
continue;
|
continue;
|
||||||
|
if (!can_tend_to(&target, &tender))
|
||||||
|
continue;
|
||||||
|
ontarget = target.shp_item[ip->i_uid];
|
||||||
if (ontarget == 0) {
|
if (ontarget == 0) {
|
||||||
pr("No %s on %s\n", ip->i_name, prship(&target));
|
pr("No %s on %s\n", ip->i_name, prship(&target));
|
||||||
continue;
|
continue;
|
||||||
|
@ -164,6 +157,11 @@ tend(void)
|
||||||
total += transfer;
|
total += transfer;
|
||||||
} else {
|
} else {
|
||||||
/* give to target from tender */
|
/* give to target from tender */
|
||||||
|
if (!can_tend_to(&tender, &target))
|
||||||
|
continue;
|
||||||
|
ontarget = target.shp_item[ip->i_uid];
|
||||||
|
vbase = &mchr[(int)target.shp_type];
|
||||||
|
maxtarget = vbase->m_item[ip->i_uid];
|
||||||
transfer = MIN(ontender, amt);
|
transfer = MIN(ontender, amt);
|
||||||
transfer = MIN(transfer, maxtarget - ontarget);
|
transfer = MIN(transfer, maxtarget - ontarget);
|
||||||
if (transfer == 0)
|
if (transfer == 0)
|
||||||
|
@ -194,6 +192,19 @@ tend(void)
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
can_tend_to(struct shpstr *from, struct shpstr *to)
|
||||||
|
{
|
||||||
|
if (to->shp_own != player->cnum && !player->god
|
||||||
|
&& relations_with(to->shp_own, player->cnum) < FRIENDLY)
|
||||||
|
return 0;
|
||||||
|
if (from->shp_uid == to->shp_uid)
|
||||||
|
return 0;
|
||||||
|
if (from->shp_x != to->shp_x || from->shp_y != to->shp_y)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
expose_ship(struct shpstr *s1, struct shpstr *s2)
|
expose_ship(struct shpstr *s1, struct shpstr *s2)
|
||||||
{
|
{
|
||||||
|
@ -237,13 +248,7 @@ tend_land(struct shpstr *tenderp, char *units)
|
||||||
if (!check_ship_ok(tenderp) || !check_land_ok(&land))
|
if (!check_ship_ok(tenderp) || !check_land_ok(&land))
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
while (nxtitem(&targets, &target)) {
|
while (nxtitem(&targets, &target)) {
|
||||||
if (!player->owner
|
if (!can_tend_to(tenderp, &target))
|
||||||
&& relations_with(target.shp_own, player->cnum) < FRIENDLY)
|
|
||||||
continue;
|
|
||||||
if (target.shp_uid == tenderp->shp_uid)
|
|
||||||
continue;
|
|
||||||
if (tenderp->shp_x != target.shp_x ||
|
|
||||||
tenderp->shp_y != target.shp_y)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Fit unit on ship */
|
/* Fit unit on ship */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue