forked from github/server
Remove the use of the spelldaten[] array. Replace with registration of spells.
First step towards getting the spell implementations out of the kernel and into gamecode (separate spells from the spell datatype)
This commit is contained in:
parent
2e8f8e28a3
commit
592ac0ce03
|
@ -179,10 +179,7 @@ int
|
|||
season(int turn)
|
||||
{
|
||||
int year,month;
|
||||
int t = turn;
|
||||
#ifdef FIRST_TURN
|
||||
t -= FIRST_TURN;
|
||||
#endif
|
||||
int t = turn - FirstTurn();
|
||||
|
||||
year = t/(months_per_year * weeks_per_month) + 1;
|
||||
month = (t - (year-1) * months_per_year * weeks_per_month)/weeks_per_month;
|
||||
|
@ -198,7 +195,7 @@ gamedate(const struct locale * lang)
|
|||
{
|
||||
int year,month,week,r;
|
||||
static char buf[256];
|
||||
int t = turn - FIRST_TURN;
|
||||
int t = turn - FirstTurn();
|
||||
|
||||
if (t<0) t = turn;
|
||||
assert(lang);
|
||||
|
@ -222,10 +219,7 @@ gamedate_season(const struct locale * lang)
|
|||
{
|
||||
int year,month,week,r;
|
||||
static char buf[256];
|
||||
int t = turn;
|
||||
#ifdef FIRST_TURN
|
||||
t -= FIRST_TURN;
|
||||
#endif
|
||||
int t = turn - FirstTurn();
|
||||
|
||||
if (t<0) t = turn;
|
||||
assert(lang);
|
||||
|
@ -249,10 +243,7 @@ gamedate2(const struct locale * lang)
|
|||
{
|
||||
int year,month,week,r;
|
||||
static char buf[256];
|
||||
int t = turn;
|
||||
#ifdef FIRST_TURN
|
||||
t -= FIRST_TURN;
|
||||
#endif
|
||||
int t = turn - FirstTurn();
|
||||
|
||||
if (t<0) t = turn;
|
||||
|
||||
|
@ -273,10 +264,7 @@ gamedate_short(const struct locale * lang)
|
|||
{
|
||||
int year,month,week,r;
|
||||
static char buf[256];
|
||||
int t = turn;
|
||||
#ifdef FIRST_TURN
|
||||
t -= FIRST_TURN;
|
||||
#endif
|
||||
int t = turn - FirstTurn();
|
||||
|
||||
if (t<0) t = turn;
|
||||
|
||||
|
|
|
@ -117,6 +117,17 @@ MaxAge(void) {
|
|||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
FirstTurn(void)
|
||||
{
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "hunger.long");
|
||||
value = str?atoi(str):0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int
|
||||
LongHunger(void) {
|
||||
static int value = -1;
|
||||
|
@ -2876,11 +2887,9 @@ int months_per_year;
|
|||
int
|
||||
month(int offset)
|
||||
{
|
||||
int t = turn + offset;
|
||||
int t = turn + offset - FirstTurn();
|
||||
int year, r, month;
|
||||
#ifdef FIRST_TURN
|
||||
t -= FIRST_TURN;
|
||||
#endif
|
||||
|
||||
if (t<0) t = turn;
|
||||
|
||||
year = t/(months_per_year * weeks_per_month) + 1;
|
||||
|
|
|
@ -1172,6 +1172,7 @@ extern const char * dbrace(const struct race * rc);
|
|||
extern void set_param(struct param ** p, const char * name, const char * data);
|
||||
extern const char* get_param(const struct param * p, const char * name);
|
||||
|
||||
extern int FirstTurn(void);
|
||||
extern int NMRTimeout(void);
|
||||
extern int LongHunger(void);
|
||||
extern boolean TradeDisabled(void);
|
||||
|
|
|
@ -292,20 +292,19 @@ find_magetype(const unit * u)
|
|||
static void
|
||||
createspelllist(unit *u, magic_t mtyp)
|
||||
{
|
||||
int sk, i;
|
||||
if (mtyp == M_GRAU)
|
||||
return;
|
||||
spell_list * slist;
|
||||
int sk;
|
||||
|
||||
if (mtyp == M_GRAU) return;
|
||||
|
||||
sk = effskill(u, SK_MAGIC);
|
||||
if (sk == 0)
|
||||
return;
|
||||
if (sk == 0) return;
|
||||
|
||||
for (i = 0; spelldaten[i].id != SPL_NOSPELL; i++) {
|
||||
if (spelldaten[i].magietyp == mtyp
|
||||
&& spelldaten[i].level <= sk)
|
||||
{
|
||||
if (!getspell(u, spelldaten[i].id))
|
||||
addspell(u, spelldaten[i].id);
|
||||
for (slist=spells;slist!=NULL;slist=slist->next) {
|
||||
spell * sp = slist->data;
|
||||
if (sp->magietyp == mtyp && sp->level <= sk) {
|
||||
if (!has_spell(u, sp))
|
||||
addspell(u, sp->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -367,23 +366,20 @@ updatespelllist(unit * u)
|
|||
{
|
||||
int max = eff_skill(u, SK_MAGIC, u->region);
|
||||
int sk = max;
|
||||
spell_list * slist;
|
||||
spell * sp;
|
||||
magic_t gebiet = find_magetype(u);
|
||||
boolean ismonster = u->faction->no==MONSTER_FACTION;
|
||||
|
||||
/* Nur Orkmagier bekommen den Keuschheitsamulettzauber */
|
||||
if (old_race(u->race) == RC_ORC
|
||||
&& !getspell(u, SPL_ARTEFAKT_CHASTITYBELT)
|
||||
&& find_spellbyid(SPL_ARTEFAKT_CHASTITYBELT)->level <= max)
|
||||
{
|
||||
sp = find_spellbyid(SPL_ARTEFAKT_CHASTITYBELT);
|
||||
if (old_race(u->race)==RC_ORC && !has_spell(u, sp) && sp->level<=max) {
|
||||
addspell(u, SPL_ARTEFAKT_CHASTITYBELT);
|
||||
}
|
||||
|
||||
/* Nur Wyrm-Magier bekommen den Wyrmtransformationszauber */
|
||||
if (fspecial(u->faction, FS_WYRM)
|
||||
&& !getspell(u, SPL_BECOMEWYRM)
|
||||
&& find_spellbyid(SPL_BECOMEWYRM)->level <= max)
|
||||
{
|
||||
sp = find_spellbyid(SPL_BECOMEWYRM);
|
||||
if (fspecial(u->faction, FS_WYRM) && !has_spell(u, sp) && sp->level<=max) {
|
||||
addspell(u, SPL_BECOMEWYRM);
|
||||
}
|
||||
|
||||
|
@ -394,17 +390,17 @@ updatespelllist(unit * u)
|
|||
/* keine breaks! Wyrme sollen alle drei Zauber können.*/
|
||||
case RC_WYRM:
|
||||
sp = find_spellbyid(SPL_WYRMODEM);
|
||||
if (sp!=NULL && !getspell(u, sp->id) && sp->level<=max) {
|
||||
if (sp!=NULL && !has_spell(u, sp) && sp->level<=max) {
|
||||
addspell(u, sp->id);
|
||||
}
|
||||
case RC_DRAGON:
|
||||
sp = find_spellbyid(SPL_DRAGONODEM);
|
||||
if (sp!=NULL && !getspell(u, sp->id) && sp->level<=max) {
|
||||
if (sp!=NULL && !has_spell(u, sp) && sp->level<=max) {
|
||||
addspell(u, sp->id);
|
||||
}
|
||||
case RC_FIREDRAGON:
|
||||
sp = find_spellbyid(SPL_FIREDRAGONODEM);
|
||||
if (sp!=NULL && getspell(u, sp->id) && sp->level<=max) {
|
||||
if (sp!=NULL && has_spell(u, sp) && sp->level<=max) {
|
||||
addspell(u, sp->id);
|
||||
}
|
||||
break;
|
||||
|
@ -415,8 +411,9 @@ updatespelllist(unit * u)
|
|||
* neue Sprüche in ihre List-of-known-spells. Das sind zb alle alten
|
||||
* Drachen, die noch den Skill Magie haben */
|
||||
|
||||
for (sp = spelldaten; sp->id != SPL_NOSPELL; ++sp) {
|
||||
boolean know = getspell(u, sp->id);
|
||||
for (slist=spells;slist!=NULL;slist=slist->next) {
|
||||
spell * sp = slist->data;
|
||||
boolean know = has_spell(u, sp);
|
||||
|
||||
if (know || (gebiet!=M_GRAU && sp->magietyp == gebiet && sp->level <= sk)) {
|
||||
faction * f = u->faction;
|
||||
|
@ -451,104 +448,17 @@ addspell(unit *u, spellid_t spellid)
|
|||
}
|
||||
|
||||
boolean
|
||||
getspell(const unit *u, spellid_t spellid)
|
||||
{
|
||||
sc_mage *m;
|
||||
spell_ptr *spt;
|
||||
|
||||
m = get_mage(u);
|
||||
if (!m) {
|
||||
return false;
|
||||
}
|
||||
for (spt = m->spellptr; spt; spt = spt->next) {
|
||||
if (spt->spellid == spellid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Spruch identifizieren */
|
||||
|
||||
#include "umlaut.h"
|
||||
|
||||
typedef struct spell_names {
|
||||
struct spell_names * next;
|
||||
const struct locale * lang;
|
||||
magic_t mtype;
|
||||
struct tnode names;
|
||||
} spell_names;
|
||||
|
||||
static spell_names * spellnames;
|
||||
|
||||
static spell_names *
|
||||
init_spellnames(const struct locale * lang, magic_t mtype)
|
||||
{
|
||||
int i;
|
||||
spell_names * sn = calloc(sizeof(spell_names), 1);
|
||||
sn->next = spellnames;
|
||||
sn->lang = lang;
|
||||
sn->mtype = mtype;
|
||||
for (i=0; spelldaten[i].id != SPL_NOSPELL; i++) {
|
||||
const char * n = spelldaten[i].sname;
|
||||
if (spelldaten[i].magietyp!=mtype) continue;
|
||||
if (spelldaten[i].info==NULL) n = locale_string(lang, mkname("spell", n));
|
||||
addtoken(&sn->names, n, (void*)(spelldaten+i));
|
||||
}
|
||||
return spellnames = sn;
|
||||
}
|
||||
|
||||
static spell_names *
|
||||
get_spellnames(const struct locale * lang, magic_t mtype)
|
||||
{
|
||||
spell_names * sn = spellnames;
|
||||
while (sn) {
|
||||
if (sn->mtype==mtype && sn->lang==lang) break;
|
||||
sn=sn->next;
|
||||
}
|
||||
if (!sn) return init_spellnames(lang, mtype);
|
||||
return sn;
|
||||
}
|
||||
|
||||
spell *
|
||||
find_spellbyname(unit *u, const char *name, const struct locale * lang)
|
||||
has_spell(const unit *u, const spell * sp)
|
||||
{
|
||||
spell_ptr *spt;
|
||||
sc_mage * m = get_mage(u);
|
||||
spell * sp = NULL;
|
||||
spell_names * sn;
|
||||
|
||||
if (!m) return NULL;
|
||||
sn = get_spellnames(lang, m->magietyp);
|
||||
if (findtoken(&sn->names, name, (void**)&sp)==E_TOK_NOMATCH) {
|
||||
magic_t mtype;
|
||||
for(mtype=0;mtype!=MAXMAGIETYP;++mtype) {
|
||||
sn = get_spellnames(lang, mtype);
|
||||
if (findtoken(&sn->names, name, (void**)&sp)!=E_TOK_NOMATCH) break;
|
||||
}
|
||||
}
|
||||
if (m==NULL) return false;
|
||||
|
||||
if (sp!=NULL) {
|
||||
for (spt = m->spellptr; spt; spt = spt->next) {
|
||||
if (sp->id==spt->spellid) return sp;
|
||||
if (spt->spellid == sp->id) return true;
|
||||
}
|
||||
}
|
||||
if (lang==default_locale) return NULL;
|
||||
return find_spellbyname(u, name, default_locale);
|
||||
}
|
||||
|
||||
spell *
|
||||
find_spellbyid(spellid_t id)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; spelldaten[i].id != SPL_NOSPELL; i++) {
|
||||
if (spelldaten[i].id == id) {
|
||||
return &spelldaten[i];
|
||||
}
|
||||
}
|
||||
return (spell *) NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
@ -601,7 +511,7 @@ set_combatspell(unit *u, spell *sp, const char * cmd, int level)
|
|||
cmistake(u, cmd, 173, MSG_MAGIC);
|
||||
return;
|
||||
}
|
||||
if (getspell(u, sp->id) == false) {
|
||||
if (has_spell(u, sp) == false) {
|
||||
/* Diesen Zauber kennt die Einheit nicht */
|
||||
cmistake(u, cmd, 169, MSG_MAGIC);
|
||||
return;
|
||||
|
@ -957,7 +867,7 @@ knowsspell(const region * r, const unit * u, const spell * sp)
|
|||
return false;
|
||||
}
|
||||
/* steht der Spruch in der Spruchliste? */
|
||||
if (getspell(u, sp->id) == false){
|
||||
if (has_spell(u, sp) == false){
|
||||
/* ist der Spruch aus einem anderen Magiegebiet? */
|
||||
if (find_magetype(u) != sp->magietyp){
|
||||
return false;
|
||||
|
|
|
@ -125,25 +125,9 @@ typedef struct sc_mage {
|
|||
struct spell_ptr *spellptr;
|
||||
} sc_mage;
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Spruchstukturdefinition:
|
||||
* id:
|
||||
* SPL_NOSPELL muss der letzte Spruch in der Liste spelldaten[] sein,
|
||||
* denn nicht auf die Reihenfolge in der Liste sondern auf die id wird
|
||||
* geprüft
|
||||
* rank:
|
||||
* gibt die Priorität und damit die Reihenfolge an, in der der Spruch
|
||||
* gezaubert wird.
|
||||
* sptyp:
|
||||
* besondere Spruchtypen (Artefakt, Regionszauber, Kampfzauber ..)
|
||||
* Komponenten[Anzahl mögl. Items][Art:Anzahl:Faktor]
|
||||
*
|
||||
*/
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Zauberliste */
|
||||
|
||||
|
||||
typedef struct castorder {
|
||||
struct castorder *next;
|
||||
void *magician; /* Magier (kann vom Typ struct unit oder fighter sein) */
|
||||
|
@ -300,7 +284,7 @@ void unset_combatspell(struct unit *u, spell *sp);
|
|||
/* löscht Kampfzauber */
|
||||
void addspell(struct unit *u, spellid_t spellid);
|
||||
/* fügt den Spruch mit der Id spellid der Spruchliste der Einheit hinzu. */
|
||||
boolean getspell(const struct unit *u, spellid_t spellid);
|
||||
boolean has_spell(const struct unit *u, const struct spell * sp);
|
||||
/* prüft, ob der Spruch in der Spruchliste der Einheit steht. */
|
||||
void updatespelllist(struct unit *u);
|
||||
/* fügt alle Zauber des Magiegebietes der Einheit, deren Stufe kleiner
|
||||
|
|
|
@ -2145,19 +2145,22 @@ readfaction(FILE * F)
|
|||
set_ursprung(f, id, ux, uy);
|
||||
}
|
||||
f->newbies = 0;
|
||||
f->options = ri(F);
|
||||
|
||||
if (((f->options & Pow(O_REPORT)) == 0)
|
||||
&& (f->options & Pow(O_COMPUTER)) == 0) {
|
||||
i = f->options = ri(F);
|
||||
|
||||
if ((i & Pow(O_REPORT))==0 && (i & Pow(O_COMPUTER))==0) {
|
||||
/* Kein Report eingestellt, Fehler */
|
||||
f->options = f->options | Pow(O_REPORT) | Pow(O_ZUGVORLAGE);
|
||||
}
|
||||
|
||||
if (global.data_version < TYPES_VERSION) {
|
||||
int i, sk = ri(F); /* f->seenspell überspringen */
|
||||
for (i = 0; spelldaten[i].id != SPL_NOSPELL; i++) {
|
||||
if (spelldaten[i].magietyp == f->magiegebiet && spelldaten[i].level <= sk) {
|
||||
a_add(&f->attribs, a_new(&at_seenspell))->data.i = spelldaten[i].id;
|
||||
int sk = ri(F); /* f->seenspell überspringen */
|
||||
spell_list * slist;
|
||||
for (slist=spells;slist!=NULL;slist=slist->next) {
|
||||
spell * sp = slist->data;
|
||||
|
||||
if (sp->magietyp==f->magiegebiet && sp->level<=sk) {
|
||||
a_add(&f->attribs, a_new(&at_seenspell))->data.i = sp->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -286,7 +286,10 @@ extern struct attrib_type at_unitdissolve;
|
|||
#ifdef WDW_PYRAMIDSPELL
|
||||
extern struct attrib_type at_wdwpyramid;
|
||||
#endif
|
||||
extern struct spell spelldaten[];
|
||||
|
||||
extern struct spell_list * spells;
|
||||
extern void init_spells(void);
|
||||
extern void register_spell(struct spell * sp);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ xml_to_locale(const xmlChar * xmlStr)
|
|||
static char zText[1024];
|
||||
char * inbuf = (char*)xmlStr;
|
||||
char * outbuf = zText;
|
||||
size_t inbytes = strlen(xmlStr)+1;
|
||||
size_t inbytes = strlen((const char*)xmlStr)+1;
|
||||
size_t outbytes = sizeof(zText);
|
||||
|
||||
if (context==(iconv_t)-1) {
|
||||
|
@ -927,7 +927,7 @@ xml_readstrings(xmlXPathContextPtr xpath, xmlNodePtr * nodeTab, int nodeNr, bool
|
|||
|
||||
xml_readtext(textNode, &lang, &text);
|
||||
if (text!=NULL) {
|
||||
assert(strcmp(zName, xml_cleanup_string(zName))==0);
|
||||
assert(strcmp(zName, (const char*)xml_cleanup_string(BAD_CAST zName))==0);
|
||||
xml_cleanup_string(text);
|
||||
locale_setstring(lang, zName, xml_to_locale(text));
|
||||
xmlFree(text);
|
||||
|
@ -946,7 +946,6 @@ parse_strings(xmlDocPtr doc)
|
|||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
xmlXPathObjectPtr strings;
|
||||
|
||||
/* TODO: remember namespaces */
|
||||
/* reading eressea/strings/string */
|
||||
strings = xmlXPathEvalExpression(BAD_CAST "/eressea/strings/string", xpath);
|
||||
xml_readstrings(xpath, strings->nodesetval->nodeTab, strings->nodesetval->nodeNr, false);
|
||||
|
|
|
@ -49,7 +49,3 @@
|
|||
|
||||
#define MAILITPATH "/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin"
|
||||
|
||||
/* Krücke für die Berechnung der Jahreszeiten in Eressea */
|
||||
|
||||
#define FIRST_TURN 184
|
||||
|
||||
|
|
|
@ -20,9 +20,6 @@
|
|||
|
||||
#include <curse.h>
|
||||
|
||||
/*
|
||||
#include "firewall.h"
|
||||
*/
|
||||
struct curse_type;
|
||||
extern const struct curse_type ct_firewall;
|
||||
extern void ct_register(const struct curse_type * ct);
|
||||
|
|
|
@ -274,13 +274,6 @@ show_newspells(void)
|
|||
* terminieren */
|
||||
|
||||
spellid_t newspellids[] = {
|
||||
#ifdef WDW_PHOENIX
|
||||
SPL_WDWPYRAMID_TRAUM,
|
||||
SPL_WDWPYRAMID_ASTRAL,
|
||||
SPL_WDWPYRAMID_DRUIDE,
|
||||
SPL_WDWPYRAMID_BARDE,
|
||||
SPL_WDWPYRAMID_CHAOS,
|
||||
#endif
|
||||
SPL_NOSPELL
|
||||
};
|
||||
|
||||
|
@ -302,7 +295,7 @@ show_newspells(void)
|
|||
|
||||
if (!sp) continue;
|
||||
|
||||
if (m->magietyp == sp->magietyp || getspell(u, sp->id)) {
|
||||
if (m->magietyp == sp->magietyp || has_spell(u, sp)) {
|
||||
attrib * a = a_find(u->faction->attribs, &at_reportspell);
|
||||
while (a && a->data.i != sp->id) a = a->nexttype;
|
||||
if (!a) {
|
||||
|
@ -316,7 +309,6 @@ show_newspells(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
@ -149,14 +149,15 @@ static void
|
|||
unit_addspell(unit& u, const char * name)
|
||||
{
|
||||
bool add = false;
|
||||
spell * sp = spelldaten;
|
||||
while (sp->id!=SPL_NOSPELL) {
|
||||
spell_list * slist = spells;
|
||||
while (slist!=NULL) {
|
||||
spell * sp = slist->data;
|
||||
if (strcmp(name, sp->sname)==0) {
|
||||
if (add) log_error(("two spells are called %s.\n", name));
|
||||
addspell(&u, sp->id);
|
||||
add = true;
|
||||
}
|
||||
++sp;
|
||||
slist=slist->next;
|
||||
}
|
||||
if (!add) log_error(("spell %s could not be found\n", name));
|
||||
}
|
||||
|
@ -164,7 +165,7 @@ unit_addspell(unit& u, const char * name)
|
|||
static bool
|
||||
unit_isfamiliar(const unit& u)
|
||||
{
|
||||
return is_familiar(&u);
|
||||
return is_familiar(&u)!=0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -178,6 +178,7 @@ game_init(void)
|
|||
|
||||
init_locales();
|
||||
init_attributes();
|
||||
init_spells();
|
||||
init_races();
|
||||
init_items();
|
||||
init_races();
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/race.h>
|
||||
|
@ -182,6 +183,7 @@ game_init(void)
|
|||
/* init_resources(); must be done inside the xml-read, because requirements use items */
|
||||
|
||||
init_attributes();
|
||||
init_spells();
|
||||
init_races();
|
||||
init_items();
|
||||
init_economy();
|
||||
|
|
|
@ -1724,6 +1724,7 @@ main(int argc, char *argv[])
|
|||
|
||||
init_locales();
|
||||
init_attributes();
|
||||
init_spells();
|
||||
|
||||
init_resources();
|
||||
#if NEW_RESOURCEGROWTH
|
||||
|
|
Loading…
Reference in New Issue