stop using MINMAX macros.

This commit is contained in:
Enno Rehling 2018-02-24 19:41:36 +01:00
parent 8a00cc3b96
commit 42c86d122e
7 changed files with 189 additions and 161 deletions

View file

@ -458,8 +458,7 @@ static int tolua_write_report(lua_State * L)
{ {
faction *f = (faction *)tolua_tousertype(L, 1, 0); faction *f = (faction *)tolua_tousertype(L, 1, 0);
if (f) { if (f) {
time_t ltime = time(0); int result = write_reports(f);
int result = write_reports(f, ltime);
lua_pushinteger(L, result); lua_pushinteger(L, result);
} }
else { else {

View file

@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef H_GC_ECONOMY #ifndef H_GC_ECONOMY
#define H_GC_ECONOMY #define H_GC_ECONOMY
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View file

@ -16,11 +16,14 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #endif
#include "pool.h" #include "pool.h"
#include "ally.h" #include "ally.h"
#include "config.h"
#include "faction.h" #include "faction.h"
#include "item.h" #include "item.h"
#include "order.h" #include "order.h"
@ -168,7 +171,8 @@ int count)
use = have; use = have;
else if (rtype->itype && mode & (GET_SLACK | GET_RESERVE)) { else if (rtype->itype && mode & (GET_SLACK | GET_RESERVE)) {
int reserve = get_reservation(u, rtype->itype); int reserve = get_reservation(u, rtype->itype);
int slack = MAX(0, have - reserve); int slack = have - reserve;
if (slack < 0) slack = 0;
if (mode & GET_RESERVE) if (mode & GET_RESERVE)
use = have - slack; use = have - slack;
else if (mode & GET_SLACK) else if (mode & GET_SLACK)
@ -206,18 +210,20 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count)
} }
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) { if ((mode & GET_SLACK) && (mode & GET_RESERVE)) {
n = MIN(use, have); n = (use < have) ? use : have;
} }
else if (rtype->itype) { else if (rtype->itype) {
int reserve = get_reservation(u, rtype->itype); int reserve = get_reservation(u, rtype->itype);
int slack = MAX(0, have - reserve); int slack = have - reserve;
if (slack < 0) slack = 0;
if (mode & GET_RESERVE) { if (mode & GET_RESERVE) {
n = have - slack; n = have - slack;
n = MIN(use, n); if (n > use) n = use;
change_reservation(u, rtype->itype, -n); change_reservation(u, rtype->itype, -n);
} }
else if (mode & GET_SLACK) { else if (mode & GET_SLACK) {
n = MIN(use, slack); n = slack;
if (n > use) n = use;
} }
} }
if (n > 0) { if (n > 0) {

View file

@ -17,7 +17,9 @@
* permission from the authors. * permission from the authors.
*/ */
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include "monsters.h" #include "monsters.h"
@ -132,7 +134,10 @@ static void reduce_weight(unit * u)
if (itype->weight >= 10 && itype->rtype->wtype == 0 if (itype->weight >= 10 && itype->rtype->wtype == 0
&& itype->rtype->atype == 0) { && itype->rtype->atype == 0) {
if (itype->capacity < itype->weight) { if (itype->capacity < itype->weight) {
int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); int reduce = (weight - capacity) / itype->weight;
if (reduce > itm->number) {
reduce = itm->number;
}
give_peasants(u, itm->type, reduce); give_peasants(u, itm->type, reduce);
weight -= reduce * itype->weight; weight -= reduce * itype->weight;
} }
@ -147,7 +152,10 @@ static void reduce_weight(unit * u)
const item_type *itype = itm->type; const item_type *itype = itm->type;
weight += itm->number * itype->weight; weight += itm->number * itype->weight;
if (itype->capacity < itype->weight) { if (itype->capacity < itype->weight) {
int reduce = MIN(itm->number, -((capacity - weight) / itype->weight)); int reduce = (weight - capacity) / itype->weight;
if (reduce > itm->number) {
reduce = itm->number;
}
give_peasants(u, itm->type, reduce); give_peasants(u, itm->type, reduce);
weight -= reduce * itype->weight; weight -= reduce * itype->weight;
} }
@ -1027,10 +1035,12 @@ static void eaten_by_monster(unit * u)
n = (int)(n * multi); n = (int)(n * multi);
if (n > 0) { if (n > 0) {
n = lovar(n); n = lovar(n);
n = MIN(rpeasants(u->region), n);
if (n > 0) { if (n > 0) {
int p = rpeasants(u->region);
if (p < n) n = p;
deathcounts(u->region, n); deathcounts(u->region, n);
rsetpeasants(u->region, rpeasants(u->region) - n); rsetpeasants(u->region, rpeasants(u->region) - n);
ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
@ -1048,8 +1058,9 @@ static void absorbed_by_monster(unit * u)
if (n > 0) { if (n > 0) {
n = lovar(n); n = lovar(n);
n = MIN(rpeasants(u->region), n);
if (n > 0) { if (n > 0) {
int p = rpeasants(u->region);
if (p < n) n = p;
rsetpeasants(u->region, rpeasants(u->region) - n); rsetpeasants(u->region, rpeasants(u->region) - n);
scale_number(u, u->number + n); scale_number(u, u->number + n);
ADDMSG(&u->region->msgs, msg_message("absorbpeasants", ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
@ -1063,7 +1074,10 @@ static int scareaway(region * r, int anzahl)
int n, p, diff = 0, emigrants[MAXDIRECTIONS]; int n, p, diff = 0, emigrants[MAXDIRECTIONS];
direction_t d; direction_t d;
anzahl = MIN(MAX(1, anzahl), rpeasants(r)); p = rpeasants(r);
if (anzahl < 1) anzahl = 1;
if (anzahl > p) anzahl = p;
assert(p >= 0 && anzahl >= 0);
/* Wandern am Ende der Woche (normal) oder wegen Monster. Die /* Wandern am Ende der Woche (normal) oder wegen Monster. Die
* Wanderung wird erst am Ende von demographics () ausgefuehrt. * Wanderung wird erst am Ende von demographics () ausgefuehrt.
@ -1073,9 +1087,7 @@ static int scareaway(region * r, int anzahl)
for (d = 0; d != MAXDIRECTIONS; d++) for (d = 0; d != MAXDIRECTIONS; d++)
emigrants[d] = 0; emigrants[d] = 0;
p = rpeasants(r); for (n = anzahl; n; n--) {
assert(p >= 0 && anzahl >= 0);
for (n = MIN(p, anzahl); n; n--) {
direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS);
region *rc = rconnect(r, dir); region *rc = rconnect(r, dir);
@ -1104,8 +1116,9 @@ static void scared_by_monster(unit * u)
} }
if (n > 0) { if (n > 0) {
n = lovar(n); n = lovar(n);
n = MIN(rpeasants(u->region), n);
if (n > 0) { if (n > 0) {
int p = rpeasants(u->region);
if (p < n) n = p;
n = scareaway(u->region, n); n = scareaway(u->region, n);
if (n > 0) { if (n > 0) {
ADDMSG(&u->region->msgs, msg_message("fleescared", ADDMSG(&u->region->msgs, msg_message("fleescared",

View file

@ -16,49 +16,52 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #endif
#include "randenc.h" #include "randenc.h"
#include "volcano.h" #include "chaos.h"
#include "economy.h" #include "economy.h"
#include "monsters.h" #include "monsters.h"
#include "move.h" #include "move.h"
#include "chaos.h"
#include "study.h" #include "study.h"
#include "volcano.h"
#include <spells/unitcurse.h> #include "spells/unitcurse.h"
#include <spells/regioncurse.h> #include "spells/regioncurse.h"
/* attributes includes */ /* attributes includes */
#include <attributes/racename.h> #include "attributes/racename.h"
#include <attributes/reduceproduction.h> #include "attributes/reduceproduction.h"
/* kernel includes */ /* kernel includes */
#include <kernel/building.h> #include "kernel/building.h"
#include <kernel/curse.h> #include "kernel/config.h"
#include <kernel/equipment.h> #include "kernel/curse.h"
#include <kernel/faction.h> #include "kernel/equipment.h"
#include <kernel/item.h> #include "kernel/faction.h"
#include <kernel/messages.h> #include "kernel/item.h"
#include <kernel/order.h> #include "kernel/messages.h"
#include <kernel/plane.h> #include "kernel/order.h"
#include <kernel/pool.h> #include "kernel/plane.h"
#include <kernel/race.h> #include "kernel/pool.h"
#include <kernel/region.h> #include "kernel/race.h"
#include <kernel/ship.h> #include "kernel/region.h"
#include <kernel/terrain.h> #include "kernel/ship.h"
#include <kernel/terrainid.h> #include "kernel/terrain.h"
#include <kernel/unit.h> #include "kernel/terrainid.h"
#include "kernel/unit.h"
/* util includes */ /* util includes */
#include <util/attrib.h> #include "util/attrib.h"
#include <util/language.h> #include "util/language.h"
#include <util/lists.h> #include "util/lists.h"
#include <util/log.h> #include "util/log.h"
#include <util/rand.h> #include "util/rand.h"
#include <util/message.h> #include "util/message.h"
#include <util/rng.h> #include "util/rng.h"
/* libc includes */ /* libc includes */
#include <string.h> #include <string.h>
@ -785,9 +788,8 @@ static void rotting_herbs(void)
int n = itm->number; int n = itm->number;
double k = n * rot_chance / 100.0; double k = n * rot_chance / 100.0;
if (fval(itm->type, ITF_HERB)) { if (fval(itm->type, ITF_HERB)) {
double nv = normalvariate(k, k / 4); int delta = (int)normalvariate(k, k / 4);
int inv = (int)nv; if (n < delta) delta = n;
int delta = MIN(n, inv);
if (!i_change(itmp, itm->type, -delta)) { if (!i_change(itmp, itm->type, -delta)) {
continue; continue;
} }
@ -823,7 +825,9 @@ void randomevents(void)
while (*blist) { while (*blist) {
building *b = *blist; building *b = *blist;
if (fval(b->type, BTF_DECAY) && !building_owner(b)) { if (fval(b->type, BTF_DECAY) && !building_owner(b)) {
b->size -= MAX(1, (b->size * 20) / 100); int delta = (b->size * 20) / 100;
if (delta < 1) delta = 1;
b->size -= delta;
if (b->size == 0) { if (b->size == 0) {
remove_building(blist, r->buildings); remove_building(blist, r->buildings);
} }

View file

@ -16,12 +16,12 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #endif
#include "reports.h" #include "reports.h"
#include "battle.h" #include "battle.h"
#include "kernel/calendar.h"
#include "guard.h" #include "guard.h"
#include "laws.h" #include "laws.h"
#include "spells.h" #include "spells.h"
@ -30,48 +30,50 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "donations.h" #include "donations.h"
/* attributes includes */ /* attributes includes */
#include <attributes/attributes.h> #include "attributes/attributes.h"
#include <attributes/follow.h> #include "attributes/follow.h"
#include <attributes/otherfaction.h> #include "attributes/otherfaction.h"
#include <attributes/racename.h> #include "attributes/racename.h"
#include <attributes/stealth.h> #include "attributes/stealth.h"
#include <spells/unitcurse.h> #include "spells/unitcurse.h"
/* kernel includes */ /* kernel includes */
#include <kernel/ally.h> #include "kernel/config.h"
#include <kernel/alliance.h> #include "kernel/calendar.h"
#include <kernel/connection.h> #include "kernel/ally.h"
#include <kernel/building.h> #include "kernel/alliance.h"
#include <kernel/curse.h> #include "kernel/connection.h"
#include <kernel/faction.h> #include "kernel/building.h"
#include <kernel/group.h> #include "kernel/curse.h"
#include <kernel/item.h> #include "kernel/faction.h"
#include <kernel/messages.h> #include "kernel/group.h"
#include <kernel/order.h> #include "kernel/item.h"
#include <kernel/plane.h> #include "kernel/messages.h"
#include <kernel/race.h> #include "kernel/order.h"
#include <kernel/region.h> #include "kernel/plane.h"
#include <kernel/resources.h> #include "kernel/race.h"
#include <kernel/ship.h> #include "kernel/region.h"
#include <kernel/spell.h> #include "kernel/resources.h"
#include <kernel/spellbook.h> #include "kernel/ship.h"
#include <kernel/terrain.h> #include "kernel/spell.h"
#include <kernel/unit.h> #include "kernel/spellbook.h"
#include "kernel/terrain.h"
#include "kernel/unit.h"
/* util includes */ /* util includes */
#include <util/attrib.h> #include "util/attrib.h"
#include <util/base36.h> #include "util/base36.h"
#include <util/bsdstring.h> #include "util/bsdstring.h"
#include <util/functions.h> #include "util/functions.h"
#include <util/goodies.h> #include "util/goodies.h"
#include <util/language.h> #include "util/language.h"
#include <util/lists.h> #include "util/lists.h"
#include <util/log.h> #include "util/log.h"
#include <util/macros.h> #include "util/macros.h"
#include <util/path.h> #include "util/path.h"
#include <util/strings.h> #include "util/strings.h"
#include <util/translation.h> #include "util/translation.h"
#include <stream.h> #include <stream.h>
#include <selist.h> #include <selist.h>
@ -610,6 +612,70 @@ report_resources(const region * r, resource_report * result, int size,
return n; return n;
} }
static size_t spskill(char *buffer, size_t size, const struct locale * lang,
const struct unit * u, struct skill * sv, int *dh)
{
char *bufp = buffer;
int effsk;
if (!u->number)
return 0;
if (sv->level <= 0) {
if (sv->old <= 0 || (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) == 0) {
return 0;
}
}
bufp = STRLCPY(bufp, ", ", size);
if (!*dh) {
bufp = STRLCPY(bufp, LOC(lang, "nr_skills"), size);
bufp = STRLCPY(bufp, ": ", size);
*dh = 1;
}
bufp = STRLCPY(bufp, skillname(sv->id, lang), size);
bufp = STRLCPY(bufp, " ", size);
if (sv->id == SK_MAGIC) {
sc_mage *mage = get_mage(u);
if (mage && mage->magietyp != M_GRAY) {
bufp = STRLCPY(bufp, LOC(lang, mkname("school",
magic_school[mage->magietyp])), size);
bufp = STRLCPY(bufp, " ", size);
}
}
if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) {
int i = u_geteffstealth(u);
if (i >= 0) {
if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0)
WARN_STATIC_BUFFER();
}
}
effsk = eff_skill(u, sv, 0);
if (wrptr(&bufp, &size, snprintf(bufp, size, "%d", effsk)) != 0)
WARN_STATIC_BUFFER();
if (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) {
int oldeff = 0;
int diff;
if (sv->old > 0) {
oldeff = sv->old + get_modifier(u, sv->id, sv->old, u->region, false);
if (oldeff < 0) oldeff = 0;
}
diff = effsk - oldeff;
if (diff != 0) {
if (wrptr(&bufp, &size, snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0)
WARN_STATIC_BUFFER();
}
}
return bufp - buffer;
}
int int
bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, char *buf, bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode, char *buf,
size_t size) size_t size)
@ -750,7 +816,7 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode,
if (u->faction == f) { if (u->faction == f) {
skill *sv; skill *sv;
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
size_t bytes = spskill(bufp, size, lang, u, sv, &dh, 1); size_t bytes = spskill(bufp, size, lang, u, sv, &dh);
assert(bytes <= INT_MAX); assert(bytes <= INT_MAX);
if (wrptr(&bufp, &size, (int)bytes) != 0) if (wrptr(&bufp, &size, (int)bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
@ -918,71 +984,6 @@ bufunit(const faction * f, const unit * u, unsigned int indent, seen_mode mode,
return dh; return dh;
} }
size_t
spskill(char *buffer, size_t size, const struct locale * lang,
const struct unit * u, struct skill * sv, int *dh, int days)
{
char *bufp = buffer;
int effsk;
if (!u->number)
return 0;
if (sv->level <= 0) {
if (sv->old <= 0 || (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) == 0) {
return 0;
}
}
bufp = STRLCPY(bufp, ", ", size);
if (!*dh) {
bufp = STRLCPY(bufp, LOC(lang, "nr_skills"), size);
bufp = STRLCPY(bufp, ": ", size);
*dh = 1;
}
bufp = STRLCPY(bufp, skillname(sv->id, lang), size);
bufp = STRLCPY(bufp, " ", size);
if (sv->id == SK_MAGIC) {
sc_mage *mage = get_mage(u);
if (mage && mage->magietyp != M_GRAY) {
bufp = STRLCPY(bufp, LOC(lang, mkname("school",
magic_school[mage->magietyp])), size);
bufp = STRLCPY(bufp, " ", size);
}
}
if (sv->id == SK_STEALTH && fval(u, UFL_STEALTH)) {
int i = u_geteffstealth(u);
if (i >= 0) {
if (wrptr(&bufp, &size, snprintf(bufp, size, "%d/", i)) != 0)
WARN_STATIC_BUFFER();
}
}
effsk = eff_skill(u, sv, 0);
if (wrptr(&bufp, &size, snprintf(bufp, size, "%d", effsk)) != 0)
WARN_STATIC_BUFFER();
if (u->faction->options & WANT_OPTION(O_SHOWSKCHANGE)) {
int oldeff = 0;
int diff;
if (sv->old > 0) {
oldeff = sv->old + get_modifier(u, sv->id, sv->old, u->region, false);
}
oldeff = MAX(0, oldeff);
diff = effsk - oldeff;
if (diff != 0) {
if (wrptr(&bufp, &size, snprintf(bufp, size, " (%s%d)", (diff > 0) ? "+" : "", diff)) != 0)
WARN_STATIC_BUFFER();
}
}
return bufp - buffer;
}
void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark) void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned int width, char mark)
{ {
bool firstline; bool firstline;
@ -1013,7 +1014,7 @@ void split_paragraph(strlist ** SP, const char *s, unsigned int indent, unsigned
firstline = false; firstline = false;
} }
if (!cut) { if (!cut) {
cut = s + MIN(len, REPORTWIDTH); cut = s + ((len < REPORTWIDTH) ? len : REPORTWIDTH);
} }
memcpy(buf + indent, s, cut - s); memcpy(buf + indent, s, cut - s);
buf[indent + (cut - s)] = 0; buf[indent + (cut - s)] = 0;
@ -1669,7 +1670,7 @@ void finish_reports(report_context *ctx) {
} }
} }
int write_reports(faction * f, time_t ltime) int write_reports(faction * f)
{ {
bool gotit = false; bool gotit = false;
struct report_context ctx; struct report_context ctx;
@ -1758,7 +1759,6 @@ int reports(void)
{ {
faction *f; faction *f;
FILE *mailit; FILE *mailit;
time_t ltime = time(NULL);
int retval = 0; int retval = 0;
char path[4096]; char path[4096];
const char * rpath = reportpath(); const char * rpath = reportpath();
@ -1775,7 +1775,7 @@ int reports(void)
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
if (f->email && !fval(f, FFL_NPC)) { if (f->email && !fval(f, FFL_NPC)) {
int error = write_reports(f, ltime); int error = write_reports(f);
if (error) if (error)
retval = error; retval = error;
if (mailit) if (mailit)
@ -1998,6 +1998,7 @@ static void eval_unitsize(struct opstack **stack, const void *userdata)
const struct unit *u = (const struct unit *)opop(stack).v; const struct unit *u = (const struct unit *)opop(stack).v;
variant var; variant var;
UNUSED_ARG(userdata);
var.i = u->number; var.i = u->number;
opush(stack, var); opush(stack, var);
} }
@ -2009,6 +2010,7 @@ static void eval_faction(struct opstack **stack, const void *userdata)
size_t len = strlen(c); size_t len = strlen(c);
variant var; variant var;
UNUSED_ARG(userdata);
var.v = strcpy(balloc(len + 1), c); var.v = strcpy(balloc(len + 1), c);
opush(stack, var); opush(stack, var);
} }
@ -2018,6 +2020,8 @@ static void eval_alliance(struct opstack **stack, const void *userdata)
const struct alliance *al = (const struct alliance *)opop(stack).v; const struct alliance *al = (const struct alliance *)opop(stack).v;
const char *c = alliancename(al); const char *c = alliancename(al);
variant var; variant var;
UNUSED_ARG(userdata);
if (c != NULL) { if (c != NULL) {
size_t len = strlen(c); size_t len = strlen(c);
var.v = strcpy(balloc(len + 1), c); var.v = strcpy(balloc(len + 1), c);

View file

@ -60,12 +60,11 @@ extern "C" {
void sparagraph(struct strlist **SP, const char *s, unsigned int indent, char mark); void sparagraph(struct strlist **SP, const char *s, unsigned int indent, char mark);
void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark); void lparagraph(struct strlist **SP, char *s, unsigned int indent, char mark);
const char *hp_status(const struct unit *u); const char *hp_status(const struct unit *u);
size_t spskill(char *pbuf, size_t siz, const struct locale *lang, const struct unit *u, struct skill *sv, int *dh, int days); /* mapper */
void spunit(struct strlist **SP, const struct faction *f, void spunit(struct strlist **SP, const struct faction *f,
const struct unit *u, unsigned int indent, seen_mode mode); const struct unit *u, unsigned int indent, seen_mode mode);
int reports(void); int reports(void);
int write_reports(struct faction *f, time_t ltime); int write_reports(struct faction *f);
int init_reports(void); int init_reports(void);
void reorder_units(struct region * r); void reorder_units(struct region * r);