forked from github/server
monsters are shedding extra weight in a smarter way.
This commit is contained in:
parent
e39b51bc13
commit
0eb91f7ab7
1 changed files with 44 additions and 17 deletions
|
@ -70,6 +70,48 @@
|
||||||
|
|
||||||
#define MAXILLUSION_TEXTS 3
|
#define MAXILLUSION_TEXTS 3
|
||||||
|
|
||||||
|
static void
|
||||||
|
reduce_weight(unit * u)
|
||||||
|
{
|
||||||
|
int horses = get_resource(u,R_HORSE);
|
||||||
|
int capacity = walkingcapacity(u);
|
||||||
|
item ** itmp = &u->items;
|
||||||
|
int weight = 0;
|
||||||
|
|
||||||
|
if (horses > 0) {
|
||||||
|
change_resource(u, R_HORSE, - min(horses,(u->number*2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 1. get rid of anything that isn't silver or really lightweight */
|
||||||
|
while (capacity>0 && *itmp!=NULL) {
|
||||||
|
item * itm = *itmp;
|
||||||
|
const item_type * itype = itm->type;
|
||||||
|
weight += itm->number*itype->weight;
|
||||||
|
if (weight>capacity) {
|
||||||
|
if (itype->weight>=10) {
|
||||||
|
if (itype->capacity < itype->weight) {
|
||||||
|
int reduce = min(itm->number, -((capacity-weight)/itype->weight));
|
||||||
|
give_item(reduce, itm->type, u, NULL, NULL);
|
||||||
|
weight -= reduce * itype->weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (*itmp==itm) itmp=&itm->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (itmp = &u->items;*itmp && weight>capacity;) {
|
||||||
|
item * itm = *itmp;
|
||||||
|
const item_type * itype = itm->type;
|
||||||
|
weight += itm->number*itype->weight;
|
||||||
|
if (itype->capacity < itype->weight) {
|
||||||
|
int reduce = min(itm->number, -((capacity-weight)/itype->weight));
|
||||||
|
give_item(reduce, itm->type, u, NULL, NULL);
|
||||||
|
weight -= reduce * itype->weight;
|
||||||
|
}
|
||||||
|
if (*itmp==itm) itmp=&itm->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static boolean
|
static boolean
|
||||||
is_waiting(const unit * u)
|
is_waiting(const unit * u)
|
||||||
{
|
{
|
||||||
|
@ -328,6 +370,7 @@ monster_move(region * r, unit * u)
|
||||||
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
||||||
locale_string(u->faction->locale, directions[d]));
|
locale_string(u->faction->locale, directions[d]));
|
||||||
|
|
||||||
|
reduce_weight(u);
|
||||||
return parse_order(buf, u->faction->locale);
|
return parse_order(buf, u->faction->locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -794,26 +837,10 @@ plan_dragon(unit * u)
|
||||||
attrib * ta = a_find(u->attribs, &at_targetregion);
|
attrib * ta = a_find(u->attribs, &at_targetregion);
|
||||||
region * r = u->region;
|
region * r = u->region;
|
||||||
region * tr = NULL;
|
region * tr = NULL;
|
||||||
int horses = get_resource(u,R_HORSE);
|
|
||||||
int capacity = walkingcapacity(u);
|
|
||||||
item ** itmp = &u->items;
|
|
||||||
boolean move = false;
|
boolean move = false;
|
||||||
order * long_order = NULL;
|
order * long_order = NULL;
|
||||||
|
|
||||||
if (horses > 0) {
|
reduce_weight(u);
|
||||||
change_resource(u, R_HORSE, - min(horses,(u->number*2)));
|
|
||||||
}
|
|
||||||
while (capacity>0 && *itmp!=NULL) {
|
|
||||||
item * itm = *itmp;
|
|
||||||
if (itm->type->capacity<itm->type->weight) {
|
|
||||||
int weight = itm->number*itm->type->capacity;
|
|
||||||
if (weight > capacity) {
|
|
||||||
int error = give_item(itm->number, itm->type, u, NULL, NULL);
|
|
||||||
if (error!=0) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (*itmp==itm) itmp=&itm->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ta==NULL) {
|
if (ta==NULL) {
|
||||||
move |= (r->land==0 || r->land->peasants==0); /* when no peasants, move */
|
move |= (r->land==0 || r->land->peasants==0); /* when no peasants, move */
|
||||||
|
|
Loading…
Reference in a new issue