- Eine ganze Menge an Kampfmeldungen übersetzt

- API für Kampfmessages runderneuert
- Alte Rendering-Funktionen rausgeworfen
- neue Rendering-Funktion für spells
This commit is contained in:
Enno Rehling 2004-04-19 22:52:36 +00:00
parent d9edccf069
commit b802320b60
10 changed files with 663 additions and 1151 deletions

View File

@ -376,12 +376,23 @@ cr_skill(const void * v, char * buffer, const void * userdata)
return 0;
}
static int
cr_spell(const void * v, char * buffer, const void * userdata)
{
const faction * report = (const faction*)userdata;
spell * sp = (spell*)v;
if (sp!=NULL) sprintf(buffer, "\"%s\"", spell_name(sp, report->locale));
else strcpy(buffer, "\"\"");
return 0;
}
void
creport_init(void)
{
tsf_register("report", &cr_ignore);
tsf_register("string", &cr_string);
tsf_register("order", &cr_string);
tsf_register("spell", &cr_spell);
tsf_register("int", &cr_int);
tsf_register("unit", &cr_unit);
tsf_register("region", &cr_region);

View File

@ -3483,6 +3483,16 @@ eval_unit(struct opstack ** stack, const void * userdata) /* unit -> string */
opush(stack, strcpy(balloc(len+1), c));
}
static void
eval_spell(struct opstack ** stack, const void * userdata) /* unit -> string */
{
const struct faction * f = (const struct faction *)userdata;
const struct spell * sp = opop(stack, const struct spell *);
const char * c = sp?spell_name(sp, f->locale):"an unknown spell";
size_t len = strlen(c);
opush(stack, strcpy(balloc(len+1), c));
}
static void
eval_unitname(struct opstack ** stack, const void * userdata) /* unit -> string */
{
@ -3628,6 +3638,7 @@ report_init(void)
add_function("ship", &eval_ship);
add_function("unit", &eval_unit);
add_function("order", &eval_string);
add_function("spell", &eval_spell);
add_function("unit.name", &eval_unitname);
add_function("unit.id", &eval_unitid);
add_function("building", &eval_building);

View File

@ -31,7 +31,6 @@ SOURCES =
pool.c
race.c
region.c
render.c
reports.c
resources.c
save.c

View File

@ -226,10 +226,12 @@ sideabkz(side *s, boolean truename)
return sideabkz_buf;
}
static void
brecord(faction * f, region * r, struct message * m)
void
message_faction(battle * b, faction * f, struct message * m)
{
if (!f->battles || f->battles->r!=r) {
region * r = b->region;
if (f->battles==NULL || f->battles->r!=r) {
struct bmsg * bm = calloc(1, sizeof(struct bmsg));
bm->next = f->battles;
f->battles = bm;
@ -275,20 +277,26 @@ battledebug(const char *s)
}
void
battlerecord(battle * b, const char *s)
message_all(battle * b, message * m)
{
bfaction * bf;
struct message * m = msg_message("msg_battle", "string", strdup(s));
plane * p = rplane(b->region);
watcher * w;
for (bf = b->factions;bf;bf=bf->next) {
brecord(bf->faction, b->region, m);
message_faction(b, bf->faction, m);
}
if (p) for (w=p->watchers;w;w=w->next) {
for (bf = b->factions;bf;bf=bf->next) if (bf->faction==w->faction) break;
if (bf==NULL) brecord(w->faction, b->region, m);
if (bf==NULL) message_faction(b, w->faction, m);
}
}
void
battlerecord(battle * b, const char *s)
{
struct message * m = msg_message("msg_battle", "string", strdup(s));
message_all(b, m);
msg_release(m);
}
@ -303,20 +311,21 @@ battlemsg(battle * b, unit * u, const char * s)
sprintf(buf, "%s %s", unitname(u), s);
m = msg_message("msg_battle", "string", strdup(buf));
for (bf=b->factions;bf;bf=bf->next) {
brecord(bf->faction, u->region, m);
message_faction(b, bf->faction, m);
}
if (p) for (w=p->watchers;w;w=w->next) {
for (bf = b->factions;bf;bf=bf->next) if (bf->faction==w->faction) break;
if (bf==NULL) brecord(w->faction, b->region, m);
if (bf==NULL) message_faction(b, w->faction, m);
}
msg_release(m);
}
static void
fbattlerecord(faction * f, region * r, const char *s)
fbattlerecord(battle * b, faction * f, const char *s)
{
s = gc_add(strdup(s));
brecord(f, r, new_message(f, "msg_battle%s:string", s));
message * m = msg_message("msg_battle", "string", gc_add(strdup(s)));
message_faction(b, f, m);
msg_release(m);
}
boolean
@ -428,38 +437,6 @@ countallies(side * as)
return count;
}
#ifdef NEW_TACTICS
static int
support(tactics * tac)
{
return tac ? 100 : 0;
}
static int
tactics_bonus(troop at, troop dt, boolean attacking)
{
battle *b = dt.fighter->side->battle;
side *as = at.fighter->side;
side *ds = dt.fighter->side;
side *s;
int abest = 0, dbest = 0;
cv_foreach(s, b->sides) {
if (!enemy(s, as) && allysf(s, as->bf->faction)) {
if (rand() % countallies(as) < support(&as->leader))
abest = max(s->leader.value, abest);
} else if (!enemy(s, as) && allysf(s, ds->bf->faction)) {
if (rand() % countallies(ds) < support(&ds->leader))
dbest = max(s->leader.value, dbest);
}
}
cv_next(s);
if (abest > dbest)
return attacking;
return 0;
}
#endif /* NEW_TACTICS */
int
statusrow(int status)
{
@ -594,7 +571,7 @@ reportcasualties(battle * b, fighter * fig, int dead)
if (fig->run.region == NULL) fig->run.region = b->region;
}
#endif
fbattlerecord(fig->unit->faction, b->region, " ");
fbattlerecord(b, fig->unit->faction, " ");
for (bf = b->factions;bf;bf=bf->next) {
faction * f = bf->faction;
#ifdef NO_RUNNING
@ -604,7 +581,7 @@ reportcasualties(battle * b, fighter * fig, int dead)
struct message * m = msg_message("casualties", "unit runto run alive fallen",
fig->unit, fig->run.region, fig->run.number, fig->alive, dead);
#endif
brecord(f, b->region, m);
message_faction(b, f, m);
msg_release(m);
}
}
@ -1019,6 +996,9 @@ rel_dam(int dam, int hp)
boolean
terminate(troop dt, troop at, int type, const char *damage, boolean missile)
{
#ifdef SMALL_BATTLE_MESSAGES
char smallbuf[512];
#endif
item ** pitm;
fighter *df = dt.fighter;
fighter *af = at.fighter;
@ -1028,7 +1008,6 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
int heiltrank = 0;
int faerie_level;
char debugbuf[512];
char smallbuf[512];
double kritchance;
/* Schild */
@ -1207,6 +1186,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
sprintf(debugbuf, "Verursacht %dTP, Rüstung %d: %d -> %d HP",
da, ar, df->person[dt.index].hp, df->person[dt.index].hp - rda);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
if (rda > 0) {
sprintf(smallbuf, "Der Treffer verursacht %s",
@ -1215,6 +1195,7 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
sprintf(smallbuf, "Der Treffer verursacht keinen Schaden");
}
}
#endif
assert(dt.index<du->number);
df->person[dt.index].hp -= rda;
@ -1231,28 +1212,32 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
}
}
df->person[dt.index].flags = (df->person[dt.index].flags & ~FL_SLEEPING);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, ".");
battlerecord(b, smallbuf);
}
#endif
return false;
}
#ifdef SHOW_KILLS
++at.fighter->kills;
#endif
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, ", die tödlich ist");
}
#endif
/* Sieben Leben */
if (old_race(du->race) == RC_CAT && (chance(1.0 / 7))) {
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, ", doch die Katzengöttin ist gnädig");
battlerecord(b, smallbuf);
} else {
/* battlemsg(b, du, "verbraucht eins der 7 Leben einer Katze."); */
}
#endif
assert(dt.index>=0 && dt.index<du->number);
df->person[dt.index].hp = unit_max_hp(du);
return false;
@ -1268,11 +1253,16 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
heiltrank = 1;
}
if (heiltrank && (chance(0.50))) {
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, ", doch ein Heiltrank bringt Rettung");
battlerecord(b, smallbuf);
} else {
battlemsg(b, du, "konnte durch einen Heiltrank überleben.");
} else
#endif
{
message * m = msg_message("battle::potionsave", "unit", du);
message_faction(b, du->faction, m);
msg_release(m);
}
assert(dt.index>=0 && dt.index<du->number);
df->person[dt.index].hp = du->race->hitpoints;
@ -1281,10 +1271,12 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
strcat(debugbuf, ", tot");
battledebug(debugbuf);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, ".");
battlerecord(b, smallbuf);
}
#endif
for (pitm=&du->items; *pitm; pitm=&(*pitm)->next) {
const item_type * itype = (*pitm)->type;
if (!itype->flags & ITF_CURSED && dt.index < (*pitm)->number) {
@ -1430,7 +1422,13 @@ fighters(battle *b, fighter *af, int minrow, int maxrow, int mask)
return fightervp;
}
/* ------------------------------------------------------------------ */
static void
report_failed_spell(battle * b, unit * mage, spell * sp)
{
message * m = msg_message("battle::spell_failed", "unit spell", mage, sp);
message_all(b, m);
msg_release(m);
}
void
do_combatmagic(battle *b, combatmagic_t was)
@ -1487,24 +1485,20 @@ do_combatmagic(battle *b, combatmagic_t was)
level = eff_spelllevel(mage, sp, level, 1);
if (sl > 0) level = min(sl, level);
if (level < 0) {
sprintf(buf, "%s versucht %s zu zaubern, doch der Zauber schlägt "
"fehl!", unitname(mage), spell_name(sp, lang));
battlerecord(b, buf);
report_failed_spell(b, mage, sp);
continue;
}
power = spellpower(r, mage, sp, level);
if (power <= 0) { /* Effekt von Antimagie */
sprintf(buf, "%s versucht %s zu zaubern, doch der Zauber schlägt "
"fehl!", unitname(mage), spell_name(sp, lang));
battlerecord(b, buf);
report_failed_spell(b, mage, sp);
pay_spell(mage, sp, level, 1);
continue;
}
if (fumble(r, mage, sp, sp->level) == true) {
sprintf(buf, "%s versucht %s zu zaubern, doch der Zauber schlägt "
"fehl!", unitname(mage), spell_name(sp, lang));
battlerecord(b, buf);
report_failed_spell(b, mage, sp);
pay_spell(mage, sp, level, 1);
continue;
}
@ -1568,9 +1562,7 @@ do_combatspell(troop at, int row)
if ((sl = get_combatspelllevel(mage, 1)) > 0) level = min(level, sl);
if (fumble(r, mage, sp, sp->level) == true) {
sprintf(buf, "%s versucht %s zu zaubern, doch der Zauber schlägt "
"fehl!", unitname(mage), spell_name(sp, lang));
battlerecord(b, buf);
report_failed_spell(b, mage, sp);
pay_spell(mage, sp, level, 1);
return;
}
@ -1587,16 +1579,13 @@ do_combatspell(troop at, int row)
/* Antimagie die Fehlschlag erhöht */
if (rand()%100 < fumblechance) {
sprintf(buf, "%s versucht %s zu zaubern, doch der Zauber schlägt "
"fehl!", unitname(mage), spell_name(sp, lang));
battlerecord(b, buf);
report_failed_spell(b, mage, sp);
pay_spell(mage, sp, level, 1);
return;
}
power = spellpower(r, mage, sp, level);
if (power <= 0) { /* Effekt von Antimagie */
sprintf(buf, "%s versucht %s zu zaubern, doch der Zauber schlägt "
"fehl!", unitname(mage), spell_name(sp, lang));
battlerecord(b, buf);
report_failed_spell(b, mage, sp);
pay_spell(mage, sp, level, 1);
return;
}
@ -1660,12 +1649,6 @@ skilldiff(troop at, troop dt, int dist)
skdiff += af->person[at.index].attack;
skdiff -= df->person[dt.index].defence;
#ifdef NEW_TACTICS
/* Effekte von Taktikern */
skdiff += tactics_bonus(at, dt, true);
skdiff -= tactics_bonus(dt, at, false);
#endif
if (df->building) {
boolean init = false;
static const curse_type * strongwall_ct, * magicwalls_ct;
@ -1777,11 +1760,13 @@ attack_message(const troop at, const troop dt, const weapon * wp, int dist)
int
hits(troop at, troop dt, weapon * awp)
{
#ifdef SMALL_BATTLE_MESSAGES
char * smallbuf = NULL;
battle * b = at.fighter->side->battle;
#endif
fighter *af = at.fighter, *df = dt.fighter;
unit *au = af->unit, *du = df->unit;
char debugbuf[512];
char *smallbuf = NULL;
armor_t armor, shield;
int skdiff = 0;
int dist = get_unitrow(af) + get_unitrow(df) - 1;
@ -1819,17 +1804,20 @@ hits(troop at, troop dt, weapon * awp)
locale_string(default_locale, resourcename(dwp->type->itype->rtype, 0)) : "unbewaffnet",
weapon_effskill(dt, at, dwp, true, dist>1),
skdiff, dist);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
smallbuf = attack_message(at, dt, awp, dist);
}
#endif
if (contest(skdiff, armor, shield)) {
strcat(debugbuf, " und trifft.");
battledebug(debugbuf);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, " und trifft.");
battlerecord(b,smallbuf);
}
#endif
#ifdef SHOW_KILLS
++at.fighter->hits;
#endif
@ -1837,54 +1825,65 @@ hits(troop at, troop dt, weapon * awp)
}
strcat(debugbuf, ".");
battledebug(debugbuf);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcat(smallbuf, ".");
battlerecord(b,smallbuf);
}
#endif
return 0;
}
void
dazzle(battle *b, troop *td)
{
#ifdef SMALL_BATTLE_MESSAGES
char smallbuf[512];
#endif
/* Nicht kumulativ ! */
if(td->fighter->person[td->index].flags & FL_DAZZLED) return;
#ifdef TODO_RUNESWORD
if (td->fighter->weapon[WP_RUNESWORD].count > td->index) {
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
strcpy(smallbuf, "Das Runenschwert glüht kurz auf.");
battlerecord(b,smallbuf);
}
#endif
return;
}
#endif
if (td->fighter->person[td->index].flags & FL_HERO) {
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
sprintf(smallbuf, "Eine kurze Schwäche erfaßt %s/%d, vergeht jedoch "
"schnell wieder.", unitname(td->fighter->unit), td->index);
battlerecord(b,smallbuf);
}
#endif
return;
}
if (td->fighter->person[td->index].flags & FL_DAZZLED) {
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
sprintf(smallbuf, "Eine kurze Schwäche erfaßt %s/%d, vergeht jedoch "
"schnell wieder.", unitname(td->fighter->unit), td->index);
battlerecord(b,smallbuf);
}
#endif
return;
}
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
sprintf(smallbuf, "%s/%d fühlt sich, als würde Kraft entzogen.",
unitname(td->fighter->unit), td->index);
battlerecord(b,smallbuf);
}
#endif
td->fighter->person[td->index].flags |= FL_DAZZLED;
td->fighter->person[td->index].defence--;
}
@ -2341,7 +2340,7 @@ aftermath(battle * b)
#ifdef SHOW_KILLS
if (df->hits + df->kills) {
struct message * m = new_message(du->faction, "killsandhits%u:unit%i:hits%i:kills", du, df->hits, df->kills);
brecord(du->faction, b->region, m);
message_faction(b, du->faction, m);
}
#endif
}
@ -2499,7 +2498,7 @@ aftermath(battle * b)
for (bf=b->factions;bf;bf=bf->next) {
faction * f = bf->faction;
fbattlerecord(f, r, " ");
fbattlerecord(b, f, " ");
cv_foreach(s, b->sides) {
if (seematrix(f, s)) {
sprintf(buf, "Heer %2d(%s): %d Tote, %d Geflohene, %d Überlebende",
@ -2508,7 +2507,7 @@ aftermath(battle * b)
sprintf(buf, "Heer %2d(Unb): %d Tote, %d Geflohene, %d Überlebende",
s->index, s->dead, s->flee, s->alive);
}
fbattlerecord(f, r, buf);
fbattlerecord(b, f, buf);
} cv_next(s);
}
/* Wir benutzen drifted, um uns zu merken, ob ein Schiff
@ -2524,7 +2523,7 @@ aftermath(battle * b)
const item_type * itype = l->type;
sprintf(buf, "%s erbeute%s %d %s.", unitname(du), du->number==1?"t":"n",
l->number, locale_string(default_locale, resourcename(itype->rtype, l->number!=1)));
fbattlerecord(du->faction, r, buf);
fbattlerecord(b, du->faction, buf);
i_change(&du->items, itype, l->number);
}
@ -2574,7 +2573,7 @@ battle_punit(unit * u, battle * b)
S = 0;
spunit(&S, f, u, 4, see_battle);
for (x = S; x; x = x->next) {
fbattlerecord(f, u->region, x->s);
fbattlerecord(b, f, x->s);
if (u->faction == f)
battledebug(x->s);
}
@ -2595,9 +2594,9 @@ print_fighters(battle * b, cvector * fighters)
int row = get_unitrow(df);
if (row != lastrow) {
char zText[32];
sprintf(zText, "... in der %d. Kampflinie:", row);
battlerecord(b, zText);
message * m = msg_message("battle::row_header", "row", row);
message_all(b, m);
msg_release(m);
lastrow = row;
}
battle_punit(du, b);
@ -2640,7 +2639,7 @@ print_header(battle * b)
if (first) strcat(buf, " und ");
if (lastf) strcat(buf, lastf);
strcat(buf, ".");
fbattlerecord(f, b->region, buf);
fbattlerecord(b, f, buf);
}
free(seen);
}
@ -2660,11 +2659,11 @@ print_stats(battle * b)
for (bf=b->factions;bf;bf=bf->next) {
faction * f = bf->faction;
fbattlerecord(f, b->region, " ");
fbattlerecord(b, f, " ");
sprintf(buf, "Heer %d: %s", side->index,
seematrix(f, side)
? sidename(side,false) : LOC(f->locale, "unknown_faction"));
fbattlerecord(f, b->region, buf);
fbattlerecord(b, f, buf);
strcpy(buf, LOC(f->locale, "battle_opponents"));
komma = false;
cv_foreach(s2, b->sides) {
@ -2680,7 +2679,7 @@ print_stats(battle * b)
}
}
cv_next(s2);
fbattlerecord(f, b->region, buf);
fbattlerecord(b, f, buf);
strcpy(buf, "Attacke gegen:");
komma = false;
cv_foreach(s2, b->sides) {
@ -2695,7 +2694,7 @@ print_stats(battle * b)
}
}
cv_next(s2);
fbattlerecord(f, b->region, buf);
fbattlerecord(b, f, buf);
}
buf[77] = (char)0;
for (k = buf; *k; ++k) *k = '-';
@ -2730,10 +2729,14 @@ print_stats(battle * b)
fighter *tf;
cv_foreach(tf, side->leader.fighters) {
unit *u = tf->unit;
if (!fval(tf, FIG_ATTACKED))
battlemsg(b, u, "überrascht den Gegner.");
else
battlemsg(b, u, "konnte dem Gegner eine Falle stellen.");
message * m = NULL;
if (!fval(tf, FIG_ATTACKED)) {
msg_message("battle::tactics_lost", "unit", u);
} else {
msg_message("battle::tactics_won", "unit", u);
}
message_all(b, m);
msg_release(m);
} cv_next(tf);
}
} cv_next(side);
@ -3231,13 +3234,13 @@ battle_report(battle * b)
for (bf=b->factions;bf;bf=bf->next) {
faction * fac = bf->faction;
fbattlerecord(fac, b->region, " ");
fbattlerecord(b, fac, " ");
if (cont == true)
sprintf(buf2, "Einheiten vor der %d. Runde:",
b->turn);
else
sprintf(buf2, "Einheiten nach dem Kampf:");
fbattlerecord(fac, b->region, buf2);
fbattlerecord(b, fac, buf2);
buf2[0] = 0;
komma = false;
cv_foreach(s, b->sides) {
@ -3269,7 +3272,7 @@ battle_report(battle * b)
}
}
} cv_next(s);
fbattlerecord(fac, b->region, buf2);
fbattlerecord(b, fac, buf2);
}
return cont;
}
@ -3416,24 +3419,12 @@ guarded_by(region * r, faction * f)
}
#endif
void
do_battle(void)
static boolean
init_battle(region * r, battle **bp)
{
region *r;
char smallbuf[512];
list_foreach(region, regions, r) {
unit *u;
battle * b = NULL;
int sides = 0;
side *s;
ship * sh;
void **fi;
building *bu;
for (u = r->units; u != NULL; u = u->next) {
fset(u->faction, FFL_NOAID);
}
unit * u;
boolean fighting = false;
/* list_foreach geht nicht, wegen flucht */
for (u = r->units; u != NULL; u = u->next) {
@ -3546,7 +3537,11 @@ do_battle(void)
}
/* Ende Fehlerbehandlung */
if (!b) {
if (b==NULL) {
unit * utmp;
for (utmp=r->units; utmp!=NULL; utmp=utmp->next) {
fset(utmp->faction, FFL_NOAID);
}
b = make_battle(r);
}
c1 = join_battle(b, u, true);
@ -3557,7 +3552,7 @@ do_battle(void)
* Einheiten greifen ein. */
if (!fval(u2, UFL_NOAID)) freset(u2->faction, FFL_NOAID);
if (c1 && c2) {
if (c1!=NULL && c2!=NULL) {
/* Merken, wer Angreifer ist, für die Rückzahlung der
* Präcombataura bei kurzem Kampf. */
c1->side->bf->attacker = true;
@ -3568,62 +3563,72 @@ do_battle(void)
sidename(c2->side, false));
battledebug(buf);
}
sides = 1;
fighting = true;
}
}
}
list_next(sl);
}
}
if (!b)
list_continue(r);
*bp = b;
return fighting;
}
void
do_battle(void)
{
region *r;
#ifdef SMALL_BATTLE_MESSAGES
char smallbuf[512];
#endif
for (r=regions;r!=NULL;r=r->next) {
battle *b = NULL;
boolean fighting = false;
side *s;
ship * sh;
void **fi;
building *bu;
fighting = init_battle(r, &b);
if (b==NULL) continue;
/* Bevor wir die alliierten hineinziehen, sollten wir schauen, *
* Ob jemand fliehen kann. Dann erübrigt sich das ganze ja
* vielleicht schon. */
print_header(b);
if (!sides) {
if (!fighting) {
/* Niemand mehr da, Kampf kann nicht stattfinden. */
battlerecord(b, "Der Kampf wurde abgebrochen, da alle "
"Verteidiger flohen.");
message * m = msg_message("battle::aborted", "");
message_all(b, m);
msg_release(m);
free_battle(b);
free(b);
list_continue(r);
continue;
}
join_allies(b);
/* Jetzt reinitialisieren wir die Matrix nochmal, um auch die passiv
* in den Kampf gezogenen korrekt zu behandeln. */
/* Jetzt wird gekämpft, je COMBAT_TURNS Runden lang, plus
* evtl.taktik: */
/* Alle Mann raus aus der Burg! */
list_foreach(building, rbuildings(r), bu) {
bu->sizeleft = bu->size;
}
list_next(bu);
for (bu=r->buildings; bu!=NULL; bu=bu->next) bu->sizeleft = bu->size;
/* make sure no ships are damaged initially */
for (sh=r->ships; sh; sh=sh->next) freset(sh, SF_DAMAGED);
/* Gibt es eine Taktikrunde ? */
b->turn = 1;
#ifndef NEW_TACTICS
if (cv_size(&b->leaders)) {
b->turn = 0;
b->has_tactics_turn = true;
} else {
b->turn = 1;
b->has_tactics_turn = false;
}
#endif
/* PRECOMBATSPELLS */
do_combatmagic(b, DO_PRECOMBATSPELL);
/* Nun erstellen wir eine Liste von allen Kämpfern, die wir
* dann scramblen */
/* Zuerst werden sie wild gemischt, und dann wird (stabil) *
* dann scramblen. Zuerst werden sie wild gemischt, und dann wird (stabil)
* nach der Kampfreihe sortiert */
v_scramble(b->fighters.begin, b->fighters.end);
v_sort(b->fighters.begin, b->fighters.end, (v_sort_fun) sort_fighterrow);
@ -3642,14 +3647,12 @@ do_battle(void)
b->dh += fig->unit->number;
}
#if 0
#ifdef SMALL_BATTLE_MESSAGES
if (b->dh <= 30) {
b->small = true;
} else {
b->small = false;
}
#else
b->small = false;
#endif
for (;battle_report(b) && b->turn<=COMBAT_TURNS;++b->turn) {
@ -3706,6 +3709,7 @@ do_battle(void)
if (chance(min(fleechance(u)+ispaniced, 0.90))) {
++runners;
flee(dt);
#ifdef SMALL_BATTLE_MESSAGES
if (b->small) {
sprintf(smallbuf, "%s/%d gelingt es, vom Schlachtfeld zu entkommen.",
unitname(fig->unit), dt.index);
@ -3715,6 +3719,7 @@ do_battle(void)
sprintf(smallbuf, "%s/%d versucht zu fliehen, wird jedoch aufgehalten.",
unitname(fig->unit), dt.index);
battlerecord(b, smallbuf);
#endif
}
}
}
@ -3789,7 +3794,6 @@ do_battle(void)
free(b);
}
}
list_next(r);
}
/* ------------------------------------------------------------- */

View File

@ -36,6 +36,8 @@ extern "C" {
#define LAST_ROW (NUMROWS-1)
#define FIRST_ROW FIGHT_ROW
struct message;
typedef struct bfaction {
struct bfaction * next;
struct side * sides;
@ -60,7 +62,9 @@ extern "C" {
boolean reelarrow;
int dh;
int alive;
#ifdef SMALL_BATTLE_MESSAGES
boolean small;
#endif
#ifdef FAST_GETUNITROW
boolean nonblockers;
#endif
@ -218,6 +222,8 @@ extern "C" {
extern boolean terminate(troop dt, troop at, int type, const char *damage, boolean missile);
extern void battlemsg(battle * b, struct unit * u, const char * s);
extern void battlerecord(battle * b, const char *s);
extern void message_all(battle * b, struct message * m);
extern void message_faction(battle * b, struct faction * f, struct message * m);
extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg, int damage_abs);
extern struct cvector * fighters(struct battle *b, struct fighter *af, int minrow, int maxrow, int mask);

View File

@ -19,6 +19,7 @@
#include "faction.h"
#include "item.h"
#include "magic.h"
#include "message.h"
#include "region.h"
#include "unit.h"
#include "movement.h"
@ -141,8 +142,9 @@ sp_kampfzauber(fighter * fi, int level, double power, spell * sp)
enemies = count_enemies(b, fi->side, minrow, maxrow);
if (!enemies) {
scat(", aber niemand war in Reichweite.");
battlerecord(b, buf);
message * m = msg_message("battle::out_of_range", "mage spell", fi->unit, sp);
message_all(b, m);
msg_release(m);
return 0;
}
scat(":");

View File

@ -577,13 +577,10 @@ ffindhash(int no)
void
stripfaction (faction * f)
{
#ifdef OLD_MESSAGES
free_messages(f->msgs);
#else
/* TODO: inhalt auch löschen */
if (f->msgs) free(f->msgs);
if (f->battles) free(f->battles);
#endif
/* TODO: free msgs */
freestrlist(f->mistakes);
freelist(f->allies);

View File

@ -363,9 +363,6 @@
<File
RelativePath=".\region.c">
</File>
<File
RelativePath=".\render.c">
</File>
<File
RelativePath=".\reports.c">
</File>

View File

@ -1,565 +0,0 @@
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2003
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* based on:
*
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
* Atlantis v1.7 Copyright 1996 by Alex Schröder
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
* This program may not be sold or used commercially without prior written
* permission from the authors.
*/
#include <config.h>
#include "eressea.h"
#include "render.h"
#include "message.h"
#ifdef OLD_MESSAGES
#include "item.h"
#include "faction.h"
#include "language.h"
#include "goodies.h"
#include "region.h"
#include "unit.h"
#include "building.h"
#include "ship.h"
#include "reports.h"
#include "karma.h"
#include "unit.h"
#include <assert.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#define RMAXHASH 64
int lastint = 0;
typedef struct localizer {
struct localizer * nexthash;
unsigned int hashkey;
const locale * lang;
struct renderer * renderers[RMAXHASH];
struct eval * evaluators[RMAXHASH];
} localizer;
typedef const char* (*eval_fun)(const locale * lang, void *);
typedef char * (*render_fun)(const message * m, const locale * lang);
typedef struct renderer {
unsigned int hashkey;
render_fun fun;
char * name;
struct renderer * nexthash;
} renderer;
typedef struct eval {
unsigned int hashkey;
eval_fun fun;
const char * name;
struct eval * nexthash;
} eval;
#define LMAXHASH 32
localizer * localizers[LMAXHASH];
static localizer *
get_localizer(const locale * lang)
{
unsigned int hkey = locale_hashkey(lang);
int id = hkey % LMAXHASH;
localizer * find = localizers[id];
while (find && find->lang!=lang) find = find->nexthash;
if (!find) {
find = calloc(sizeof(localizer), 1);
find->nexthash = localizers[id];
localizers[id] = find;
find->hashkey = hkey;
find->lang = lang;
}
return find;
}
void
add_renderfun(const char * name, localizer * l, render_fun fun)
{
unsigned int hkey = hashstring(name);
unsigned int id = hkey % RMAXHASH;
renderer * find = l->renderers[id];
while (find && find->hashkey!=hkey) find=find->nexthash;
if (!find) {
find = calloc(1, sizeof(renderer));
find->nexthash = l->renderers[id];
l->renderers[id] = find;
find->hashkey = hkey;
find->fun = fun;
find->name = strdup(name);
}
else assert(!strcmp(find->name, name));
}
void
add_evalfun(const char * name, localizer * l, eval_fun fun)
{
unsigned int hkey = hashstring(name);
unsigned int id = hkey % RMAXHASH;
eval * find = l->evaluators[id];
while (find && find->hashkey!=hkey) find=find->nexthash;
if (!find) {
find = calloc(1, sizeof(eval));
find->nexthash = l->evaluators[id];
l->evaluators[id] = find;
find->hashkey = hkey;
find->fun = fun;
find->name = strdup(name);
}
else assert(!strcmp(find->name, name));
}
void
render_cleanup(void)
{
int i;
for (i=0;i!=LMAXHASH;++i) {
while (localizers[i]) {
int s;
localizer * l = localizers[i]->nexthash;
#if 0
for (s=0;s!=SMAXHASH;++s) {
while (localizers[i]->strings[s]) {
struct locale_string * ls = localizers[i]->strings[s]->nexthash;
free(localizers[i]->strings[s]);
localizers[i]->strings[s]=ls;
}
}
#endif
for (s=0;s!=RMAXHASH;++s) {
while (localizers[i]->evaluators[s]) {
eval * e = localizers[i]->evaluators[s]->nexthash;
free(localizers[i]->evaluators[s]);
localizers[i]->evaluators[s] = e;
}
}
for (s=0;s!=RMAXHASH;++s) {
while (localizers[i]->renderers[s]) {
renderer * e = localizers[i]->renderers[s]->nexthash;
free(localizers[i]->renderers[s]);
localizers[i]->renderers[s] = e;
}
}
free(localizers[i]);
localizers[i] = l;
}
}
}
static const char *
v_order(const locale * l, void * data) {
return (const char *)data;
}
static const char *
v_unit(const locale * l, void * data) {
unit * u = (void*)data;
if (u) return unitname(u);
return locale_string(l, "unknownunit");
}
static const char *
v_of_de(const locale * l, void * data) {
int i = (int)data;
if (!i || i==INT_MAX || i==lastint) return "";
sprintf(buf, "von %d ", i);
return buf;
}
static const char *
v_sink_de(const locale * l, void * data) {
int i = (int)data;
unused(l);
return i?" und sank":"";
}
static const char *
v_mage_de(const locale * l, void * data) {
int i = (int)data;
unused(l);
/* TODO: i==1 getarnt, wilder Hack */
return i>1?unitname((unit*)i):"Jemand";
}
static const char *
v_unknown(const locale * l, void * data) {
unused(l);
unused(data);
/* TODO: i==1 getarnt, wilder Hack */
return "[an error occured]";
}
const char *
v_dir(const locale * l, void * data) {
int i = (int)data;
static const char* dres[6] = { "northwest", "northeast", "east",
"southeast", "southwest", "west" };
/* static char buffer[10]; */
return locale_string(l, dres[i]);
}
static char rbuf[8192];
static char *
render_immediate(const message * m, const char * find, localizer * l)
{
char * b = rbuf;
const char * p = find;
while (*p) {
while (*p && *p!='{') *b++ = *p++;
if (*p=='{') {
static char token[128];
static char function[128];
char * t = token;
char * f = function;
eval_fun fun = NULL;
const char * var = NULL;
int i = 0;
struct entry * e = m->type->entries;
++p;
if (*p=='$') {
unsigned int key;
eval * e;
++p;
while (*p!=' ') *f++ = *p++;
*f = 0;
key = hashstring(function);
for (e = l->evaluators[key % RMAXHASH];e;e=e->nexthash) {
if (!strcmp(e->name, function)) break;
}
if (e==NULL) {
/* in default gucken */
localizer * l = get_localizer(find_locale("de"));
for (e = l->evaluators[key % RMAXHASH];e;e=e->nexthash) {
if (!strcmp(e->name, function)) break;
}
if (!e) {
fun = v_unknown;
fprintf(stderr, "WARNING: unknown function for rendering %s\n", function);
}
else fun = e->fun;
}
else fun = e->fun;
++p;
}
while (*p!='}') {
*t++ = *p++;
}
*t = 0;
++p;
while (e && strcmp(e->name, token)) {
e = e->next;
++i;
}
if (fun) var = fun(l->lang, m->data[i]);
else if (e) switch (e->type) {
case IT_FACTION:
var = factionname((faction*)m->data[i]);
break;
case IT_UNIT:
/* TODO: Grammatik falsch. Groß/Kleinschreibung */
if (m->data[i] == (void *)&u_peasants) {
if (b == rbuf) {
var = "Die Bevölkerung";
} else {
var = "die Bevölkerung";
}
} else if(m->data[i] == NULL || m->data[i] == &u_unknown) {
if (b == rbuf) {
var = "Eine unerkannte Einheit";
} else {
var = "eine unerkannte Einheit";
}
} else {
var = unitname((unit*)m->data[i]);
}
break;
case IT_REGION:
if (m->data[i]) var = tregionid((region*)m->data[i], m->receiver);
else var="eine unbekannte Region";
break;
case IT_SHIP:
var = shipname((ship*)m->data[i]);
break;
case IT_BUILDING:
var = buildingname((building*)m->data[i]);
break;
case IT_RESOURCETYPE:
var = locale_string(l->lang, resourcename((const resource_type *)m->data[i], (lastint==1)?0:GR_PLURAL));
break;
case IT_RESOURCE:
var = resname((resource_t)m->data[i], lastint!=1);
break;
case IT_SKILL:
var = skillnames[(int)m->data[i]];
break;
case IT_INT:
sprintf(token, "%d", (int)m->data[i]);
var = token;
lastint = (int)m->data[i];
break;
case IT_STRING:
var = (char*)m->data[i];
break;
case IT_DIRECTION:
var = directions[(int)m->data[i]];
break;
case IT_FSPECIAL:
var = fspecials[(int)m->data[i]].name;
break;
} else {
assert(!"unknown token");
}
while (*var) *b++ = *var++;
}
}
*b = 0;
return rbuf;
}
void
rendercr(FILE * f, messagetype * mt, const locale * lang)
{
fprintf(f, "\"%s\";%u\n", locale_string(lang, mt->name), mt->hashkey);
}
static char *
render_default(const message * m, const locale * lang)
{
const char * str = locale_string(lang, m->type->name);
if (!str) {
fprintf(stderr, "WARNUNG: fehlende message %s\n", m->type->name);
return m->type->name;
}
else return render_immediate(m, str, get_localizer(lang));
}
static render_fun
get_renderfun(const char * name, const localizer * l)
{
unsigned int hkey = hashstring(name);
unsigned int id = hkey % RMAXHASH;
renderer * find = l->renderers[id];
while (find && find->hashkey!=hkey) find=find->nexthash;
if (find && !strcmp(find->name, name)) return find->fun;
return &render_default;
}
const char *
render(const message * m, const locale * lang)
{
localizer * loc = get_localizer(lang);
char * s;
render_fun f;
f = get_renderfun(m->type->name, loc);
s = f(m, lang);
return s;
}
static char *
render_income(const message * m, const locale * lang)
{
static const char * special[] = {"income_work","income_entertainment","income_tax","income_trade","income_tradetax", "income_steal", "income_magic"};
static const char * special2[] = {"income_work_reduced","income_entertainment_reduced","income_tax_reduced","income_trade","income_tradetax", "income_steal_reduced", "income_magic_reduced"};
int want=0, have=0, type = -1;
const char * key;
localizer * l = get_localizer(lang);
struct entry * e = m->type->entries;
const char * ls;
int i = 0;
if (!l) return render_default(m, lang);
while (e) {
switch(e->type) {
case IT_INT:
if (!strcmp(e->name, "amount")) have = (int)m->data[i];
else if (!strcmp(e->name, "wanted")) want = (int)m->data[i];
else if (!strcmp(e->name, "mode")) type = (int)m->data[i];
else assert(0);
break;
case IT_REGION:
case IT_UNIT:
/* part of the message, but safely ignored here */
break;
default:
assert(0);
}
++i;
e = e->next;
}
if (type<0) return render_default(m, lang);
if (want!=have) key = special2[type];
else key = special[type];
ls = locale_string(lang, key);
return render_immediate(m, ls, l);
}
static char *
de_render_casualties(const message * m, const locale * lang)
{
/*
* casualties;de;{unit} verlor {fallen} Personen, {alive} überlebten und {run} flohen nach {runto}.
*/
int i, fallen=0, alive=0, run=0;
region * runto = NULL;
unit * u = NULL;
char * sbuf;
struct entry * e = m->type->entries;
for(i=0;e;e=e->next, ++i) {
switch(e->type) {
case IT_INT:
if (!strcmp(e->name, "fallen")) fallen = (int)m->data[i];
else if (!strcmp(e->name, "run")) run = (int)m->data[i];
else if (!strcmp(e->name, "alive")) alive = (int)m->data[i];
else assert(0);
break;
case IT_REGION:
if (!strcmp(e->name, "runto")) runto = (region*)m->data[i];
else assert(0);
break;
case IT_UNIT:
if (!strcmp(e->name, "unit")) u = (unit*)m->data[i];
else assert(0);
break;
default:
assert(!"message format of 'casualties' is broken");
}
}
sbuf = rbuf;
if (fallen) {
sbuf = strcpy(sbuf, unitname(u)) + strlen(sbuf);
sbuf += sprintf(sbuf, " verlor %d Person%s", fallen, fallen==1?"":"en");
if (alive) sbuf += sprintf(sbuf, ", %d überlebt%s", alive, alive==1?"e":"en");
if (run) sbuf += sprintf(sbuf, " und %d floh%s nach %s", run, run==1?"":"en", tregionid(runto, m->receiver));
} else {
if (alive && run) {
sprintf(sbuf, "%d Person%s aus %s überlebt%s und %d floh%s nach %s",
alive, alive==1?"":"en",
unitname(u), alive==1?"e":"en",
run, run==1?"":"en",
tregionid(runto, m->receiver));
} else if (run) {
sprintf(sbuf, "%d Person%s aus %s floh%s nach %s",
run, run==1?"":"en", unitname(u), run==1?"":"en",
tregionid(runto, m->receiver));
}
}
strcat(sbuf, ".");
return rbuf;
}
static const char *
v_travel(const locale * l, void * data)
{
int i = (int)data;
unused(l);
switch(i) {
case 0: return "flieht";
case 1: return "reitet";
default: return "wandert";
}
}
static const char *
v_travelthru_de(const locale * l, void * data) {
char * c = (char*)data;
unused(l);
if (c && strlen(c)) sprintf(buf," Dabei wurde %s durchquert.", c);
else return "";
return buf;
}
void
render_init(void)
{
localizer * loc;
locale * lang = find_locale("de");
if (lang==NULL) lang = make_locale("de");
loc = get_localizer(lang);
add_renderfun("income", loc, render_income);
add_renderfun("casualties", loc, de_render_casualties);
add_evalfun("dir", loc, v_dir);
add_evalfun("dir", loc, v_dir);
add_evalfun("travel", loc, v_travel);
add_evalfun("unit", loc, v_unit);
add_evalfun("order", loc, v_order);
add_evalfun("of", loc, v_of_de);
add_evalfun("sink", loc, v_sink_de);
add_evalfun("mage", loc, v_mage_de);
add_evalfun("travelthru", loc, v_travelthru_de);
lang = find_locale("en");
if (lang==NULL) lang = make_locale("en");
loc = get_localizer(lang);
add_renderfun("income", loc, render_income);
}
void
read_messages(FILE * F, const struct locale * deflocale)
{
unused(deflocale);
while (fgets(buf, 8192, F)) {
char * b = buf;
char * name = b;
char * language;
struct locale * lang;
char * section = NULL;
int level = 0;
messagetype * mtype;
buf[strlen(buf)-1] = 0; /* \n weg */
if (buf[0]=='#' || buf[0]==0) continue;
while (*b && *b!=';') ++b;
if (!*b) continue;
*b++ = 0;
section = b;
while (*b && *b!=';' && *b!=':') ++b;
if (!strcmp(section, "none")) section=NULL;
if (*b==':') {
char * x;
*b++ = 0;
x = b;
while (*b && *b!=';') ++b;
*b++ = 0;
level=atoi(x);
} else {
level = 0;
*b++ = 0;
}
language = b;
while (*b && *b!=';') ++b;
*b++ = 0;
lang = find_locale(language);
if (!lang) lang = make_locale(language);
mtype = find_messagetype(name);
if (!mtype) mtype = new_messagetype(name, level, section);
else if (section && !mtype->section) {
mtype->section = mc_add(section);
mtype->level = level;
}
locale_setstring(lang, name, b);
}
}
#endif

View File

@ -2047,7 +2047,7 @@
</type>
<text locale="de">"$unit($unit) in $region($region) stellt fest, dass es hier $localize($amount,$locale("de")) $resource($herb,$amount) gibt."</text>
<text locale="fr">"$unit($unit) discovers that $localize($amount,$locale("en")) $resource($herb,$amount) grow in $region($region)."</text>
<text locale="en">"$unit($unit) discovers that $localize($amount,$locale("en")) $resource($herb,$amount) grow in $region($region)."</text>
<text locale="en">"$unit($unit) discovers that $localize($amount,$locale("fr")) $resource($herb,$amount) grow in $region($region)."</text>
</message>
<message name="destroy_partial" section="events">
<type>
@ -5692,5 +5692,55 @@
<text locale="fr">"The wormhole in $region($region) disappears."</text>
<text locale="en">"The wormhole in $region($region) disappears."</text>
</message>
<message name="battle::potionsave" section="battle">
<type>
<arg name="unit" type="unit"/>
</type>
<text locale="de">"$unit($unit) konnte durch einen Heiltrank überleben."</text>
<text locale="en">"$unit($unit) was saved by a haling potion."</text>
</message>
<message name="battle::tactics_lost" section="battle">
<type>
<arg name="unit" type="unit"/>
</type>
<text locale="de">"$unit($unit) konnte dem Gegner eine Falle stellen."</text>
<text locale="en">"$unit($unit) lured the enemy into an ambush."</text>
</message>
<message name="battle::tactics_won" section="battle">
<type>
<arg name="unit" type="unit"/>
</type>
<text locale="de">"$unit($unit) überrascht den Gegner."</text>
<text locale="en">"$unit($unit) surprises the enemies."</text>
</message>
<message name="battle::spell_failed" section="battle">
<type>
<arg name="unit" type="unit"/>
<arg name="spell" type="spell"/>
</type>
<text locale="de">"$unit($unit) versucht $spell($spell) zu zaubern, doch der Zauber schlägt fehl!"</text>
<text locale="en">"$unit($unit) tries to cast $spell($spell), but the spell fails!"</text>
</message>
<message name="battle::row_header" section="battle">
<type>
</type>
<text locale="de">"Der Kampf wurde abgebrochen, da alle Verteidiger flohen."</text>
<text locale="en">"The battle was aborted because all enemies escaped."</text>
</message>
<message name="battle::aborted" section="battle">
<type>
<arg name="row" type="int"/>
</type>
<text locale="de">"... in der $int($row) Kampflinie:"</text>
<text locale="en">"... in combat rank $int($row):"</text>
</message>
<message name="battle::out_of_range" section="battle">
<type>
<arg name="mage" type="unit"/>
<arg name="spell" type="spell"/>
</type>
<text locale="de">"$unit($mage) zaubert $spell($spell), aber niemand war in Reichweite."</text>
<text locale="en">"$unit($mage) casts $spell($spell), but nobody was in range."</text>
</message>
</messages>