forked from github/server
rt_find -> get_resourcetype optimization
This commit is contained in:
parent
d581737744
commit
dc8a8cdd71
|
@ -66,8 +66,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
#include <attributes/orcification.h>
|
#include <attributes/orcification.h>
|
||||||
|
|
||||||
#include <items/seed.h>
|
|
||||||
|
|
||||||
/* libs includes */
|
/* libs includes */
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -2493,11 +2491,7 @@ static void planttrees(region * r, unit * u, int raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mallornbäume kann man nur in Mallornregionen züchten */
|
/* Mallornbäume kann man nur in Mallornregionen züchten */
|
||||||
if (fval(r, RF_MALLORN)) {
|
rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORNSEED : R_SEED);
|
||||||
rtype = rt_mallornseed;
|
|
||||||
} else {
|
|
||||||
rtype = rt_seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skill prüfen */
|
/* Skill prüfen */
|
||||||
skill = eff_skill(u, SK_HERBALISM, r);
|
skill = eff_skill(u, SK_HERBALISM, r);
|
||||||
|
@ -2565,11 +2559,7 @@ static void breedtrees(region * r, unit * u, int raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mallornbäume kann man nur in Mallornregionen züchten */
|
/* Mallornbäume kann man nur in Mallornregionen züchten */
|
||||||
if (fval(r, RF_MALLORN)) {
|
rtype = get_resourcetype(fval(r, RF_MALLORN) ? R_MALLORNSEED : R_SEED);
|
||||||
rtype = rt_mallornseed;
|
|
||||||
} else {
|
|
||||||
rtype = rt_seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Skill prüfen */
|
/* Skill prüfen */
|
||||||
skill = eff_skill(u, SK_HERBALISM, r);
|
skill = eff_skill(u, SK_HERBALISM, r);
|
||||||
|
@ -2679,7 +2669,7 @@ static void breed_cmd(unit * u, struct order *ord)
|
||||||
default:
|
default:
|
||||||
if (p != P_ANY) {
|
if (p != P_ANY) {
|
||||||
rtype = findresourcetype(s, u->faction->locale);
|
rtype = findresourcetype(s, u->faction->locale);
|
||||||
if (rtype == rt_mallornseed || rtype == rt_seed) {
|
if (rtype == get_resourcetype(R_SEED) || rtype == get_resourcetype(R_MALLORNSEED)) {
|
||||||
breedtrees(r, u, m);
|
breedtrees(r, u, m);
|
||||||
break;
|
break;
|
||||||
} else if (rtype != get_resourcetype(R_HORSE)) {
|
} else if (rtype != get_resourcetype(R_HORSE)) {
|
||||||
|
|
|
@ -28,35 +28,33 @@
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
resource_type *rt_seed = 0;
|
|
||||||
resource_type *rt_mallornseed = 0;
|
|
||||||
|
|
||||||
static void produce_seeds(region * r, const resource_type * rtype, int norders)
|
static void produce_seeds(region * r, const resource_type * rtype, int norders)
|
||||||
{
|
{
|
||||||
assert(rtype == rt_seed && r->land && r->land->trees[0] >= norders);
|
assert(r->land && r->land->trees[0] >= norders);
|
||||||
r->land->trees[0] -= norders;
|
r->land->trees[0] -= norders;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int limit_seeds(const region * r, const resource_type * rtype)
|
static int limit_seeds(const region * r, const resource_type * rtype)
|
||||||
{
|
{
|
||||||
assert(rtype == rt_seed);
|
if (fval(r, RF_MALLORN)) {
|
||||||
if (fval(r, RF_MALLORN))
|
return 0;
|
||||||
return 0;
|
}
|
||||||
return r->land ? r->land->trees[0] : 0;
|
return r->land ? r->land->trees[0] : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_seed(void)
|
void init_seed(void)
|
||||||
{
|
{
|
||||||
attrib *a;
|
attrib *a;
|
||||||
resource_limit *rdata;
|
resource_limit *rdata;
|
||||||
|
resource_type *rtype;
|
||||||
|
|
||||||
rt_seed = rt_find("seed");
|
rtype = rt_find("seed");
|
||||||
if (rt_seed != NULL) {
|
if (rtype != NULL) {
|
||||||
a = a_add(&rt_seed->attribs, a_new(&at_resourcelimit));
|
a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
|
||||||
rdata = (resource_limit *) a->data.v;
|
rdata = (resource_limit *) a->data.v;
|
||||||
rdata->limit = limit_seeds;
|
rdata->limit = limit_seeds;
|
||||||
rdata->produce = produce_seeds;
|
rdata->produce = produce_seeds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mallorn */
|
/* mallorn */
|
||||||
|
@ -64,14 +62,12 @@ void init_seed(void)
|
||||||
static void
|
static void
|
||||||
produce_mallornseeds(region * r, const resource_type * rtype, int norders)
|
produce_mallornseeds(region * r, const resource_type * rtype, int norders)
|
||||||
{
|
{
|
||||||
assert(rtype == rt_mallornseed && r->land && r->land->trees[0] >= norders);
|
|
||||||
assert(fval(r, RF_MALLORN));
|
assert(fval(r, RF_MALLORN));
|
||||||
r->land->trees[0] -= norders;
|
r->land->trees[0] -= norders;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int limit_mallornseeds(const region * r, const resource_type * rtype)
|
static int limit_mallornseeds(const region * r, const resource_type * rtype)
|
||||||
{
|
{
|
||||||
assert(rtype == rt_mallornseed);
|
|
||||||
if (!fval(r, RF_MALLORN)) {
|
if (!fval(r, RF_MALLORN)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -80,17 +76,18 @@ static int limit_mallornseeds(const region * r, const resource_type * rtype)
|
||||||
|
|
||||||
void init_mallornseed(void)
|
void init_mallornseed(void)
|
||||||
{
|
{
|
||||||
attrib *a;
|
attrib *a;
|
||||||
resource_limit *rdata;
|
resource_limit *rdata;
|
||||||
|
resource_type *rtype;
|
||||||
|
|
||||||
rt_mallornseed = rt_find("mallornseed");
|
rtype = rt_find("mallornseed");
|
||||||
if (rt_mallornseed != NULL) {
|
if (rtype != NULL) {
|
||||||
rt_mallornseed->flags |= RTF_LIMITED;
|
rtype->flags |= RTF_LIMITED;
|
||||||
rt_mallornseed->flags |= RTF_POOLED;
|
rtype->flags |= RTF_POOLED;
|
||||||
|
|
||||||
a = a_add(&rt_mallornseed->attribs, a_new(&at_resourcelimit));
|
a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
|
||||||
rdata = (resource_limit *) a->data.v;
|
rdata = (resource_limit *) a->data.v;
|
||||||
rdata->limit = limit_mallornseeds;
|
rdata->limit = limit_mallornseeds;
|
||||||
rdata->produce = produce_mallornseeds;
|
rdata->produce = produce_mallornseeds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern struct resource_type *rt_seed;
|
|
||||||
extern void init_seed(void);
|
extern void init_seed(void);
|
||||||
|
|
||||||
extern struct resource_type *rt_mallornseed;
|
|
||||||
extern void init_mallornseed(void);
|
extern void init_mallornseed(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -609,7 +609,8 @@ const char *itemnames[MAX_RESOURCES] = {
|
||||||
"laen", "fairyboot", "aoc", "pegasus",
|
"laen", "fairyboot", "aoc", "pegasus",
|
||||||
"elvenhorse", "charger", "dolphin", "roqf", "trollbelt",
|
"elvenhorse", "charger", "dolphin", "roqf", "trollbelt",
|
||||||
"aurafocus", "sphereofinv", "magicbag",
|
"aurafocus", "sphereofinv", "magicbag",
|
||||||
"magicherbbag", "dreameye", "p2", "money", "aura", "permaura",
|
"magicherbbag", "dreameye", "p2", "seed", "mallornseed",
|
||||||
|
"money", "aura", "permaura",
|
||||||
"hp", "unit", "peasant"
|
"hp", "unit", "peasant"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -290,7 +290,8 @@ extern "C" {
|
||||||
R_SACK_OF_CONSERVATION,
|
R_SACK_OF_CONSERVATION,
|
||||||
R_TACTICCRYSTAL,
|
R_TACTICCRYSTAL,
|
||||||
R_WATER_OF_LIFE,
|
R_WATER_OF_LIFE,
|
||||||
|
R_SEED,
|
||||||
|
R_MALLORNSEED,
|
||||||
/* SONSTIGE */
|
/* SONSTIGE */
|
||||||
R_SILVER,
|
R_SILVER,
|
||||||
R_AURA, /* Aura */
|
R_AURA, /* Aura */
|
||||||
|
|
|
@ -78,13 +78,13 @@ static spell * test_magic_create_spell(void)
|
||||||
|
|
||||||
sp->components = (spell_component *) calloc(4, sizeof(spell_component));
|
sp->components = (spell_component *) calloc(4, sizeof(spell_component));
|
||||||
sp->components[0].amount = 1;
|
sp->components[0].amount = 1;
|
||||||
sp->components[0].type = rt_find("money");
|
sp->components[0].type = get_resourcetype(R_SILVER);
|
||||||
sp->components[0].cost = SPC_FIX;
|
sp->components[0].cost = SPC_FIX;
|
||||||
sp->components[1].amount = 1;
|
sp->components[1].amount = 1;
|
||||||
sp->components[1].type = rt_find("aura");
|
sp->components[1].type = get_resourcetype(R_AURA);
|
||||||
sp->components[1].cost = SPC_LEVEL;
|
sp->components[1].cost = SPC_LEVEL;
|
||||||
sp->components[2].amount = 1;
|
sp->components[2].amount = 1;
|
||||||
sp->components[2].type = rt_find("horse");
|
sp->components[2].type = get_resourcetype(R_HORSE);
|
||||||
sp->components[2].cost = SPC_LINEAR;
|
sp->components[2].cost = SPC_LINEAR;
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
@ -110,16 +110,16 @@ void test_pay_spell(CuTest * tc)
|
||||||
set_level(u, SK_MAGIC, 5);
|
set_level(u, SK_MAGIC, 5);
|
||||||
unit_add_spell(u, 0, sp, 1);
|
unit_add_spell(u, 0, sp, 1);
|
||||||
|
|
||||||
change_resource(u, rt_find("money"), 1);
|
change_resource(u, get_resourcetype(R_SILVER), 1);
|
||||||
change_resource(u, rt_find("aura"), 3);
|
change_resource(u, get_resourcetype(R_AURA), 3);
|
||||||
change_resource(u, rt_find("horse"), 3);
|
change_resource(u, get_resourcetype(R_HORSE), 3);
|
||||||
|
|
||||||
level = eff_spelllevel(u, sp, 3, 1);
|
level = eff_spelllevel(u, sp, 3, 1);
|
||||||
CuAssertIntEquals(tc, 3, level);
|
CuAssertIntEquals(tc, 3, level);
|
||||||
pay_spell(u, sp, level, 1);
|
pay_spell(u, sp, level, 1);
|
||||||
CuAssertIntEquals(tc, 0, get_resource(u, rt_find("money")));
|
CuAssertIntEquals(tc, 0, get_resource(u, get_resourcetype(R_SILVER)));
|
||||||
CuAssertIntEquals(tc, 0, get_resource(u, rt_find("aura")));
|
CuAssertIntEquals(tc, 0, get_resource(u, get_resourcetype(R_AURA)));
|
||||||
CuAssertIntEquals(tc, 0, get_resource(u, rt_find("horse")));
|
CuAssertIntEquals(tc, 0, get_resource(u, get_resourcetype(R_HORSE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_pay_spell_failure(CuTest * tc)
|
void test_pay_spell_failure(CuTest * tc)
|
||||||
|
@ -143,19 +143,19 @@ void test_pay_spell_failure(CuTest * tc)
|
||||||
set_level(u, SK_MAGIC, 5);
|
set_level(u, SK_MAGIC, 5);
|
||||||
unit_add_spell(u, 0, sp, 1);
|
unit_add_spell(u, 0, sp, 1);
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 1, change_resource(u, rt_find("money"), 1));
|
CuAssertIntEquals(tc, 1, change_resource(u, get_resourcetype(R_SILVER), 1));
|
||||||
CuAssertIntEquals(tc, 2, change_resource(u, rt_find("aura"), 2));
|
CuAssertIntEquals(tc, 2, change_resource(u, get_resourcetype(R_AURA), 2));
|
||||||
CuAssertIntEquals(tc, 3, change_resource(u, rt_find("horse"), 3));
|
CuAssertIntEquals(tc, 3, change_resource(u, get_resourcetype(R_HORSE), 3));
|
||||||
|
|
||||||
level = eff_spelllevel(u, sp, 3, 1);
|
level = eff_spelllevel(u, sp, 3, 1);
|
||||||
CuAssertIntEquals(tc, 2, level);
|
CuAssertIntEquals(tc, 2, level);
|
||||||
pay_spell(u, sp, level, 1);
|
pay_spell(u, sp, level, 1);
|
||||||
CuAssertIntEquals(tc, 1, change_resource(u, rt_find("money"), 1));
|
CuAssertIntEquals(tc, 1, change_resource(u, get_resourcetype(R_SILVER), 1));
|
||||||
CuAssertIntEquals(tc, 3, change_resource(u, rt_find("aura"), 3));
|
CuAssertIntEquals(tc, 3, change_resource(u, get_resourcetype(R_AURA), 3));
|
||||||
CuAssertIntEquals(tc, 2, change_resource(u, rt_find("horse"), 1));
|
CuAssertIntEquals(tc, 2, change_resource(u, get_resourcetype(R_HORSE), 1));
|
||||||
|
|
||||||
CuAssertIntEquals(tc, 0, eff_spelllevel(u, sp, 3, 1));
|
CuAssertIntEquals(tc, 0, eff_spelllevel(u, sp, 3, 1));
|
||||||
CuAssertIntEquals(tc, 0, change_resource(u, rt_find("money"), -1));
|
CuAssertIntEquals(tc, 0, change_resource(u, get_resourcetype(R_SILVER), -1));
|
||||||
CuAssertIntEquals(tc, 0, eff_spelllevel(u, sp, 2, 1));
|
CuAssertIntEquals(tc, 0, eff_spelllevel(u, sp, 2, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,9 @@ int get_resource(const unit * u, const resource_type * rtype)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
if (rtype->itype) {
|
if (rtype->itype) {
|
||||||
if (rtype == rt_find("stone") && (u_race(u)->flags & RCF_STONEGOLEM)) {
|
if (rtype == get_resourcetype(R_STONE) && (u_race(u)->flags & RCF_STONEGOLEM)) {
|
||||||
return u->number * GOLEM_STONE;
|
return u->number * GOLEM_STONE;
|
||||||
} else if (rtype->itype == it_find("iron") && (u_race(u)->flags & RCF_IRONGOLEM)) {
|
} else if (rtype == get_resourcetype(R_IRON) && (u_race(u)->flags & RCF_IRONGOLEM)) {
|
||||||
return u->number * GOLEM_IRON;
|
return u->number * GOLEM_IRON;
|
||||||
} else {
|
} else {
|
||||||
return i_get(u->items, rtype->itype);
|
return i_get(u->items, rtype->itype);
|
||||||
|
|
|
@ -14,9 +14,9 @@ static void test_recreate_world(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
CuAssertPtrEquals(tc, 0, get_locale("de"));
|
CuAssertPtrEquals(tc, 0, get_locale("de"));
|
||||||
CuAssertPtrEquals(tc, 0, it_find("horse"));
|
CuAssertPtrEquals(tc, 0, it_find("horse"));
|
||||||
CuAssertPtrNotNull(tc, rt_find("hp"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_LIFE));
|
||||||
CuAssertPtrNotNull(tc, rt_find("permaura"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA));
|
||||||
CuAssertPtrNotNull(tc, rt_find("aura"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_AURA));
|
||||||
CuAssertPtrNotNull(tc, it_find("money"));
|
CuAssertPtrNotNull(tc, it_find("money"));
|
||||||
|
|
||||||
test_create_world();
|
test_create_world();
|
||||||
|
@ -24,26 +24,26 @@ static void test_recreate_world(CuTest * tc)
|
||||||
CuAssertPtrNotNull(tc, default_locale);
|
CuAssertPtrNotNull(tc, default_locale);
|
||||||
CuAssertPtrNotNull(tc, findregion(0, 0));
|
CuAssertPtrNotNull(tc, findregion(0, 0));
|
||||||
CuAssertPtrNotNull(tc, it_find("horse"));
|
CuAssertPtrNotNull(tc, it_find("horse"));
|
||||||
CuAssertPtrNotNull(tc, rt_find("horse"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_HORSE));
|
||||||
CuAssertPtrNotNull(tc, it_find("money"));
|
CuAssertPtrNotNull(tc, it_find("money"));
|
||||||
CuAssertPtrNotNull(tc, rt_find("hp"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_LIFE));
|
||||||
CuAssertPtrNotNull(tc, rt_find("money"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_SILVER));
|
||||||
CuAssertPtrNotNull(tc, rt_find("aura"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_AURA));
|
||||||
CuAssertPtrNotNull(tc, rt_find("permaura"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA));
|
||||||
CuAssertPtrNotNull(tc, rt_find("peasant"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT));
|
||||||
CuAssertPtrNotNull(tc, rt_find("unit"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_UNIT));
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
CuAssertPtrEquals(tc, 0, get_locale("de"));
|
CuAssertPtrEquals(tc, 0, get_locale("de"));
|
||||||
CuAssertPtrEquals(tc, 0, it_find("horse"));
|
CuAssertPtrEquals(tc, 0, (void*)it_find("horse"));
|
||||||
CuAssertPtrEquals(tc, 0, rt_find("horse"));
|
CuAssertPtrEquals(tc, 0, (void*)get_resourcetype(R_HORSE));
|
||||||
CuAssertPtrNotNull(tc, it_find("money"));
|
CuAssertPtrNotNull(tc, it_find("money"));
|
||||||
CuAssertPtrNotNull(tc, rt_find("hp"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_LIFE));
|
||||||
CuAssertPtrNotNull(tc, rt_find("money"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_SILVER));
|
||||||
CuAssertPtrNotNull(tc, rt_find("aura"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_AURA));
|
||||||
CuAssertPtrNotNull(tc, rt_find("permaura"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_PERMAURA));
|
||||||
CuAssertPtrNotNull(tc, rt_find("peasant"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_PEASANT));
|
||||||
CuAssertPtrNotNull(tc, rt_find("unit"));
|
CuAssertPtrNotNull(tc, get_resourcetype(R_UNIT));
|
||||||
CuAssertPtrEquals(tc, 0, findregion(0, 0));
|
CuAssertPtrEquals(tc, 0, findregion(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue