forked from github/server
route all casting through a single cast_spell function.
This commit is contained in:
parent
1885831204
commit
294b7bf01e
18
src/battle.c
18
src/battle.c
|
@ -1749,18 +1749,12 @@ void do_combatmagic(battle * b, combatmagic_t was)
|
|||
fighter *fig = co->magician.fig;
|
||||
const spell *sp = co->sp;
|
||||
|
||||
level = co->level;
|
||||
if (!sp->cast) {
|
||||
log_error("spell '%s' has no function.\n", sp->sname);
|
||||
}
|
||||
else {
|
||||
level = sp->cast(co);
|
||||
level = cast_spell(co);
|
||||
if (level > 0) {
|
||||
pay_spell(fig->unit, sp, level, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (rank = 0; rank < MAX_SPELLRANK; rank++) {
|
||||
free_castorders(spellranks[rank].begin);
|
||||
}
|
||||
|
@ -1771,7 +1765,7 @@ static int cast_combatspell(troop at, const spell * sp, int level, double force)
|
|||
castorder co;
|
||||
|
||||
create_castorder_combat(&co, at.fighter, sp, level, force);
|
||||
level = sp->cast(&co);
|
||||
level = cast_spell(&co);
|
||||
free_castorder(&co);
|
||||
if (level > 0) {
|
||||
pay_spell(at.fighter->unit, sp, level, 1);
|
||||
|
@ -1840,12 +1834,7 @@ static void do_combatspell(troop at)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!sp->cast) {
|
||||
log_error("spell '%s' has no function.\n", sp->sname);
|
||||
}
|
||||
else {
|
||||
level = cast_combatspell(at, sp, level, power);
|
||||
}
|
||||
}
|
||||
|
||||
/* Sonderattacken: Monster patzern nicht und zahlen auch keine
|
||||
|
@ -1860,9 +1849,6 @@ static void do_extra_spell(troop at, const att * a)
|
|||
if (!sp) {
|
||||
log_error("no such spell: '%s'", a->data.sp->name);
|
||||
}
|
||||
else if (sp->cast == NULL) {
|
||||
log_error("spell '%s' has no function.", sp->sname);
|
||||
}
|
||||
else {
|
||||
assert(a->level > 0);
|
||||
cast_combatspell(at, sp, a->level, a->level);
|
||||
|
|
|
@ -512,17 +512,12 @@ static void unit_castspell(unit * u, const char *name, int level)
|
|||
if (sp) {
|
||||
spellbook *book = unit_get_spellbook(u);
|
||||
if (spellbook_get(book, sp)) {
|
||||
if (!sp->cast) {
|
||||
log_error("spell '%s' has no function.\n", sp->sname);
|
||||
}
|
||||
else {
|
||||
castorder co;
|
||||
create_castorder(&co, u, 0, sp, u->region, level, (double)level, 0, 0, 0);
|
||||
sp->cast(&co);
|
||||
cast_spell(&co);
|
||||
free_castorder(&co);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int tolua_unit_castspell(lua_State * L)
|
||||
|
|
|
@ -595,7 +595,7 @@ static void json_spells(cJSON *json) {
|
|||
continue;
|
||||
}
|
||||
else if (strcmp(item->string, "cast") == 0) {
|
||||
sp->cast = (spell_f)get_function(item->valuestring);
|
||||
sp->cast_fun = (spell_f)get_function(item->valuestring);
|
||||
}
|
||||
else if (strcmp(item->string, "syntax") == 0) {
|
||||
sp->syntax = strdup(item->valuestring);
|
||||
|
|
|
@ -41,7 +41,7 @@ extern "C" {
|
|||
int sptyp;
|
||||
int rank; /* Reihenfolge der Zauber */
|
||||
struct spell_component *components;
|
||||
spell_f cast;
|
||||
spell_f cast_fun;
|
||||
} spell;
|
||||
|
||||
typedef struct spellref {
|
||||
|
|
|
@ -1423,7 +1423,7 @@ static int parse_spells(xmlDocPtr doc)
|
|||
xmlFree(propValue);
|
||||
}
|
||||
}
|
||||
sp->cast = (spell_f)cast;
|
||||
sp->cast_fun = (spell_f)cast;
|
||||
xmlXPathFreeObject(result);
|
||||
|
||||
/* reading eressea/spells/spell/resource */
|
||||
|
|
12
src/magic.c
12
src/magic.c
|
@ -1433,7 +1433,7 @@ static void do_fumble(castorder * co)
|
|||
case 5:
|
||||
case 6:
|
||||
/* Spruch gelingt, aber alle Magiepunkte weg */
|
||||
co->level = sp->cast(co);
|
||||
co->level = cast_spell(co);
|
||||
set_spellpoints(u, 0);
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell",
|
||||
u, r, sp));
|
||||
|
@ -1444,7 +1444,7 @@ static void do_fumble(castorder * co)
|
|||
case 9:
|
||||
default:
|
||||
/* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */
|
||||
co->level = sp->cast(co);
|
||||
co->level = cast_spell(co);
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer5", "unit region spell",
|
||||
u, r, sp));
|
||||
countspells(u, 3);
|
||||
|
@ -2900,7 +2900,7 @@ void magic(void)
|
|||
fumbled = true;
|
||||
}
|
||||
else {
|
||||
co->level = sp->cast(co);
|
||||
co->level = cast_spell(co);
|
||||
if (co->level <= 0) {
|
||||
/* Kosten nur für real benötige Stufe berechnen */
|
||||
continue;
|
||||
|
@ -3003,6 +3003,12 @@ spell *unit_getspell(struct unit *u, const char *name, const struct locale * lan
|
|||
return 0;
|
||||
}
|
||||
|
||||
int cast_spell(struct castorder *co)
|
||||
{
|
||||
const spell *sp = co->sp;
|
||||
return sp->cast_fun(co);
|
||||
}
|
||||
|
||||
static critbit_tree cb_spellbooks;
|
||||
|
||||
spellbook * get_spellbook(const char * name)
|
||||
|
|
|
@ -286,6 +286,7 @@ extern "C" {
|
|||
/* Hänge c-order co an die letze c-order von cll an */
|
||||
void free_castorders(struct castorder *co);
|
||||
/* Speicher wieder freigeben */
|
||||
int cast_spell(struct castorder *co);
|
||||
|
||||
/* Prüfroutinen für Zaubern */
|
||||
int countspells(struct unit *u, int step);
|
||||
|
|
|
@ -378,7 +378,7 @@ void test_multi_cast(CuTest *tc) {
|
|||
|
||||
test_setup();
|
||||
sp = create_spell("fireball", 0);
|
||||
sp->cast = cast_fireball;
|
||||
sp->cast_fun = cast_fireball;
|
||||
CuAssertPtrEquals(tc, sp, find_spell("fireball"));
|
||||
|
||||
lang = test_create_locale();
|
||||
|
|
Loading…
Reference in New Issue