Fast vollständige Krieg/Frieden Implementation (Tarnung fehlt, Schiffe fehlen)

This commit is contained in:
Enno Rehling 2002-12-18 17:40:21 +00:00
parent c184a888a9
commit 5693ace211
9 changed files with 213 additions and 34 deletions

View File

@ -64,6 +64,7 @@
#include <goodies.h> #include <goodies.h>
#include <crmessage.h> #include <crmessage.h>
#include <nrmessage.h> #include <nrmessage.h>
#include <base36.h>
#include <language.h> #include <language.h>
/* libc includes */ /* libc includes */
@ -821,7 +822,19 @@ show_allies(FILE * F, const faction * f, const ally * sf)
} }
} }
} }
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
#ifdef REGIONOWNERS
static void
show_enemies(FILE * F, const faction_list* flist)
{
for (;flist!=NULL;flist=flist->next) {
if (flist->data) {
int fno = flist->data->no;
fprintf(F, "ENEMY %u\n%d;partei\n", fno);
}
}
}
#endif
/* prints all visible spells in a region */ /* prints all visible spells in a region */
static void static void
@ -1039,6 +1052,9 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
for (i=0;i!=MAXOPTIONS;++i) { for (i=0;i!=MAXOPTIONS;++i) {
fprintf(F, "%d;%s\n", (f->options&want(i))?1:0, options[i]); fprintf(F, "%d;%s\n", (f->options&want(i))?1:0, options[i]);
} }
#ifdef REGIONOWNERS
show_enemies(F, f->enemies);
#endif
show_allies(F, f, f->allies); show_allies(F, f, f->allies);
{ {
group * g; group * g;
@ -1101,6 +1117,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
const char * tname; const char * tname;
unsigned char seemode = sd->mode; unsigned char seemode = sd->mode;
const region * r = sd->r; const region * r = sd->r;
unit * owner = region_owner(r);
sd = sd->next; sd = sd->next;
if (!rplane(r)) fprintf(F, "REGION %d %d\n", region_x(r, f), region_y(r, f)); if (!rplane(r)) fprintf(F, "REGION %d %d\n", region_x(r, f), region_y(r, f));
@ -1132,6 +1149,9 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
fputs("\"travel\";visibility\n", F); fputs("\"travel\";visibility\n", F);
break; break;
} }
if (owner) {
fprintf(F, "%d;owner\n", owner->faction->no);
}
if (seemode == see_neighbour) { if (seemode == see_neighbour) {
cr_borders(r, f, seemode, F); cr_borders(r, f, seemode, F);
} else { } else {

View File

@ -2740,6 +2740,63 @@ evict(void)
} }
#endif #endif
#ifdef REGIONOWNERS
static void
declare_war(void)
{
region *r;
for (r=regions;r;r=r->next) {
unit * u;
for (u=r->units;u;u=u->next) {
strlist *S;
faction * f = u->faction;
for (S = u->orders; S; S = S->next) {
switch (igetkeyword(S->s, f->locale)) {
case K_WAR:
for (;;) {
const char * s = getstrtoken();
if (s[0]==0) break;
else {
faction * enemy = findfaction(atoi36(s));
if (enemy) {
if (!is_enemy(f, enemy)) {
add_enemy(f, enemy);
ADDMSG(&enemy->msgs, msg_message("war_notify", "enemy", f));
ADDMSG(&f->msgs, msg_message("war_confirm", "enemy", enemy));
}
} else {
ADDMSG(&f->msgs, msg_message("error66", "unit region command", u, r, S->s));
}
}
}
break;
case K_PEACE:
for (;;) {
const char * s = getstrtoken();
if (s[0]==0) break;
else {
faction * enemy = findfaction(atoi36(s));
if (enemy) {
if (is_enemy(f, enemy)) {
remove_enemy(f, enemy);
ADDMSG(&enemy->msgs, msg_message("peace_notify", "enemy", f));
ADDMSG(&f->msgs, msg_message("peace_confirm", "enemy", enemy));
}
} else {
ADDMSG(&f->msgs, msg_message("error66", "unit region command", u, r, S->s));
}
}
}
break;
default:
break;
}
}
}
}
}
#endif
static void static void
renumber(void) renumber(void)
{ {
@ -2749,7 +2806,7 @@ renumber(void)
unit * u; unit * u;
int i; int i;
for (r=regions;r;r=r->next) { for (r=regions;r;r=r->next) {
for (u=r->units;u;u=u->next) { for (u=r->units;u;u=u->next) {
faction * f = u->faction; faction * f = u->faction;
for (S = u->orders; S; S = S->next) if (igetkeyword(S->s, u->faction->locale)==K_NUMBER) { for (S = u->orders; S; S = S->next) if (igetkeyword(S->s, u->faction->locale)==K_NUMBER) {
@ -3520,6 +3577,10 @@ processorders (void)
#endif #endif
#ifdef ALLIANCEJOIN #ifdef ALLIANCEJOIN
alliancejoin(); alliancejoin();
#endif
#ifdef REGIONOWNERS
puts(" - Krieg & Frieden");
declare_war();
#endif #endif
puts(" - Neue Nummern"); puts(" - Neue Nummern");
renumber(); renumber();

View File

@ -1279,7 +1279,16 @@ describe(FILE * F, const region * r, int partial, faction * f)
scat("."); scat(".");
} }
if (!is_cursed(r->attribs, C_REGCONF, 0)) { {
const unit * u = region_owner(r);
if (u) {
scat(" Die Region ist im Besitz von ");
scat(factionname(u->faction));
scat(".");
}
}
if (!is_cursed(r->attribs, C_REGCONF, 0)) {
attrib *a_do = a_find(r->attribs, &at_overrideroads); attrib *a_do = a_find(r->attribs, &at_overrideroads);
if(a_do) { if(a_do) {
scat(" "); scat(" ");
@ -1716,9 +1725,9 @@ show_allies(const faction * f, const ally * allies)
} }
static void static void
allies(FILE * F, faction * f) allies(FILE * F, const faction * f)
{ {
group * g = f->groups; const group * g = f->groups;
if (f->allies) { if (f->allies) {
if (!f->allies->next) { if (!f->allies->next) {
strcpy(buf, "Wir helfen der Partei "); strcpy(buf, "Wir helfen der Partei ");
@ -1747,6 +1756,28 @@ allies(FILE * F, faction * f)
} }
} }
#ifdef REGIONOWNERS
static void
enemies(FILE * F, const faction * f)
{
faction_list * flist = f->enemies;
if (flist!=NULL) {
strcpy(buf, "Wir liegen im Krieg mit ");
for (;flist!=NULL;flist = flist->next) {
const faction * enemy = flist->data;
scat(factionname(enemy));
if (flist->next) {
scat(", ");
} else {
scat(".");
}
}
rparagraph(F, buf, 0, 0);
rnl(F);
}
}
#endif
static void static void
guards(FILE * F, const region * r, const faction * see) guards(FILE * F, const region * r, const faction * see)
{ /* die Partei see sieht dies; wegen { /* die Partei see sieht dies; wegen
@ -1762,7 +1793,7 @@ guards(FILE * F, const region * r, const faction * see)
boolean tarned = false; boolean tarned = false;
/* Bewachung */ /* Bewachung */
for (u = r->units; u; u = u->next) for (u = r->units; u; u = u->next) {
if (getguard(u)) { if (getguard(u)) {
faction *f = u->faction; faction *f = u->faction;
faction *fv = visible_faction(see, u); faction *fv = visible_faction(see, u);
@ -1780,21 +1811,25 @@ guards(FILE * F, const region * r, const faction * see)
} }
} }
} }
if (!nextguard && !tarned) return; }
strcpy(buf, "Die Region wird von ");
if (nextguard || tarned) {
strcpy(buf, "Die Region wird von ");
} else {
return;
}
for (i = 0; i!=nextguard+(tarned?1:0); ++i) { for (i = 0; i!=nextguard+(tarned?1:0); ++i) {
if (i!=0) { if (i!=0) {
if (i == nextguard-(tarned?0:1)) if (i == nextguard-(tarned?0:1))
scat(" und "); scat(" und ");
else else
scat(", "); scat(", ");
} }
if (i<nextguard) scat(factionname(guardians[i])); if (i<nextguard) scat(factionname(guardians[i]));
else scat("unbekannten Einheiten"); else scat("unbekannten Einheiten");
} }
scat(" bewacht."); scat(" bewacht.");
rnl(F); rnl(F);
rparagraph(F, buf, 0, 0); rparagraph(F, buf, 0, 0);
@ -2120,6 +2155,9 @@ report(FILE *F, faction * f, const faction_list * addresses,
centre(F, LOC(f->locale, "nr_alliances"), false); centre(F, LOC(f->locale, "nr_alliances"), false);
rnl(F); rnl(F);
#ifdef REGIONOWNERS
enemies(F, f);
#endif
allies(F, f); allies(F, f);
rpline(F); rpline(F);
@ -2159,19 +2197,20 @@ report(FILE *F, faction * f, const faction_list * addresses,
guards(F, r, f); guards(F, r, f);
durchreisende(F, r, f); durchreisende(F, r, f);
} }
else if (sd->mode==see_far) { else {
describe(F, r, 3, f); if (sd->mode==see_far) {
guards(F, r, f); describe(F, r, 3, f);
durchreisende(F, r, f); guards(F, r, f);
} durchreisende(F, r, f);
else if (turm_sieht_region) { }
describe(F, r, 2, f); else if (turm_sieht_region) {
durchreisende(F, r, f); describe(F, r, 2, f);
} else { durchreisende(F, r, f);
describe(F, r, 1, f); } else {
durchreisende(F, r, f); describe(F, r, 1, f);
} durchreisende(F, r, f);
}
}
/* Statistik */ /* Statistik */
if (wants_stats && unit_in_region == 1) if (wants_stats && unit_in_region == 1)

View File

@ -197,6 +197,8 @@ const char *keywords[MAXKEYWORDS] =
"ENDE", "ENDE",
"FAHREN", "FAHREN",
"NUMMER", "NUMMER",
"KRIEG",
"FRIEDEN",
"FOLGEN", "FOLGEN",
"FORSCHEN", "FORSCHEN",
"GIB", "GIB",

View File

@ -398,6 +398,8 @@ enum {
K_END, K_END,
K_DRIVE, K_DRIVE,
K_NUMBER, K_NUMBER,
K_WAR,
K_PEACE,
K_FOLLOW, K_FOLLOW,
K_RESEARCH, K_RESEARCH,
K_GIVE, K_GIVE,

View File

@ -300,8 +300,8 @@ is_enemy(const struct faction * f, const struct faction * enemy)
return false; return false;
} }
void static void
add_enemy(struct faction * f, struct faction * enemy) add_enemy_i(struct faction * f, struct faction * enemy)
{ {
if (!is_enemy(f, enemy)) { if (!is_enemy(f, enemy)) {
struct faction_list * flist = malloc(sizeof(faction_list)); struct faction_list * flist = malloc(sizeof(faction_list));
@ -312,7 +312,14 @@ add_enemy(struct faction * f, struct faction * enemy)
} }
void void
remove_enemy(struct faction * f, const struct faction * enemy) add_enemy(struct faction * f, struct faction * enemy)
{
add_enemy_i(f, enemy);
/* add_enemy_i(enemy, f); */
}
static void
remove_enemy_i(struct faction * f, const struct faction * enemy)
{ {
struct faction_list **pflist = &f->enemies; struct faction_list **pflist = &f->enemies;
while (*pflist!=NULL) { while (*pflist!=NULL) {
@ -325,4 +332,12 @@ remove_enemy(struct faction * f, const struct faction * enemy)
} }
} }
} }
void
remove_enemy(struct faction * f, struct faction * enemy)
{
remove_enemy_i(f, enemy);
/* remove_enemy_i(enemy, f); */
}
#endif #endif

View File

@ -92,7 +92,7 @@ extern void destroyfaction(faction * f);
#ifdef REGIONOWNERS #ifdef REGIONOWNERS
extern boolean is_enemy(const struct faction * f, const struct faction * enemy); extern boolean is_enemy(const struct faction * f, const struct faction * enemy);
extern void add_enemy(struct faction * f, struct faction * enemy); extern void add_enemy(struct faction * f, struct faction * enemy);
extern void remove_enemy(struct faction * f, const struct faction * enemy); extern void remove_enemy(struct faction * f, struct faction * enemy);
#endif #endif
#endif #endif

View File

@ -5402,6 +5402,38 @@
<text locale="de">"$unit($unit) konnte nicht von $region($region) nach $region($target) reisen, da der Besitzer der Region es verhinderte."</text> <text locale="de">"$unit($unit) konnte nicht von $region($region) nach $region($target) reisen, da der Besitzer der Region es verhinderte."</text>
</message> </message>
<message name="war_notify" section="events">
<type>
<arg name="enemy" type="faction"></arg>
</type>
<text locale="de">"$faction($faction) hat uns den Krieg erklärt."</text>
<text locale="en">"$faction($faction) has declared war on us."</text>
</message>
<message name="war_confirm" section="events">
<type>
<arg name="enemy" type="faction"></arg>
</type>
<text locale="de">"Wir haben $faction($faction) den Krieg erklärt."</text>
<text locale="en">"We declared war on $faction($faction)."</text>
</message>
<message name="peace_notify" section="events">
<type>
<arg name="enemy" type="faction"></arg>
</type>
<text locale="de">"$faction($faction) hat den Krieg mit uns beendet."</text>
<text locale="en">"$faction($faction) has declared peace with us."</text>
</message>
<message name="peace_confirm" section="events">
<type>
<arg name="enemy" type="faction"></arg>
</type>
<text locale="de">"Wir haben den Krieg mit $faction($faction) beendet."</text>
<text locale="en">"We declared peace with $faction($faction)."</text>
</message>
<message name="moveblockedbyguard" section="movement"> <message name="moveblockedbyguard" section="movement">
<type> <type>
<arg name="unit" type="unit"></arg> <arg name="unit" type="unit"></arg>

View File

@ -1839,6 +1839,14 @@
<string name="NUMMER"> <string name="NUMMER">
<text locale="de">NUMMER</text> <text locale="de">NUMMER</text>
</string> </string>
<string name="FRIEDEN">
<text locale="de">FRIEDEN</text>
<text locale="en">PEACE</text>
</string>
<string name="KRIEG">
<text locale="de">KRIEG</text>
<text locale="en">WAR</text>
</string>
<string name="FOLGEN"> <string name="FOLGEN">
<text locale="de">FOLGEN</text> <text locale="de">FOLGEN</text>
</string> </string>