forked from github/server
reduce code duplication: itemcloak code was copied between NR and CR.
This commit is contained in:
parent
5a73fc80d8
commit
40d9ebfa94
|
@ -742,13 +742,10 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
|
||||||
const char *str;
|
const char *str;
|
||||||
const item_type *lasttype;
|
const item_type *lasttype;
|
||||||
int pr;
|
int pr;
|
||||||
item *itm, *show;
|
item *itm, *show = NULL;
|
||||||
building *b;
|
building *b;
|
||||||
const char *pzTmp;
|
const char *pzTmp;
|
||||||
skill *sv;
|
skill *sv;
|
||||||
bool itemcloak = false;
|
|
||||||
static const curse_type *itemcloak_ct = 0;
|
|
||||||
static bool init = false;
|
|
||||||
item result[MAX_INVENTORY];
|
item result[MAX_INVENTORY];
|
||||||
const faction *sf;
|
const faction *sf;
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
@ -758,15 +755,6 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
|
||||||
if (fval(u_race(u), RCF_INVISIBLE))
|
if (fval(u_race(u), RCF_INVISIBLE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!init) {
|
|
||||||
init = true;
|
|
||||||
itemcloak_ct = ct_find("itemcloak");
|
|
||||||
}
|
|
||||||
if (itemcloak_ct != NULL) {
|
|
||||||
curse * cu = get_curse(u->attribs, itemcloak_ct);
|
|
||||||
itemcloak = cu && curse_active(cu);
|
|
||||||
}
|
|
||||||
|
|
||||||
stream_printf(out, "EINHEIT %d\n", u->no);
|
stream_printf(out, "EINHEIT %d\n", u->no);
|
||||||
stream_printf(out, "\"%s\";Name\n", unit_getname(u));
|
stream_printf(out, "\"%s\";Name\n", unit_getname(u));
|
||||||
str = u_description(u, f->locale);
|
str = u_description(u, f->locale);
|
||||||
|
@ -970,16 +958,14 @@ void cr_output_unit(stream *out, const region * r, const faction * f,
|
||||||
if (f == u->faction || omniscient(f)) {
|
if (f == u->faction || omniscient(f)) {
|
||||||
show = u->items;
|
show = u->items;
|
||||||
}
|
}
|
||||||
else if (!itemcloak && mode >= see_unit) {
|
|
||||||
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
|
||||||
assert(n >= 0);
|
|
||||||
if (n > 0)
|
|
||||||
show = result;
|
|
||||||
else
|
|
||||||
show = NULL;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
show = NULL;
|
if (mode >= see_unit) {
|
||||||
|
int n = report_items(u, result, MAX_INVENTORY, u, f);
|
||||||
|
assert(n >= 0);
|
||||||
|
if (n > 0) {
|
||||||
|
show = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lasttype = NULL;
|
lasttype = NULL;
|
||||||
for (itm = show; itm; itm = itm->next) {
|
for (itm = show; itm; itm = itm->next) {
|
||||||
|
|
|
@ -897,18 +897,10 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
||||||
{
|
{
|
||||||
building *b = largestbuilding(r, &cmp_wage, false);
|
building *b = largestbuilding(r, &cmp_wage, false);
|
||||||
int esize = 0;
|
int esize = 0;
|
||||||
curse *c;
|
|
||||||
double wage;
|
double wage;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
const building_type *artsculpture_type = bt_find("artsculpture");
|
const building_type *artsculpture_type = bt_find("artsculpture");
|
||||||
static const curse_type *drought_ct, *blessedharvest_ct;
|
const struct curse_type *ctype;
|
||||||
static bool init;
|
|
||||||
|
|
||||||
if (!init) {
|
|
||||||
init = true;
|
|
||||||
drought_ct = ct_find("drought");
|
|
||||||
blessedharvest_ct = ct_find("blessedharvest");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (b != NULL) {
|
if (b != NULL) {
|
||||||
/* TODO: this reveals imaginary castles */
|
/* TODO: this reveals imaginary castles */
|
||||||
|
@ -937,7 +929,7 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
||||||
}
|
}
|
||||||
if (rule_blessed_harvest() == HARVEST_WORK) {
|
if (rule_blessed_harvest() == HARVEST_WORK) {
|
||||||
/* E1 rules */
|
/* E1 rules */
|
||||||
wage += curse_geteffect(get_curse(r->attribs, blessedharvest_ct));
|
wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -954,8 +946,9 @@ default_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bei einer Dürre verdient man nur noch ein Viertel */
|
/* Bei einer Dürre verdient man nur noch ein Viertel */
|
||||||
if (drought_ct) {
|
ctype = ct_find("drought");
|
||||||
c = get_curse(r->attribs, drought_ct);
|
if (ctype) {
|
||||||
|
curse *c = get_curse(r->attribs, ctype);
|
||||||
if (curse_active(c))
|
if (curse_active(c))
|
||||||
wage /= curse_geteffect(c);
|
wage /= curse_geteffect(c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,16 +265,24 @@ static size_t buforder(char *buffer, size_t size, const order * ord, int mode)
|
||||||
* \param viewer: the faction looking at the items
|
* \param viewer: the faction looking at the items
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
report_items(const item * items, item * result, int size, const unit * owner,
|
report_items(const unit *u, item * result, int size, const unit * owner,
|
||||||
const faction * viewer)
|
const faction * viewer)
|
||||||
{
|
{
|
||||||
const item *itm;
|
const item *itm, *items = u->items;
|
||||||
int n = 0; /* number of results */
|
int n = 0; /* number of results */
|
||||||
|
bool itemcloak = false;
|
||||||
|
const curse_type *itemcloak_ct = ct_find("itemcloak");
|
||||||
|
|
||||||
assert(owner == NULL || viewer != owner->faction
|
assert(owner == NULL || viewer != owner->faction);
|
||||||
|| !"not required for owner=viewer!");
|
|
||||||
assert(size);
|
assert(size);
|
||||||
|
|
||||||
|
if (itemcloak_ct) {
|
||||||
|
curse * cu = get_curse(u->attribs, itemcloak_ct);
|
||||||
|
itemcloak = cu && curse_active(cu);
|
||||||
|
}
|
||||||
|
if (itemcloak) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
for (itm = items; itm; itm = itm->next) {
|
for (itm = items; itm; itm = itm->next) {
|
||||||
item *ishow;
|
item *ishow;
|
||||||
const char *ic;
|
const char *ic;
|
||||||
|
@ -455,20 +463,12 @@ size_t size)
|
||||||
const char *pzTmp, *str;
|
const char *pzTmp, *str;
|
||||||
building *b;
|
building *b;
|
||||||
bool isbattle = (bool)(mode == see_battle);
|
bool isbattle = (bool)(mode == see_battle);
|
||||||
item *itm;
|
item *itm, *show = NULL;
|
||||||
item *show;
|
|
||||||
faction *fv = visible_faction(f, u);
|
faction *fv = visible_faction(f, u);
|
||||||
char *bufp = buf;
|
char *bufp = buf;
|
||||||
bool itemcloak = false;
|
|
||||||
const curse_type *itemcloak_ct = 0;
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
item results[MAX_INVENTORY];
|
item results[MAX_INVENTORY];
|
||||||
|
|
||||||
itemcloak_ct = ct_find("itemcloak");
|
|
||||||
if (itemcloak_ct) {
|
|
||||||
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
|
|
||||||
}
|
|
||||||
|
|
||||||
bufp = STRLCPY(bufp, unitname(u), size);
|
bufp = STRLCPY(bufp, unitname(u), size);
|
||||||
|
|
||||||
if (!isbattle) {
|
if (!isbattle) {
|
||||||
|
@ -599,16 +599,12 @@ size_t size)
|
||||||
if (f == u->faction || omniscient(f)) {
|
if (f == u->faction || omniscient(f)) {
|
||||||
show = u->items;
|
show = u->items;
|
||||||
}
|
}
|
||||||
else if (!itemcloak && mode >= see_unit) {
|
else if (mode >= see_unit) {
|
||||||
int n = report_items(u->items, results, MAX_INVENTORY, u, f);
|
int n = report_items(u, results, MAX_INVENTORY, u, f);
|
||||||
assert(n >= 0);
|
assert(n >= 0);
|
||||||
if (n > 0)
|
if (n > 0) {
|
||||||
show = results;
|
show = results;
|
||||||
else
|
}
|
||||||
show = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
show = NULL;
|
|
||||||
}
|
}
|
||||||
for (itm = show; itm; itm = itm->next) {
|
for (itm = show; itm; itm = itm->next) {
|
||||||
const char *ic;
|
const char *ic;
|
||||||
|
|
|
@ -107,7 +107,7 @@ extern "C" {
|
||||||
void view_neighbours(struct seen_region **seen, struct region * r, struct faction * f);
|
void view_neighbours(struct seen_region **seen, struct region * r, struct faction * f);
|
||||||
int report_resources(const struct seen_region *sr,
|
int report_resources(const struct seen_region *sr,
|
||||||
struct resource_report *result, int size, const struct faction *viewer);
|
struct resource_report *result, int size, const struct faction *viewer);
|
||||||
int report_items(const struct item *items, struct item *result, int size,
|
int report_items(const struct unit *u, struct item *result, int size,
|
||||||
const struct unit *owner, const struct faction *viewer);
|
const struct unit *owner, const struct faction *viewer);
|
||||||
void report_item(const struct unit *owner, const struct item *i,
|
void report_item(const struct unit *owner, const struct item *i,
|
||||||
const struct faction *viewer, const char **name, const char **basename,
|
const struct faction *viewer, const char **name, const char **basename,
|
||||||
|
|
|
@ -959,13 +959,7 @@ int sp_strong_wall(struct castorder * co)
|
||||||
unit *mage = fi->unit;
|
unit *mage = fi->unit;
|
||||||
building *burg;
|
building *burg;
|
||||||
double effect;
|
double effect;
|
||||||
static bool init = false;
|
|
||||||
message *msg;
|
message *msg;
|
||||||
static const curse_type *strongwall_ct;
|
|
||||||
if (!init) {
|
|
||||||
init = true;
|
|
||||||
strongwall_ct = ct_find("strongwall");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mage->building) {
|
if (!mage->building) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -973,7 +967,7 @@ int sp_strong_wall(struct castorder * co)
|
||||||
burg = mage->building;
|
burg = mage->building;
|
||||||
|
|
||||||
effect = power / 4;
|
effect = power / 4;
|
||||||
create_curse(mage, &burg->attribs, strongwall_ct, power, 1, effect, 0);
|
create_curse(mage, &burg->attribs, ct_find("strongwall"), power, 1, effect, 0);
|
||||||
|
|
||||||
msg =
|
msg =
|
||||||
msg_message("sp_strongwalls_effect", "mage building", mage, mage->building);
|
msg_message("sp_strongwalls_effect", "mage building", mage, mage->building);
|
||||||
|
|
Loading…
Reference in New Issue