forked from github/server
further reduce number of bt_find calls.
This commit is contained in:
parent
5bb9a10a46
commit
d9e541843b
|
@ -1795,6 +1795,7 @@ static void expandselling(region * r, request * sellorders, int limit)
|
||||||
unit *hafenowner;
|
unit *hafenowner;
|
||||||
static int counter[MAXLUXURIES];
|
static int counter[MAXLUXURIES];
|
||||||
static int ncounter = 0;
|
static int ncounter = 0;
|
||||||
|
const struct building_type *castle_bt;
|
||||||
|
|
||||||
if (ncounter == 0) {
|
if (ncounter == 0) {
|
||||||
const luxury_type *ltype;
|
const luxury_type *ltype;
|
||||||
|
@ -1810,15 +1811,15 @@ static void expandselling(region * r, request * sellorders, int limit)
|
||||||
}
|
}
|
||||||
/* Stelle Eigentümer der größten Burg fest. Bekommt Steuern aus jedem
|
/* Stelle Eigentümer der größten Burg fest. Bekommt Steuern aus jedem
|
||||||
* Verkauf. Wenn zwei Burgen gleicher Größe bekommt gar keiner etwas. */
|
* Verkauf. Wenn zwei Burgen gleicher Größe bekommt gar keiner etwas. */
|
||||||
|
castle_bt = bt_find("castle");
|
||||||
for (b = rbuildings(r); b; b = b->next) {
|
for (b = rbuildings(r); b; b = b->next) {
|
||||||
if (b->size > maxsize && building_owner(b) != NULL
|
if (b->size > maxsize && building_owner(b) != NULL
|
||||||
&& b->type == bt_find("castle")) {
|
&& b->type == castle_bt) {
|
||||||
maxb = b;
|
maxb = b;
|
||||||
maxsize = b->size;
|
maxsize = b->size;
|
||||||
maxowner = building_owner(b);
|
maxowner = building_owner(b);
|
||||||
}
|
}
|
||||||
else if (b->size == maxsize && b->type == bt_find("castle")) {
|
else if (b->size == maxsize && b->type == castle_bt) {
|
||||||
maxb = (building *)NULL;
|
maxb = (building *)NULL;
|
||||||
maxowner = (unit *)NULL;
|
maxowner = (unit *)NULL;
|
||||||
}
|
}
|
||||||
|
@ -1923,13 +1924,7 @@ static void expandselling(region * r, request * sellorders, int limit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (use > 0) {
|
if (use > 0) {
|
||||||
#ifdef NDEBUG
|
|
||||||
use_pooled(oa[j].unit, ltype->itype->rtype, GET_DEFAULT, use);
|
use_pooled(oa[j].unit, ltype->itype->rtype, GET_DEFAULT, use);
|
||||||
#else
|
|
||||||
/* int i = */ use_pooled(oa[j].unit, ltype->itype->rtype, GET_DEFAULT,
|
|
||||||
use);
|
|
||||||
/* assert(i==use); */
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(oa);
|
free(oa);
|
||||||
|
|
|
@ -446,6 +446,7 @@ void remove_building(building ** blist, building * b)
|
||||||
|
|
||||||
/* Falls Karawanserei, Damm oder Tunnel einstürzen, wird die schon
|
/* Falls Karawanserei, Damm oder Tunnel einstürzen, wird die schon
|
||||||
* gebaute Straße zur Hälfte vernichtet */
|
* gebaute Straße zur Hälfte vernichtet */
|
||||||
|
// TODO: caravan, tunnel, dam modularization ? is_building_type ?
|
||||||
if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) {
|
if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) {
|
||||||
region *r = b->region;
|
region *r = b->region;
|
||||||
int d;
|
int d;
|
||||||
|
|
|
@ -486,7 +486,6 @@ static void test_building_type(CuTest *tc) {
|
||||||
btype = test_create_buildingtype("house");
|
btype = test_create_buildingtype("house");
|
||||||
CuAssertIntEquals(tc, true, is_building_type(btype, "house"));
|
CuAssertIntEquals(tc, true, is_building_type(btype, "house"));
|
||||||
CuAssertIntEquals(tc, false, is_building_type(btype, "castle"));
|
CuAssertIntEquals(tc, false, is_building_type(btype, "castle"));
|
||||||
CuAssertIntEquals(tc, false, is_building_type(NULL, "house"));
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -764,8 +764,7 @@ static const int wagetable[7][4] = {
|
||||||
|
|
||||||
int cmp_wage(const struct building *b, const building * a)
|
int cmp_wage(const struct building *b, const building * a)
|
||||||
{
|
{
|
||||||
const struct building_type *bt_castle = bt_find("castle");
|
if (is_building_type(b->type, "castle")) {
|
||||||
if (b->type == bt_castle) {
|
|
||||||
if (!a)
|
if (!a)
|
||||||
return 1;
|
return 1;
|
||||||
if (b->size > a->size)
|
if (b->size > a->size)
|
||||||
|
|
|
@ -3082,10 +3082,7 @@ static void age_stonecircle(building *b) {
|
||||||
|
|
||||||
static building *age_building(building * b)
|
static building *age_building(building * b)
|
||||||
{
|
{
|
||||||
const struct building_type *bt_blessed;
|
if (is_building_type(b->type, "blessedstonecircle")) {
|
||||||
|
|
||||||
bt_blessed = bt_find("blessedstonecircle");
|
|
||||||
if (bt_blessed && b->type == bt_blessed) {
|
|
||||||
age_stonecircle(b);
|
age_stonecircle(b);
|
||||||
}
|
}
|
||||||
a_age(&b->attribs, b);
|
a_age(&b->attribs, b);
|
||||||
|
|
|
@ -110,7 +110,7 @@ bool check_leuchtturm(region * r, faction * f)
|
||||||
a = a->next) {
|
a = a->next) {
|
||||||
building *b = (building *)a->data.v;
|
building *b = (building *)a->data.v;
|
||||||
|
|
||||||
assert(b->type == bt_find("lighthouse"));
|
assert(is_building_type(b->type, "lighthouse"));
|
||||||
if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
|
if (fval(b, BLD_MAINTAINED) && b->size >= 10) {
|
||||||
int maxd = (int)log10(b->size) + 1;
|
int maxd = (int)log10(b->size) + 1;
|
||||||
|
|
||||||
|
|
|
@ -669,8 +669,7 @@ static bool is_freezing(const unit * u)
|
||||||
int check_ship_allowed(struct ship *sh, const region * r)
|
int check_ship_allowed(struct ship *sh, const region * r)
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
const building_type *bt_harbour = NULL;
|
const building_type *bt_harbour = bt_find("harbour");
|
||||||
bt_harbour = bt_find("harbour");
|
|
||||||
|
|
||||||
if (sh->region && r_insectstalled(r)) {
|
if (sh->region && r_insectstalled(r)) {
|
||||||
/* insekten dürfen nicht hier rein. haben wir welche? */
|
/* insekten dürfen nicht hier rein. haben wir welche? */
|
||||||
|
@ -923,6 +922,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r)
|
||||||
int guard_count = 0;
|
int guard_count = 0;
|
||||||
int stealth = eff_stealth(reisender, r);
|
int stealth = eff_stealth(reisender, r);
|
||||||
const struct resource_type *ramulet = get_resourcetype(R_AMULET_OF_TRUE_SEEING);
|
const struct resource_type *ramulet = get_resourcetype(R_AMULET_OF_TRUE_SEEING);
|
||||||
|
const struct building_type *castle_bt = bt_find("castle");
|
||||||
|
|
||||||
double base_prob = config_get_flt("rules.guard.base_stop_prob", .3);
|
double base_prob = config_get_flt("rules.guard.base_stop_prob", .3);
|
||||||
double skill_prob = config_get_flt("rules.guard.skill_stop_prob", .1);
|
double skill_prob = config_get_flt("rules.guard.skill_stop_prob", .1);
|
||||||
|
@ -947,7 +947,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r)
|
||||||
double prob_u = (sk - stealth) * skill_prob;
|
double prob_u = (sk - stealth) * skill_prob;
|
||||||
/* amulet counts at most once */
|
/* amulet counts at most once */
|
||||||
prob_u += _min(1, _min(u->number, i_get(u->items, ramulet->itype))) * amulet_prob;
|
prob_u += _min(1, _min(u->number, i_get(u->items, ramulet->itype))) * amulet_prob;
|
||||||
if (u->building && (u->building->type == bt_find("castle")) && u == building_owner(u->building))
|
if (u->building && (u->building->type == castle_bt) && u == building_owner(u->building))
|
||||||
prob_u += castle_prob*buildingeffsize(u->building, 0);
|
prob_u += castle_prob*buildingeffsize(u->building, 0);
|
||||||
if (prob_u >= prob) {
|
if (prob_u >= prob) {
|
||||||
prob = prob_u;
|
prob = prob_u;
|
||||||
|
|
|
@ -352,16 +352,13 @@ void
|
||||||
report_building(const struct building *b, const char **name,
|
report_building(const struct building *b, const char **name,
|
||||||
const char **illusion)
|
const char **illusion)
|
||||||
{
|
{
|
||||||
const struct building_type *bt_illusion;
|
|
||||||
|
|
||||||
if (name) {
|
if (name) {
|
||||||
*name = buildingtype(b->type, b, b->size);
|
*name = buildingtype(b->type, b, b->size);
|
||||||
}
|
}
|
||||||
if (illusion) {
|
if (illusion) {
|
||||||
*illusion = NULL;
|
*illusion = NULL;
|
||||||
|
|
||||||
bt_illusion = bt_find("illusioncastle");
|
if (is_building_type(b->type, "illusioncastle")) {
|
||||||
if (bt_illusion && b->type == bt_illusion) {
|
|
||||||
const attrib *a = a_find(b->attribs, &at_icastle);
|
const attrib *a = a_find(b->attribs, &at_icastle);
|
||||||
if (a != NULL) {
|
if (a != NULL) {
|
||||||
*illusion = buildingtype(icastle_type(a), b, b->size);
|
*illusion = buildingtype(icastle_type(a), b, b->size);
|
||||||
|
|
|
@ -969,7 +969,7 @@ static int sp_blessstonecircle(castorder * co)
|
||||||
|
|
||||||
b = p->param[0]->data.b;
|
b = p->param[0]->data.b;
|
||||||
|
|
||||||
if (b->type != bt_find("stonecircle")) {
|
if (!is_building_type(b->type, "stonecircle")) {
|
||||||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
||||||
"error_notstonecircle", "building", b));
|
"error_notstonecircle", "building", b));
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -2052,7 +2052,7 @@ static int sp_homestone(castorder * co)
|
||||||
double force = co->force;
|
double force = co->force;
|
||||||
double effect;
|
double effect;
|
||||||
message *msg;
|
message *msg;
|
||||||
if (!mage->building || mage->building->type != bt_find("castle")) {
|
if (!mage->building || !is_building_type(mage->building->type, "castle")) {
|
||||||
cmistake(mage, co->order, 197, MSG_MAGIC);
|
cmistake(mage, co->order, 197, MSG_MAGIC);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -5971,8 +5971,8 @@ int sp_movecastle(castorder * co)
|
||||||
u = unext;
|
u = unext;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((b->type == bt_find("caravan") || b->type == bt_find("dam")
|
if ((is_building_type(b->type, "caravan") || is_building_type(b->type, "dam")
|
||||||
|| b->type == bt_find("tunnel"))) {
|
|| is_building_type(b->type, "tunnel"))) {
|
||||||
direction_t d;
|
direction_t d;
|
||||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||||
if (rroad(r, d)) {
|
if (rroad(r, d)) {
|
||||||
|
|
Loading…
Reference in New Issue