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 <crmessage.h>
#include <nrmessage.h>
#include <base36.h>
#include <language.h>
/* 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 */
static void
@ -1039,6 +1052,9 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
for (i=0;i!=MAXOPTIONS;++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);
{
group * g;
@ -1101,6 +1117,7 @@ report_computer(FILE * F, faction * f, const seen_region * seen,
const char * tname;
unsigned char seemode = sd->mode;
const region * r = sd->r;
unit * owner = region_owner(r);
sd = sd->next;
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);
break;
}
if (owner) {
fprintf(F, "%d;owner\n", owner->faction->no);
}
if (seemode == see_neighbour) {
cr_borders(r, f, seemode, F);
} else {

View File

@ -2740,6 +2740,63 @@ evict(void)
}
#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
renumber(void)
{
@ -2749,7 +2806,7 @@ renumber(void)
unit * u;
int i;
for (r=regions;r;r=r->next) {
for (r=regions;r;r=r->next) {
for (u=r->units;u;u=u->next) {
faction * f = u->faction;
for (S = u->orders; S; S = S->next) if (igetkeyword(S->s, u->faction->locale)==K_NUMBER) {
@ -3520,6 +3577,10 @@ processorders (void)
#endif
#ifdef ALLIANCEJOIN
alliancejoin();
#endif
#ifdef REGIONOWNERS
puts(" - Krieg & Frieden");
declare_war();
#endif
puts(" - Neue Nummern");
renumber();

View File

@ -1279,7 +1279,16 @@ describe(FILE * F, const region * r, int partial, faction * f)
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);
if(a_do) {
scat(" ");
@ -1716,9 +1725,9 @@ show_allies(const faction * f, const ally * allies)
}
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->next) {
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
guards(FILE * F, const region * r, const faction * see)
{ /* die Partei see sieht dies; wegen
@ -1762,7 +1793,7 @@ guards(FILE * F, const region * r, const faction * see)
boolean tarned = false;
/* Bewachung */
for (u = r->units; u; u = u->next)
for (u = r->units; u; u = u->next) {
if (getguard(u)) {
faction *f = u->faction;
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) {
if (i!=0) {
if (i == nextguard-(tarned?0:1))
scat(" und ");
else
scat(", ");
}
if (i<nextguard) scat(factionname(guardians[i]));
if (i == nextguard-(tarned?0:1))
scat(" und ");
else
scat(", ");
}
if (i<nextguard) scat(factionname(guardians[i]));
else scat("unbekannten Einheiten");
}
else scat("unbekannten Einheiten");
}
scat(" bewacht.");
rnl(F);
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);
rnl(F);
#ifdef REGIONOWNERS
enemies(F, f);
#endif
allies(F, f);
rpline(F);
@ -2159,19 +2197,20 @@ report(FILE *F, faction * f, const faction_list * addresses,
guards(F, r, f);
durchreisende(F, r, f);
}
else if (sd->mode==see_far) {
describe(F, r, 3, f);
guards(F, r, f);
durchreisende(F, r, f);
}
else if (turm_sieht_region) {
describe(F, r, 2, f);
durchreisende(F, r, f);
} else {
describe(F, r, 1, f);
durchreisende(F, r, f);
}
else {
if (sd->mode==see_far) {
describe(F, r, 3, f);
guards(F, r, f);
durchreisende(F, r, f);
}
else if (turm_sieht_region) {
describe(F, r, 2, f);
durchreisende(F, r, f);
} else {
describe(F, r, 1, f);
durchreisende(F, r, f);
}
}
/* Statistik */
if (wants_stats && unit_in_region == 1)

View File

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

View File

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

View File

@ -300,8 +300,8 @@ is_enemy(const struct faction * f, const struct faction * enemy)
return false;
}
void
add_enemy(struct faction * f, struct faction * enemy)
static void
add_enemy_i(struct faction * f, struct faction * enemy)
{
if (!is_enemy(f, enemy)) {
struct faction_list * flist = malloc(sizeof(faction_list));
@ -312,7 +312,14 @@ add_enemy(struct faction * f, struct faction * enemy)
}
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;
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

View File

@ -92,7 +92,7 @@ extern void destroyfaction(faction * f);
#ifdef REGIONOWNERS
extern boolean is_enemy(const struct faction * f, const 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

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>
</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">
<type>
<arg name="unit" type="unit"></arg>

View File

@ -1839,6 +1839,14 @@
<string name="NUMMER">
<text locale="de">NUMMER</text>
</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">
<text locale="de">FOLGEN</text>
</string>