forked from github/server
removed duplication in good/bad dreams code
This commit is contained in:
parent
b41049da53
commit
d9f8479055
|
@ -117,6 +117,8 @@ int curse_age(attrib * a)
|
|||
curse *c = (curse *)a->data.v;
|
||||
int result = 0;
|
||||
|
||||
c_clearflag(c, CURSE_ISNEW);
|
||||
|
||||
if (c_flags(c) & CURSE_NOAGE) {
|
||||
c->duration = INT_MAX;
|
||||
}
|
||||
|
|
|
@ -1274,7 +1274,22 @@ static int item_modification(const unit * u, skill_t sk, int val)
|
|||
return val;
|
||||
}
|
||||
|
||||
static int att_modification(const unit * u, skill_t sk)
|
||||
static int update_gbdream(const unit * u, int bonus, curse *c, const curse_type *gbdream_ct, int sign){
|
||||
if (curse_active(c) && c->type == gbdream_ct) {
|
||||
double effect = curse_geteffect(c);
|
||||
unit *mage = c->magician;
|
||||
/* wir suchen jeweils den groessten Bonus und den groestsen Malus */
|
||||
if (sign * effect > sign * bonus) {
|
||||
if (mage == NULL || mage->number == 0
|
||||
|| sign>0?alliedunit(mage, u->faction, HELP_GUARD):!alliedunit(mage, u->faction, HELP_GUARD)) {
|
||||
bonus = effect;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bonus;
|
||||
}
|
||||
|
||||
int att_modification(const unit * u, skill_t sk)
|
||||
{
|
||||
double result = 0;
|
||||
static bool init = false;
|
||||
|
@ -1311,22 +1326,10 @@ static int att_modification(const unit * u, skill_t sk)
|
|||
attrib *a = a_find(u->region->attribs, &at_curse);
|
||||
while (a && a->type == &at_curse) {
|
||||
curse *c = (curse *)a->data.v;
|
||||
if (curse_active(c) && c->type == gbdream_ct) {
|
||||
double mod = curse_geteffect(c);
|
||||
unit *mage = c->magician;
|
||||
/* wir suchen jeweils den groesten Bonus und den groesten Malus */
|
||||
if (mod > bonus) {
|
||||
if (mage == NULL || mage->number == 0
|
||||
|| alliedunit(mage, u->faction, HELP_GUARD)) {
|
||||
bonus = mod;
|
||||
}
|
||||
}
|
||||
else if (mod < malus) {
|
||||
if (mage == NULL || !alliedunit(mage, u->faction, HELP_GUARD)) {
|
||||
malus = mod;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bonus = update_gbdream(u, bonus, c, gbdream_ct, 1);
|
||||
malus = update_gbdream(u, malus, c, gbdream_ct, -1);
|
||||
|
||||
a = a->next;
|
||||
}
|
||||
result = result + bonus + malus;
|
||||
|
|
40
src/spells.c
40
src/spells.c
|
@ -4645,6 +4645,8 @@ int sp_analysedream(castorder * co)
|
|||
return cast_level;
|
||||
}
|
||||
|
||||
static int sp_gbdreams(castorder * co, const char *curse_name, int effect);
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Name: Schlechte Traeume
|
||||
* Stufe: 10
|
||||
|
@ -4660,28 +4662,7 @@ int sp_analysedream(castorder * co)
|
|||
* */
|
||||
int sp_baddreams(castorder * co)
|
||||
{
|
||||
int duration;
|
||||
unit *mage = co->magician.u;
|
||||
int cast_level = co->level;
|
||||
float power = co->force;
|
||||
region *r = co_get_region(co);
|
||||
curse *c;
|
||||
float effect;
|
||||
|
||||
/* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken,
|
||||
* also duration+2 */
|
||||
duration = (int)_max(1, power / 2); /* Stufe 1 macht sonst mist */
|
||||
duration = 2 + rng_int() % duration;
|
||||
|
||||
/* Nichts machen als ein entsprechendes Attribut in die Region legen. */
|
||||
effect = -1;
|
||||
c = create_curse(mage, &r->attribs, ct_find("gbdream"), power, duration, effect, 0);
|
||||
|
||||
/* Erfolg melden */
|
||||
ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect",
|
||||
"unit region command", c->magician, mage->region, co->order));
|
||||
|
||||
return cast_level;
|
||||
return sp_gbdreams(co, "gbdream", -1);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
@ -4697,21 +4678,26 @@ int sp_baddreams(castorder * co)
|
|||
* (FARCASTING | SPELLLEVEL | REGIONSPELL | TESTRESISTANCE)
|
||||
*/
|
||||
int sp_gooddreams(castorder * co)
|
||||
{
|
||||
return sp_gbdreams(co, "gbdream", 1);
|
||||
}
|
||||
|
||||
static int sp_gbdreams(castorder * co, const char *curse_name, int effect)
|
||||
{
|
||||
int duration;
|
||||
curse *c;
|
||||
region *r = co_get_region(co);
|
||||
unit *mage = co->magician.u;
|
||||
int cast_level = co->level;
|
||||
float power = co->force;
|
||||
float effect;
|
||||
region *r = co_get_region(co);
|
||||
curse *c;
|
||||
|
||||
/* wirkt erst in der Folgerunde, soll mindestens eine Runde wirken,
|
||||
* also duration+2 */
|
||||
duration = (int)_max(1, power / 2); /* Stufe 1 macht sonst mist */
|
||||
duration = 2 + rng_int() % duration;
|
||||
effect = 1;
|
||||
c = create_curse(mage, &r->attribs, ct_find("gbdream"), power, duration, effect, 0);
|
||||
|
||||
/* Nichts machen als ein entsprechendes Attribut in die Region legen. */
|
||||
c = create_curse(mage, &r->attribs, ct_find(curse_name), power, duration, effect, 0);
|
||||
|
||||
/* Erfolg melden */
|
||||
ADDMSG(&mage->faction->msgs, msg_message("regionmagic_effect",
|
||||
|
|
Loading…
Reference in New Issue