From 775e8edae1bf41cd6c78c6edf055cc1aacd618c4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 17 May 2012 16:40:50 -0700 Subject: [PATCH] as much as possible, replace the UFL_OWNER flag with checking the owner the canonical way. --- src/bindings/bind_building.c | 8 +----- src/gamecode/creport.c | 26 +++++++++--------- src/gamecode/economy.c | 51 ------------------------------------ src/gamecode/laws.c | 48 ++++++++++++++------------------- src/gamecode/laws_test.c | 1 - src/gamecode/report.c | 8 +++--- src/kernel/build.c | 1 - src/kernel/config.h | 7 ----- src/kernel/move.c | 4 +-- src/kernel/unit.c | 27 ++++++------------- 10 files changed, 49 insertions(+), 132 deletions(-) diff --git a/src/bindings/bind_building.c b/src/bindings/bind_building.c index 1a220b4e5..97432bfca 100644 --- a/src/bindings/bind_building.c +++ b/src/bindings/bind_building.c @@ -170,13 +170,7 @@ static int tolua_building_set_owner(lua_State * L) { building *b = (building *) tolua_tousertype(L, 1, 0); unit *u = (unit *) tolua_tousertype(L, 2, 0); - unit *o = b ? building_owner(b) : NULL; - if (o && o != u) { - freset(o, UFL_OWNER); - } - if (u) { - fset(u, UFL_OWNER); - } + building_set_owner(b, u); return 0; } diff --git a/src/gamecode/creport.c b/src/gamecode/creport.c index 0f37b9685..8c63cd9e3 100644 --- a/src/gamecode/creport.c +++ b/src/gamecode/creport.c @@ -1351,24 +1351,26 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) ru && ru->type == &at_travelunit; ru = ru->next) { unit *u = (unit *) ru->data.v; if (cansee_durchgezogen(f, r, u, 0) && r != u->region) { - if (!u->ship || !fval(u, UFL_OWNER)) - continue; - if (!seeships) - fprintf(F, "DURCHSCHIFFUNG\n"); - seeships = true; - fprintf(F, "\"%s\"\n", shipname(u->ship)); + if (u->ship && ship_owner(u->ship)==u) { + if (!seeships) { + fprintf(F, "DURCHSCHIFFUNG\n"); + } + seeships = true; + fprintf(F, "\"%s\"\n", shipname(u->ship)); + } } } for (ru = a_find(r->attribs, &at_travelunit); ru && ru->type == &at_travelunit; ru = ru->next) { unit *u = (unit *) ru->data.v; if (cansee_durchgezogen(f, r, u, 0) && r != u->region) { - if (u->ship) - continue; - if (!seeunits) - fprintf(F, "DURCHREISE\n"); - seeunits = true; - fprintf(F, "\"%s\"\n", unitname(u)); + if (!u->ship) { + if (!seeunits) { + fprintf(F, "DURCHREISE\n"); + } + seeunits = true; + fprintf(F, "\"%s\"\n", unitname(u)); + } } } } diff --git a/src/gamecode/economy.c b/src/gamecode/economy.c index 6b99573a8..0deab6870 100644 --- a/src/gamecode/economy.c +++ b/src/gamecode/economy.c @@ -1105,51 +1105,6 @@ static boolean maintain(building * b, boolean first) return true; } -#ifdef COLLAPSE_CHANCE -static void gebaeude_stuerzt_ein(region * r, building * b) -{ - unit *u; - int n, i; - int opfer = 0; - int road = 0; - struct message *msg; - - for (u = r->units; u; u = u->next) { - if (u->building == b) { - int loss = 0; - - fset(u->faction, FFL_MARK); - freset(u, UFL_OWNER); - leave(r, u); - n = u->number; -#ifdef COLLAPSE_SURVIVAL - for (i = 0; i < n; i++) { - if (rng_double() >= COLLAPSE_SURVIVAL) { - ++loss; - } - } -#endif - scale_number(u, u->number - loss); - opfer += loss; - } - } - - msg = - msg_message("buildingcrash", "region building opfer road", r, b, opfer, - road); - add_message(&r->msgs, msg); - for (u = r->units; u; u = u->next) { - faction *f = u->faction; - if (fval(f, FFL_MARK)) { - freset(u->faction, FFL_MARK); - add_message(&f->msgs, msg); - } - } - msg_release(msg); - remove_building(&r->buildings, b); -} -#endif - void maintain_buildings(region * r, boolean crash) { building **bp = &r->buildings; @@ -1159,12 +1114,6 @@ void maintain_buildings(region * r, boolean crash) /* the second time, send a message */ if (crash) { -#ifdef COLLAPSE_CHANCE - if (!maintained && (rng_double() < COLLAPSE_CHANCE)) { - gebaeude_stuerzt_ein(r, b); - continue; - } -#endif if (!fval(b, BLD_WORKING)) { unit *u = building_owner(b); const char *msgtype = diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 8d1c4b229..61e0989df 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -1203,7 +1203,7 @@ static void nmr_death(faction * f) if (rule) { unit *u; for (u = f->units; u; u = u->nextF) { - if (u->building && fval(u, UFL_OWNER)) { + if (u->building && building_owner(u->building)==u) { remove_building(&u->region->buildings, u->building); } } @@ -1526,7 +1526,6 @@ static cmp_building_cb get_cmp_region_owner(void) static int display_cmd(unit * u, struct order *ord) { - building *b = u->building; char **s = NULL; const char *str; region *r = u->region; @@ -1538,19 +1537,19 @@ static int display_cmd(unit * u, struct order *ord) switch (findparam_ex(str, u->faction->locale)) { case P_BUILDING: case P_GEBAEUDE: - if (!b) { + if (!u->building) { cmistake(u, ord, 145, MSG_PRODUCE); break; } - if (!fval(u, UFL_OWNER)) { + if (building_owner(u->building)!=u) { cmistake(u, ord, 5, MSG_PRODUCE); break; } - if (!fval(b->type, BTF_NAMECHANGE) && b->display && b->display[0] != 0) { + if (!fval(u->building->type, BTF_NAMECHANGE) && u->building->display && u->building->display[0]) { cmistake(u, ord, 278, MSG_EVENT); break; } - s = &b->display; + s = &u->building->display; break; case P_SHIP: @@ -1558,7 +1557,7 @@ static int display_cmd(unit * u, struct order *ord) cmistake(u, ord, 144, MSG_PRODUCE); break; } - if (!fval(u, UFL_OWNER)) { + if (ship_owner(u->ship)!=u) { cmistake(u, ord, 12, MSG_PRODUCE); break; } @@ -1581,15 +1580,15 @@ static int display_cmd(unit * u, struct order *ord) break; case P_REGION: - if (!b) { + if (!u->building) { cmistake(u, ord, 145, MSG_EVENT); break; } - if (!fval(u, UFL_OWNER)) { + if (building_owner(u->building)!=u) { cmistake(u, ord, 148, MSG_EVENT); break; } - if (b != largestbuilding(r, get_cmp_region_owner(), false)) { + if (u->building != largestbuilding(r, get_cmp_region_owner(), false)) { cmistake(u, ord, 147, MSG_EVENT); break; } @@ -1682,7 +1681,7 @@ rename_building(unit * u, order * ord, building * b, const char *name) } } } else { - if (!fval(u, UFL_OWNER)) { + if (owner!=u) { cmistake(u, ord, 148, MSG_PRODUCE); return -1; } @@ -1814,7 +1813,7 @@ static int name_cmd(unit * u, struct order *ord) cmistake(u, ord, 144, MSG_PRODUCE); break; } - if (!fval(u, UFL_OWNER)) { + if (ship_owner(u->ship)!=u) { cmistake(u, ord, 12, MSG_PRODUCE); break; } @@ -1857,7 +1856,7 @@ static int name_cmd(unit * u, struct order *ord) cmistake(u, ord, 145, MSG_EVENT); break; } - if (!fval(u, UFL_OWNER)) { + if (building_owner(b)!=u) { cmistake(u, ord, 148, MSG_EVENT); break; } @@ -2881,7 +2880,9 @@ static void reorder(void) cmistake(u, ord, 258, MSG_EVENT); } else if (v->building != u->building || v->ship != u->ship) { cmistake(u, ord, 259, MSG_EVENT); - } else if (fval(u, UFL_OWNER)) { + } else if (u->building && building_owner(u->building)==u) { + cmistake(u, ord, 260, MSG_EVENT); + } else if (u->ship && ship_owner(u->ship)==u) { cmistake(u, ord, 260, MSG_EVENT); } else if (v == u) { cmistake(u, ord, 10, MSG_EVENT); @@ -2895,7 +2896,9 @@ static void reorder(void) sorted = true; break; case P_BEFORE: - if (fval(v, UFL_OWNER)) { + if (v->ship && ship_owner(v->ship)==v) { + cmistake(v, ord, 261, MSG_EVENT); + } else if (v->building && building_owner(v->building)==v) { cmistake(v, ord, 261, MSG_EVENT); } else { unit **vp = &r->units; @@ -2990,7 +2993,7 @@ static int renumber_cmd(unit * u, order * ord) cmistake(u, ord, 116, MSG_EVENT); break; } - if (!fval(u, UFL_OWNER)) { + if (ship_owner(u->ship)!=u) { cmistake(u, ord, 146, MSG_EVENT); break; } @@ -3018,7 +3021,7 @@ static int renumber_cmd(unit * u, order * ord) cmistake(u, ord, 145, MSG_EVENT); break; } - if (!fval(u, UFL_OWNER)) { + if (building_owner(u->building)!=u) { cmistake(u, ord, 148, MSG_EVENT); break; } @@ -4068,12 +4071,6 @@ static void maintain_buildings_1(region * r) maintain_buildings(r, false); } -#ifdef COLLAPSE_CHANCE -static void maintain_buildings_2(region * r) -{ - maintain_buildings(r, true); -} -#endif static void reset_moved(unit * u) { freset(u, UFL_MOVED); @@ -4246,11 +4243,6 @@ void init_processor(void) } add_proc_global(p, &demographics, "Nahrung, Seuchen, Wachstum, Wanderung"); -#ifdef COLLAPSE_CHANCE - p += 10; - add_proc_region(p, &maintain_buildings_2, "Gebaeudeunterhalt (2. Versuch)"); -#endif - if (!global.disabled[K_SORT]) { p += 10; add_proc_global(p, &reorder, "Einheiten sortieren"); diff --git a/src/gamecode/laws_test.c b/src/gamecode/laws_test.c index e8fbd1895..fce2fa060 100644 --- a/src/gamecode/laws_test.c +++ b/src/gamecode/laws_test.c @@ -54,7 +54,6 @@ static void test_rename_building(CuTest * tc) f = test_create_faction(rc_find("human")); u = test_create_unit(f, r); u_set_building(u, b); - fset(u, UFL_OWNER); rename_building(u, NULL, b, "Villa Nagel"); CuAssertStrEquals(tc, "Villa Nagel", b->name); diff --git a/src/gamecode/report.c b/src/gamecode/report.c index 79d2c8e54..e08b198d5 100644 --- a/src/gamecode/report.c +++ b/src/gamecode/report.c @@ -1382,7 +1382,7 @@ static void durchreisende(FILE * F, const region * r, const faction * f) for (a = abegin; a && a->type == &at_travelunit; a = a->next) { unit *u = (unit *) a->data.v; - if (r != u->region && (u->ship == NULL || fval(u, UFL_OWNER))) { + if (r != u->region && (!u->ship || ship_owner(u->ship)==u)) { if (cansee_durchgezogen(f, r, u, 0)) { ++maxtravel; } @@ -1399,7 +1399,7 @@ static void durchreisende(FILE * F, const region * r, const faction * f) for (a = abegin; a && a->type == &at_travelunit; a = a->next) { unit *u = (unit *) a->data.v; - if (r != u->region && (u->ship == NULL || fval(u, UFL_OWNER))) { + if (r != u->region && (!u->ship || ship_owner(u->ship)==u)) { if (cansee_durchgezogen(f, r, u, 0)) { ++counter; if (u->ship != NULL) { @@ -1565,7 +1565,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) unitid(u), u->name, u->number, get_money(u)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - if (u->building != NULL && fval(u, UFL_OWNER)) { + if (u->building && building_owner(u->building)==u) { building *b = u->building; int cost = buildingmaintenance(b, r_silver); @@ -1578,7 +1578,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) WARN_STATIC_BUFFER(); } } else if (u->ship) { - if (fval(u, UFL_OWNER)) { + if (ship_owner(u->ship)==u) { bytes = (int)strlcpy(bufp, ",S", size); } else { bytes = (int)strlcpy(bufp, ",s", size); diff --git a/src/kernel/build.c b/src/kernel/build.c index 4804c7d1c..e718ff5b2 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -376,7 +376,6 @@ int destroy_cmd(unit * u, struct order *ord) /* all units leave the building */ for (u2 = r->units; u2; u2 = u2->next) { if (u2->building == b) { - freset(u2, UFL_OWNER); leave_building(u2); } } diff --git a/src/kernel/config.h b/src/kernel/config.h index 30145886d..510678c27 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -68,13 +68,6 @@ extern "C" { /* Chance of a monster attack */ #define MONSTERATTACK 0.4F -/** Chance of an unmaintained building crashing */ -/* #define COLLAPSE_CHANCE 0.4F */ -#undef COLLAPSE_CHANCE -/** chance to survive the crash of a building */ -/* #define COLLAPSE_SURVIVAL 0.5F */ -#undef COLLAPSE_SURVIVAL - /* Bewegungsweiten: */ #define BP_WALKING 4 #define BP_RIDING 6 diff --git a/src/kernel/move.c b/src/kernel/move.c index f0d484650..d6600e05d 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -2597,13 +2597,13 @@ void movement(void) set_order(&u->thisorder, NULL); } else { if (ships) { - if (u->ship && fval(u, UFL_OWNER)) { + if (u->ship && ship_owner(u->ship)==u) { init_tokens(u->thisorder); skip_token(); move(u, false); } } else { - if (u->ship == NULL || !fval(u, UFL_OWNER)) { + if (!u->ship || ship_owner(u->ship)!=u) { init_tokens(u->thisorder); skip_token(); move(u, false); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 3b1fdcf3b..f4dd38596 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -795,32 +795,21 @@ void u_set_ship(unit * u, ship * sh) void leave_ship(unit * u) { struct ship *sh = u->ship; - if (!sh) return; + u->ship = 0; + if (sh->_owner==u) { + sh->_owner = ship_owner(sh); + } set_leftship(u, sh); } void leave_building(unit * u) { - struct building *b = u->building; + building * b = u->building; - u->building = NULL; - if (b && fval(u, UFL_OWNER)) { - unit *u2, *owner = NULL; - freset(u, UFL_OWNER); - - for (u2 = u->region->units; u2; u2 = u2->next) { - if (u2->building == b) { - if (u2->faction == u->faction) { - owner = u2; - break; - } else if (owner == NULL) - owner = u2; - } - } - if (owner != NULL) { - fset(owner, UFL_OWNER); - } + u->building = 0; + if (b->_owner==u) { + b->_owner = building_owner(b); } }