static void reduce_weight(unit * u) { int capacity, weight = 0; item **itmp = &u->items; int horses = get_resource(u, get_resourcetype(R_HORSE)); if (horses > 0) { horses = _min(horses, (u->number * 2)); change_resource(u, get_resourcetype(R_HORSE), -horses); } /* 0. ditch any vehicles */ while (*itmp != NULL) { item *itm = *itmp; const item_type *itype = itm->type; if (itype->flags & ITF_VEHICLE) { give_peasants(u, itm->type, itm->number); } else { weight += itm->number * itype->weight; } if (*itmp == itm) itmp = &itm->next; } capacity = walkingcapacity(u); /* 1. get rid of anything that isn't silver or really lightweight or helpful in combat */ for (itmp = &u->items; *itmp && capacity > 0;) { item *itm = *itmp; const item_type *itype = itm->type; weight += itm->number * itype->weight; if (weight > capacity) { if (itype->weight >= 10 && itype->rtype->wtype == 0 && itype->rtype->atype == 0) { if (itype->capacity < itype->weight) { int reduce = _min(itm->number, -((capacity - weight) / itype->weight)); give_peasants(u, itm->type, reduce); 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_peasants(u, itm->type, reduce); weight -= reduce * itype->weight; } if (*itmp == itm) itmp = &itm->next; } }
int unit_getcapacity(const unit * u) { return walkingcapacity(u); }