forked from github/server
simplified the work() functions
splitting more functionality from process_orders into separate functions
This commit is contained in:
parent
422008c0e2
commit
7783077517
23 changed files with 169 additions and 185 deletions
|
@ -866,7 +866,7 @@ show_allies(FILE * F, const faction * f, const ally * sf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
static void
|
static void
|
||||||
show_enemies(FILE * F, const faction_list* flist)
|
show_enemies(FILE * F, const faction_list* flist)
|
||||||
{
|
{
|
||||||
|
@ -1137,7 +1137,7 @@ report_computer(const char * filename, report_context * ctx)
|
||||||
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
|
#ifdef ENEMIES
|
||||||
show_enemies(F, f->enemies);
|
show_enemies(F, f->enemies);
|
||||||
#endif
|
#endif
|
||||||
show_allies(F, f, f->allies);
|
show_allies(F, f, f->allies);
|
||||||
|
@ -1237,9 +1237,9 @@ report_computer(const char * filename, report_context * ctx)
|
||||||
if (sd->mode!=see_unit) fprintf(F, "\"%s\";visibility\n", visibility[sd->mode]);
|
if (sd->mode!=see_unit) fprintf(F, "\"%s\";visibility\n", visibility[sd->mode]);
|
||||||
|
|
||||||
{
|
{
|
||||||
unit * owner = region_owner(r);
|
faction * owner = region_owner(r);
|
||||||
if (owner) {
|
if (owner) {
|
||||||
fprintf(F, "%d;owner\n", owner->faction->no);
|
fprintf(F, "%d;owner\n", owner->no);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sd->mode == see_neighbour) {
|
if (sd->mode == see_neighbour) {
|
||||||
|
@ -1285,7 +1285,7 @@ report_computer(const char * filename, report_context * ctx)
|
||||||
fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION);
|
fprintf(F, "%d;Rekruten\n", rpeasants(r) / RECRUITFRACTION);
|
||||||
}
|
}
|
||||||
if (production(r)) {
|
if (production(r)) {
|
||||||
fprintf(F, "%d;Lohn\n", fwage(r, f, true));
|
fprintf(F, "%d;Lohn\n", wage(r, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (res) {
|
while (res) {
|
||||||
|
|
|
@ -2884,7 +2884,7 @@ expandwork(region * r)
|
||||||
/* n: verbleibende Einnahmen */
|
/* n: verbleibende Einnahmen */
|
||||||
/* m: maximale Arbeiter */
|
/* m: maximale Arbeiter */
|
||||||
int m = maxworkingpeasants(r);
|
int m = maxworkingpeasants(r);
|
||||||
int p_wage = wage(r,NULL,false);
|
int p_wage = wage(r, NULL, NULL);
|
||||||
int verdienst = 0;
|
int verdienst = 0;
|
||||||
request *o;
|
request *o;
|
||||||
|
|
||||||
|
@ -2902,7 +2902,7 @@ expandwork(region * r)
|
||||||
|
|
||||||
assert(workers>=0);
|
assert(workers>=0);
|
||||||
|
|
||||||
u->n = workers * wage(u->region, u, false);
|
u->n = workers * wage(u->region, u->faction, u->race);
|
||||||
|
|
||||||
m -= workers;
|
m -= workers;
|
||||||
assert(m>=0);
|
assert(m>=0);
|
||||||
|
@ -2954,7 +2954,7 @@ work(unit * u, order * ord)
|
||||||
cmistake(u, ord, 69, MSG_INCOME);
|
cmistake(u, ord, 69, MSG_INCOME);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
w = wage(r,u,false);
|
w = wage(r, u->faction, u->race);
|
||||||
u->wants = u->number * w;
|
u->wants = u->number * w;
|
||||||
o = nextworker++;
|
o = nextworker++;
|
||||||
o->unit = u;
|
o->unit = u;
|
||||||
|
|
|
@ -2764,7 +2764,7 @@ instant_orders(void)
|
||||||
/* Beachten: einige Monster sollen auch unbewaffent die Region bewachen
|
/* Beachten: einige Monster sollen auch unbewaffent die Region bewachen
|
||||||
* können */
|
* können */
|
||||||
void
|
void
|
||||||
remove_unequipped_guarded(void)
|
update_guards(void)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
unit *u;
|
unit *u;
|
||||||
|
@ -3038,7 +3038,7 @@ evict(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
static void
|
static void
|
||||||
declare_war(void)
|
declare_war(void)
|
||||||
{
|
{
|
||||||
|
@ -4037,7 +4037,7 @@ processorders (void)
|
||||||
#ifdef ALLIANCEJOIN
|
#ifdef ALLIANCEJOIN
|
||||||
alliancejoin();
|
alliancejoin();
|
||||||
#endif
|
#endif
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
puts(" - Krieg & Frieden");
|
puts(" - Krieg & Frieden");
|
||||||
declare_war();
|
declare_war();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,7 +32,7 @@ void demographics(void);
|
||||||
void last_orders(void);
|
void last_orders(void);
|
||||||
void stripunit(struct unit * u);
|
void stripunit(struct unit * u);
|
||||||
void find_address(void);
|
void find_address(void);
|
||||||
void remove_unequipped_guarded(void);
|
void update_guards(void);
|
||||||
|
|
||||||
/* eressea-specific. put somewhere else, please. */
|
/* eressea-specific. put somewhere else, please. */
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
|
|
|
@ -1126,10 +1126,10 @@ describe(FILE * F, const region * r, int partial, faction * f)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const unit * u = region_owner(r);
|
const faction * owner = region_owner(r);
|
||||||
if (u) {
|
if (owner!=NULL) {
|
||||||
bufp += strxcpy(bufp, " Die Region ist im Besitz von ");
|
bufp += strxcpy(bufp, " Die Region ist im Besitz von ");
|
||||||
bufp += strxcpy(bufp, factionname(u->faction));
|
bufp += strxcpy(bufp, factionname(owner));
|
||||||
strcpy(bufp++, ".");
|
strcpy(bufp++, ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1290,7 +1290,7 @@ statistics(FILE * F, const region * r, const faction * f)
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
}
|
}
|
||||||
if (production(r) && (!fval(r->terrain, SEA_REGION) || f->race == new_race[RC_AQUARIAN])) {
|
if (production(r) && (!fval(r->terrain, SEA_REGION) || f->race == new_race[RC_AQUARIAN])) {
|
||||||
m = msg_message("nr_stat_salary", "max", fwage(r, f, true));
|
m = msg_message("nr_stat_salary", "max", wage(r, f, f->race));
|
||||||
nr_render(m, f->locale, buf, sizeof(buf), f);
|
nr_render(m, f->locale, buf, sizeof(buf), f);
|
||||||
rps(F, buf);
|
rps(F, buf);
|
||||||
msg_release(m);
|
msg_release(m);
|
||||||
|
@ -1470,7 +1470,7 @@ report_template(const char * filename, report_context * ctx)
|
||||||
}
|
}
|
||||||
rps_nowrap(F, buf);
|
rps_nowrap(F, buf);
|
||||||
rnl(F);
|
rnl(F);
|
||||||
sprintf(buf,"; ECheck Lohn %d", fwage(r,f,true));
|
sprintf(buf,"; ECheck Lohn %d", wage(r, f, f->race));
|
||||||
rps_nowrap(F, buf);
|
rps_nowrap(F, buf);
|
||||||
rnl(F);
|
rnl(F);
|
||||||
rps_nowrap(F, "");
|
rps_nowrap(F, "");
|
||||||
|
@ -1655,7 +1655,7 @@ allies(FILE * F, const faction * f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
static void
|
static void
|
||||||
enemies(FILE * F, const faction * f)
|
enemies(FILE * F, const faction * f)
|
||||||
{
|
{
|
||||||
|
@ -2150,7 +2150,7 @@ report_plaintext(const char * filename, report_context * ctx)
|
||||||
centre(F, LOC(f->locale, "nr_alliances"), false);
|
centre(F, LOC(f->locale, "nr_alliances"), false);
|
||||||
rnl(F);
|
rnl(F);
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
enemies(F, f);
|
enemies(F, f);
|
||||||
#endif
|
#endif
|
||||||
allies(F, f);
|
allies(F, f);
|
||||||
|
|
|
@ -2784,7 +2784,7 @@ plagues(region * r, boolean ismagic)
|
||||||
/* Seuchenwahrscheinlichkeit in % */
|
/* Seuchenwahrscheinlichkeit in % */
|
||||||
|
|
||||||
prob = pow((double) rpeasants(r) /
|
prob = pow((double) rpeasants(r) /
|
||||||
(mwp * (((double)wage(r,NULL,false)) / 10.0) * 1.3), 4.0)
|
(mwp * (((double)wage(r, NULL, NULL)) / 10.0) * 1.3), 4.0)
|
||||||
* (double) SEUCHE;
|
* (double) SEUCHE;
|
||||||
|
|
||||||
if (rand() % 100 >= (int)prob && !ismagic) return;
|
if (rand() % 100 >= (int)prob && !ismagic) return;
|
||||||
|
@ -2823,43 +2823,46 @@ static const int wagetable[7][4] = {
|
||||||
{15, 13, 16, 2} /* Zitadelle */
|
{15, 13, 16, 2} /* Zitadelle */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Gibt Arbeitslohn für entsprechende Rasse zurück, oder für
|
||||||
|
* die Bauern wenn f == NULL. */
|
||||||
int
|
int
|
||||||
wage(const region *r, const unit *u, boolean img)
|
wage(const region *r, const faction * f, const race * rc)
|
||||||
/* Gibt Arbeitslohn für entsprechende Rasse zurück, oder für
|
|
||||||
* die Bauern wenn ra == NORACE. */
|
|
||||||
{
|
{
|
||||||
building *b = largestbuilding(r, img);
|
building *b = largestbuilding(r, false);
|
||||||
int esize = 0;
|
int esize = 0;
|
||||||
curse * c;
|
curse * c;
|
||||||
int wage;
|
int wage;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
const building_type *artsculpture_type = bt_find("artsculpture");
|
const building_type *artsculpture_type = bt_find("artsculpture");
|
||||||
static const curse_type * drought_ct, * blessedharvest_ct;
|
static const curse_type * drought_ct, * blessedharvest_ct;
|
||||||
static boolean init;
|
static boolean init;
|
||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init = true;
|
init = true;
|
||||||
drought_ct = ct_find("drought");
|
drought_ct = ct_find("drought");
|
||||||
blessedharvest_ct = ct_find("blessedharvest");
|
blessedharvest_ct = ct_find("blessedharvest");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b) esize = buildingeffsize(b, img);
|
if (b!=NULL) {
|
||||||
|
/* TODO: this reveals imaginary castles */
|
||||||
|
esize = buildingeffsize(b, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (u) {
|
if (f!=NULL) {
|
||||||
wage = wagetable[esize][u->race == new_race[RC_ORC] || u->race == new_race[RC_SNOTLING] || u->race == new_race[RC_URUK]];
|
wage = wagetable[esize][rc == new_race[RC_ORC]];
|
||||||
if (fspecial(u->faction, FS_URBAN)) {
|
if (fspecial(f, FS_URBAN)) {
|
||||||
wage += wagetable[esize][3];
|
wage += wagetable[esize][3];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fval(r->terrain, SEA_REGION)) {
|
if (fval(r->terrain, SEA_REGION)) {
|
||||||
wage = 11;
|
wage = 11;
|
||||||
} else if (fval(r, RF_ORCIFIED)) {
|
} else if (fval(r, RF_ORCIFIED)) {
|
||||||
wage = wagetable[esize][1];
|
wage = wagetable[esize][1];
|
||||||
} else {
|
} else {
|
||||||
wage = wagetable[esize][2];
|
wage = wagetable[esize][2];
|
||||||
}
|
}
|
||||||
wage += curse_geteffect(get_curse(r->attribs, blessedharvest_ct));
|
wage += curse_geteffect(get_curse(r->attribs, blessedharvest_ct));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Artsculpture: Income +5 */
|
/* Artsculpture: Income +5 */
|
||||||
for(b=r->buildings; b; b=b->next) {
|
for(b=r->buildings; b; b=b->next) {
|
||||||
|
@ -2868,63 +2871,21 @@ wage(const region *r, const unit *u, boolean img)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Godcurse: Income -10 */
|
/* Godcurse: Income -10 */
|
||||||
if (curse_active(get_curse(r->attribs, ct_find("godcursezone")))) {
|
if (curse_active(get_curse(r->attribs, ct_find("godcursezone")))) {
|
||||||
wage = max(0,wage-10);
|
wage = max(0,wage-10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bei einer Dürre verdient man nur noch ein Viertel */
|
/* Bei einer Dürre verdient man nur noch ein Viertel */
|
||||||
if (drought_ct) {
|
if (drought_ct) {
|
||||||
c = get_curse(r->attribs, drought_ct);
|
c = get_curse(r->attribs, drought_ct);
|
||||||
if (curse_active(c)) wage /= curse_geteffect(c);
|
if (curse_active(c)) wage /= curse_geteffect(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
a = a_find(r->attribs, &at_reduceproduction);
|
a = a_find(r->attribs, &at_reduceproduction);
|
||||||
if (a) wage = (wage * a->data.sa[0])/100;
|
if (a) wage = (wage * a->data.sa[0])/100;
|
||||||
|
|
||||||
return wage;
|
return wage;
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
fwage(const region *r, const faction *f, boolean img)
|
|
||||||
{
|
|
||||||
building *b = largestbuilding(r, img);
|
|
||||||
int esize = 0;
|
|
||||||
int wage;
|
|
||||||
attrib *a;
|
|
||||||
curse * c;
|
|
||||||
|
|
||||||
if (b) esize = buildingeffsize(b, img);
|
|
||||||
|
|
||||||
if (f) {
|
|
||||||
wage = wagetable[esize][f->race == new_race[RC_ORC]];
|
|
||||||
if (fspecial(f, FS_URBAN)) {
|
|
||||||
wage += wagetable[esize][3];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (fval(r->terrain, SEA_REGION)) {
|
|
||||||
wage = 11;
|
|
||||||
} else if (fval(r, RF_ORCIFIED)) {
|
|
||||||
wage = wagetable[esize][1];
|
|
||||||
} else {
|
|
||||||
wage = wagetable[esize][2];
|
|
||||||
}
|
|
||||||
wage += curse_geteffect(get_curse(r->attribs, ct_find("blessedharvest")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Godcurse: Income -10 */
|
|
||||||
if (curse_active(get_curse(r->attribs, ct_find("godcursezone")))) {
|
|
||||||
wage = max(0,wage-10);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Bei einer Dürre verdient man nur noch ein Viertel */
|
|
||||||
c = get_curse(r->attribs, ct_find("drought"));
|
|
||||||
if (curse_active(c)) wage /= curse_geteffect(c);
|
|
||||||
|
|
||||||
a = a_find(r->attribs, &at_reduceproduction);
|
|
||||||
if (a) wage = (wage * a->data.sa[0])/100;
|
|
||||||
|
|
||||||
return wage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static region *
|
static region *
|
||||||
|
|
|
@ -181,8 +181,8 @@ struct building_type;
|
||||||
#define REGIONOWNERS_VERSION 400
|
#define REGIONOWNERS_VERSION 400
|
||||||
#define UGROUPS_VERSION 500 /* nicht aktivieren, nicht fertig */
|
#define UGROUPS_VERSION 500 /* nicht aktivieren, nicht fertig */
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
# define RELEASE_VERSION REGIONOWNERS_VERSION
|
# define RELEASE_VERSION ENEMIES_VERSION
|
||||||
#else
|
#else
|
||||||
# define RELEASE_VERSION TERRAIN_VERSION
|
# define RELEASE_VERSION TERRAIN_VERSION
|
||||||
#endif
|
#endif
|
||||||
|
@ -1121,8 +1121,7 @@ extern int lifestyle(const struct unit*);
|
||||||
extern int besieged(const struct unit * u);
|
extern int besieged(const struct unit * u);
|
||||||
extern int maxworkingpeasants(const struct region * r);
|
extern int maxworkingpeasants(const struct region * r);
|
||||||
|
|
||||||
extern int wage(const struct region *r, const struct unit *u, boolean img);
|
extern int wage(const struct region *r, const struct faction *f, const struct race * rc);
|
||||||
extern int fwage(const struct region *r, const struct faction *f, boolean img);
|
|
||||||
extern int movewhere(const struct unit *u, const char * token, struct region * r, struct region** resultp);
|
extern int movewhere(const struct unit *u, const char * token, struct region * r, struct region** resultp);
|
||||||
extern struct message * movement_error(struct unit * u, const char * token, struct order * ord, int error_code);
|
extern struct message * movement_error(struct unit * u, const char * token, struct order * ord, int error_code);
|
||||||
extern boolean move_blocked(const struct unit * u, const struct region *src, const struct region *dest);
|
extern boolean move_blocked(const struct unit * u, const struct region *src, const struct region *dest);
|
||||||
|
@ -1159,6 +1158,7 @@ typedef struct settings {
|
||||||
boolean disabled[MAXKEYWORDS];
|
boolean disabled[MAXKEYWORDS];
|
||||||
struct param * parameters;
|
struct param * parameters;
|
||||||
void * vm_state;
|
void * vm_state;
|
||||||
|
|
||||||
} settings;
|
} settings;
|
||||||
extern settings global;
|
extern settings global;
|
||||||
|
|
||||||
|
|
|
@ -314,7 +314,7 @@ update_interval(struct faction * f, struct region * r)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
boolean
|
boolean
|
||||||
is_enemy(const struct faction * f, const struct faction * enemy)
|
is_enemy(const struct faction * f, const struct faction * enemy)
|
||||||
{
|
{
|
||||||
|
|
|
@ -95,7 +95,7 @@ typedef struct faction {
|
||||||
struct unit * units;
|
struct unit * units;
|
||||||
struct attrib *attribs;
|
struct attrib *attribs;
|
||||||
struct message_list * msgs;
|
struct message_list * msgs;
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
struct faction_list * enemies;
|
struct faction_list * enemies;
|
||||||
#endif
|
#endif
|
||||||
struct bmsg {
|
struct bmsg {
|
||||||
|
@ -124,7 +124,7 @@ extern void destroyfaction(faction * f);
|
||||||
extern void set_alliance(struct faction * a, struct faction * b, int status);
|
extern void set_alliance(struct faction * a, struct faction * b, int status);
|
||||||
extern int get_alliance(const struct faction * a, const struct faction * b);
|
extern int get_alliance(const struct faction * a, const struct faction * b);
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
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, struct faction * enemy);
|
extern void remove_enemy(struct faction * f, struct faction * enemy);
|
||||||
|
|
|
@ -191,13 +191,16 @@ static boolean
|
||||||
entrance_allowed(const struct unit * u, const struct region * r)
|
entrance_allowed(const struct unit * u, const struct region * r)
|
||||||
{
|
{
|
||||||
#ifdef REGIONOWNERS
|
#ifdef REGIONOWNERS
|
||||||
unit * owner = region_owner(r);
|
faction * owner = region_owner(r);
|
||||||
if (owner == NULL || u->faction == owner->faction) return true;
|
if (owner == NULL || u->faction == owner) return true;
|
||||||
if (alliedunit(owner, u->faction, HELP_TRAVEL)) return true;
|
if (alliedfaction(r->planep, owner, u->faction, HELP_TRAVEL)) return true;
|
||||||
if (is_enemy(u->faction, owner->faction)) return true;
|
#ifdef ENEMIES
|
||||||
return false;
|
if (is_enemy(u->faction, owner)) return true;
|
||||||
#endif
|
#endif
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -1002,7 +1002,7 @@ terraform_region(region * r, const terrain_type * terrain)
|
||||||
peasants = MAXPEASANTS_PER_AREA * (rand() % (terrain->size / MAXPEASANTS_PER_AREA / 2));
|
peasants = MAXPEASANTS_PER_AREA * (rand() % (terrain->size / MAXPEASANTS_PER_AREA / 2));
|
||||||
#endif
|
#endif
|
||||||
rsetpeasants(r, max(100, peasants));
|
rsetpeasants(r, max(100, peasants));
|
||||||
rsetmoney(r, rpeasants(r) * ((wage(r, NULL, false)+1) + rand() % 5));
|
rsetmoney(r, rpeasants(r) * ((wage(r, NULL, NULL)+1) + rand() % 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1079,24 +1079,22 @@ r_addmessage(struct region * r, const struct faction * viewer, struct message *
|
||||||
return add_message(&imsg->msgs, msg);
|
return add_message(&imsg->msgs, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct unit *
|
struct faction *
|
||||||
region_owner(const struct region * r)
|
region_owner(const struct region * r)
|
||||||
{
|
{
|
||||||
#ifdef REGIONOWNERS
|
#ifdef REGIONOWNERS
|
||||||
struct unit * owner = NULL;
|
return r->owner;
|
||||||
int maxsize = 0;
|
|
||||||
building * b = r->buildings;
|
|
||||||
for (;b!=NULL;b=b->next) {
|
|
||||||
if (b->size>maxsize) {
|
|
||||||
struct unit * u = buildingowner(r, b);
|
|
||||||
if (u) {
|
|
||||||
owner = u;
|
|
||||||
maxsize=b->size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return owner;
|
|
||||||
#else
|
#else
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
region_setowner(struct region * r, struct faction * owner)
|
||||||
|
{
|
||||||
|
#ifdef REGIONOWNERS
|
||||||
|
r->owner = owner;
|
||||||
|
#else
|
||||||
|
unused(r, owner);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -106,6 +106,9 @@ typedef struct region {
|
||||||
struct donation * donations;
|
struct donation * donations;
|
||||||
const struct terrain_type * terrain;
|
const struct terrain_type * terrain;
|
||||||
struct rawmaterial * resources;
|
struct rawmaterial * resources;
|
||||||
|
#ifdef REGIONOWNERS
|
||||||
|
struct faction * owner;
|
||||||
|
#endif
|
||||||
#ifdef FAST_CONNECT
|
#ifdef FAST_CONNECT
|
||||||
struct region * connect[MAXDIRECTIONS];
|
struct region * connect[MAXDIRECTIONS];
|
||||||
#endif
|
#endif
|
||||||
|
@ -232,7 +235,9 @@ extern int production(const struct region *r);
|
||||||
extern int read_region_reference(struct region ** r, FILE * F);
|
extern int read_region_reference(struct region ** r, FILE * F);
|
||||||
extern void write_region_reference(const struct region * r, FILE * F);
|
extern void write_region_reference(const struct region * r, FILE * F);
|
||||||
|
|
||||||
extern struct unit * region_owner(const struct region * r);
|
void region_setowner(struct region * r, struct faction * owner);
|
||||||
|
extern struct faction * region_owner(const struct region * r);
|
||||||
|
|
||||||
extern struct region * r_connect(const struct region *, direction_t dir);
|
extern struct region * r_connect(const struct region *, direction_t dir);
|
||||||
#ifdef FAST_CONNECT
|
#ifdef FAST_CONNECT
|
||||||
# define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, dir))
|
# define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, dir))
|
||||||
|
|
|
@ -425,11 +425,11 @@ getbuf(FILE * F)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
static void
|
static void
|
||||||
read_enemies(FILE * F, faction * f)
|
read_enemies(FILE * F, faction * f)
|
||||||
{
|
{
|
||||||
if (global.data_version<REGIONOWNERS_VERSION) return;
|
if (global.data_version<ENEMIES_VERSION) return;
|
||||||
f->enemies = NULL;
|
f->enemies = NULL;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char zText[32];
|
char zText[32];
|
||||||
|
@ -448,12 +448,10 @@ read_enemies(FILE * F, faction * f)
|
||||||
static void
|
static void
|
||||||
write_enemies(FILE * F, const faction_list * flist)
|
write_enemies(FILE * F, const faction_list * flist)
|
||||||
{
|
{
|
||||||
#if RELEASE_VERSION>=REGIONOWNERS_VERSION
|
|
||||||
while (flist) {
|
while (flist) {
|
||||||
fprintf(F, "%s ", itoa36(flist->data->no));
|
fprintf(F, "%s ", itoa36(flist->data->no));
|
||||||
}
|
}
|
||||||
fputs("end \n", F);
|
fputs("end \n", F);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1666,7 +1664,7 @@ readfaction(FILE * F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
read_groups(F, f);
|
read_groups(F, f);
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
read_enemies(F, f);
|
read_enemies(F, f);
|
||||||
#endif
|
#endif
|
||||||
return f;
|
return f;
|
||||||
|
@ -1731,7 +1729,7 @@ writefaction(FILE * F, const faction * f)
|
||||||
fprintf(F, "end ");
|
fprintf(F, "end ");
|
||||||
wnl(F);
|
wnl(F);
|
||||||
write_groups(F, f->groups);
|
write_groups(F, f->groups);
|
||||||
#ifdef REGIONOWNERS
|
#ifdef ENEMIES
|
||||||
write_enemies(F, f->enemies);
|
write_enemies(F, f->enemies);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "eressea.h"
|
#include "eressea.h"
|
||||||
#ifdef SCORE_MODULE
|
#ifdef SCORE_MODULE
|
||||||
|
#include "score.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
#include <kernel/alliance.h>
|
#include <kernel/alliance.h>
|
||||||
|
|
|
@ -220,7 +220,7 @@ extern char * strdup(const char *s);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define unused(var) var = var
|
#define unused(var) (var)
|
||||||
|
|
||||||
|
|
||||||
/**** ****
|
/**** ****
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <attributes/key.h>
|
#include <attributes/key.h>
|
||||||
#include <modules/autoseed.h>
|
#include <modules/autoseed.h>
|
||||||
|
#include <modules/score.h>
|
||||||
|
|
||||||
// gamecode includes
|
// gamecode includes
|
||||||
#include <gamecode/laws.h>
|
#include <gamecode/laws.h>
|
||||||
|
@ -218,6 +219,40 @@ lua_equipunit(unit& u, const char * eqname)
|
||||||
equip_unit(&u, get_equipment(eqname));
|
equip_unit(&u, get_equipment(eqname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_subscriptions(void)
|
||||||
|
{
|
||||||
|
FILE * F;
|
||||||
|
char zText[MAX_PATH];
|
||||||
|
faction * f;
|
||||||
|
strcat(strcpy(zText, basepath()), "/subscriptions");
|
||||||
|
F = fopen(zText, "r");
|
||||||
|
if (F==NULL) {
|
||||||
|
log_info((0, "could not open %s.\n", zText));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (;;) {
|
||||||
|
char zFaction[5];
|
||||||
|
int subscription, fno;
|
||||||
|
if (fscanf(F, "%d %s", &subscription, zFaction)<=0) break;
|
||||||
|
fno = atoi36(zFaction);
|
||||||
|
f = findfaction(fno);
|
||||||
|
if (f!=NULL) {
|
||||||
|
f->subscription=subscription;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(F);
|
||||||
|
|
||||||
|
sprintf(zText, "subscriptions.%u", turn);
|
||||||
|
F = fopen(zText, "w");
|
||||||
|
for (f=factions;f!=NULL;f=f->next) {
|
||||||
|
fprintf(F, "%s:%u:%s:%s:%s:%u:\n",
|
||||||
|
itoa36(f->no), f->subscription, f->email, f->override,
|
||||||
|
dbrace(f->race), f->lastorders);
|
||||||
|
}
|
||||||
|
fclose(F);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lua_learnskill(unit& u, const char * skname, float chances)
|
lua_learnskill(unit& u, const char * skname, float chances)
|
||||||
{
|
{
|
||||||
|
@ -248,6 +283,10 @@ bind_eressea(lua_State * L)
|
||||||
def("get_turn", &get_turn),
|
def("get_turn", &get_turn),
|
||||||
def("remove_empty_units", &remove_empty_units),
|
def("remove_empty_units", &remove_empty_units),
|
||||||
|
|
||||||
|
def("update_subscriptions", &update_subscriptions),
|
||||||
|
def("update_guards", &update_guards),
|
||||||
|
def("update_scores", &score),
|
||||||
|
|
||||||
def("equip_unit", &lua_equipunit),
|
def("equip_unit", &lua_equipunit),
|
||||||
def("learn_skill", &lua_learnskill),
|
def("learn_skill", &lua_learnskill),
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
|
#include <kernel/faction.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
#include <kernel/plane.h>
|
#include <kernel/plane.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
|
@ -58,6 +59,16 @@ region_getname(const region& r) {
|
||||||
return r.terrain->_name;
|
return r.terrain->_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
lua_region_setowner(region& r, faction * f) {
|
||||||
|
region_setowner(&r, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static faction *
|
||||||
|
lua_region_getowner(const region& r) {
|
||||||
|
return region_owner(&r);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
region_setinfo(region& r, const char * info) {
|
region_setinfo(region& r, const char * info) {
|
||||||
set_string(&r.display, info);
|
set_string(&r.display, info);
|
||||||
|
@ -244,6 +255,7 @@ bind_region(lua_State * L)
|
||||||
.def(self == region())
|
.def(self == region())
|
||||||
.property("name", ®ion_getname, ®ion_setname)
|
.property("name", ®ion_getname, ®ion_setname)
|
||||||
.property("info", ®ion_getinfo, ®ion_setinfo)
|
.property("info", ®ion_getinfo, ®ion_setinfo)
|
||||||
|
.property("owner", &lua_region_getowner, &lua_region_setowner)
|
||||||
.property("terrain", ®ion_getterrain)
|
.property("terrain", ®ion_getterrain)
|
||||||
.def("add_notice", ®ion_addnotice)
|
.def("add_notice", ®ion_addnotice)
|
||||||
.def("add_direction", ®ion_adddirection)
|
.def("add_direction", ®ion_adddirection)
|
||||||
|
|
|
@ -268,7 +268,7 @@ processturn(char *filename)
|
||||||
autoseed(&players, k, true);
|
autoseed(&players, k, true);
|
||||||
}
|
}
|
||||||
score();
|
score();
|
||||||
remove_unequipped_guarded();
|
update_guards();
|
||||||
if (!noreports) reports();
|
if (!noreports) reports();
|
||||||
free_units();
|
free_units();
|
||||||
puts(" - Beseitige leere Parteien");
|
puts(" - Beseitige leere Parteien");
|
||||||
|
|
|
@ -37,7 +37,6 @@
|
||||||
#include <items/itemtypes.h>
|
#include <items/itemtypes.h>
|
||||||
|
|
||||||
/* modules includes */
|
/* modules includes */
|
||||||
#include <modules/score.h>
|
|
||||||
#include <modules/xmas.h>
|
#include <modules/xmas.h>
|
||||||
#include <modules/gmcmd.h>
|
#include <modules/gmcmd.h>
|
||||||
#include <modules/infocmd.h>
|
#include <modules/infocmd.h>
|
||||||
|
@ -324,40 +323,6 @@ lua_done(lua_State * luaState)
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
update_subscriptions(void)
|
|
||||||
{
|
|
||||||
FILE * F;
|
|
||||||
char zText[MAX_PATH];
|
|
||||||
faction * f;
|
|
||||||
strcat(strcpy(zText, basepath()), "/subscriptions");
|
|
||||||
F = fopen(zText, "r");
|
|
||||||
if (F==NULL) {
|
|
||||||
log_info((0, "could not open %s.\n", zText));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
char zFaction[5];
|
|
||||||
int subscription, fno;
|
|
||||||
if (fscanf(F, "%d %s", &subscription, zFaction)<=0) break;
|
|
||||||
fno = atoi36(zFaction);
|
|
||||||
f = findfaction(fno);
|
|
||||||
if (f!=NULL) {
|
|
||||||
f->subscription=subscription;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(F);
|
|
||||||
|
|
||||||
sprintf(zText, "subscriptions.%u", turn);
|
|
||||||
F = fopen(zText, "w");
|
|
||||||
for (f=factions;f!=NULL;f=f->next) {
|
|
||||||
fprintf(F, "%s:%u:%s:%s:%s:%u:\n",
|
|
||||||
itoa36(f->no), f->subscription, f->email, f->override,
|
|
||||||
dbrace(f->race), f->lastorders);
|
|
||||||
}
|
|
||||||
fclose(F);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
process_orders()
|
process_orders()
|
||||||
{
|
{
|
||||||
|
@ -369,10 +334,7 @@ process_orders()
|
||||||
#endif
|
#endif
|
||||||
turn++;
|
turn++;
|
||||||
processorders();
|
processorders();
|
||||||
score();
|
|
||||||
remove_unequipped_guarded();
|
|
||||||
|
|
||||||
update_subscriptions();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ end
|
||||||
function process(orders)
|
function process(orders)
|
||||||
-- initialize starting equipment for new players
|
-- initialize starting equipment for new players
|
||||||
equipment_setitem("new_faction", "conquesttoken", "1");
|
equipment_setitem("new_faction", "conquesttoken", "1");
|
||||||
equipment_setitem("new_faction", "wood", "30");
|
equipment_setitem("new_faction", "log", "30");
|
||||||
equipment_setitem("new_faction", "stone", "30");
|
equipment_setitem("new_faction", "stone", "30");
|
||||||
equipment_setitem("new_faction", "money", "4200");
|
equipment_setitem("new_faction", "money", "4200");
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,8 @@ function process(orders)
|
||||||
spawn_braineaters(0.25)
|
spawn_braineaters(0.25)
|
||||||
plan_monsters()
|
plan_monsters()
|
||||||
process_orders()
|
process_orders()
|
||||||
|
update_guards()
|
||||||
|
update_scores()
|
||||||
|
|
||||||
change_locales()
|
change_locales()
|
||||||
|
|
||||||
|
@ -99,6 +101,11 @@ function process(orders)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- demo: how to add a special familiars-constructor
|
||||||
|
function initfamiliar_lynx(u)
|
||||||
|
print("a lynx is born ;-)")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- main body of script
|
-- main body of script
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
function initfamiliar_lynx(u)
|
|
||||||
print("a lynx is born :-)")
|
|
||||||
end
|
|
||||||
|
|
||||||
function peasant_getresource(u)
|
function peasant_getresource(u)
|
||||||
return u.region:get_resource("peasant")
|
return u.region:get_resource("peasant")
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,8 @@ function process(orders)
|
||||||
-- (no more braineaters) spawn_braineaters(0.25)
|
-- (no more braineaters) spawn_braineaters(0.25)
|
||||||
plan_monsters()
|
plan_monsters()
|
||||||
process_orders()
|
process_orders()
|
||||||
outfile = "" .. get_turn()
|
update_guards()
|
||||||
|
update_scores()
|
||||||
|
|
||||||
-- write out the initial reports (no need to run a turn)
|
-- write out the initial reports (no need to run a turn)
|
||||||
write_passwords()
|
write_passwords()
|
||||||
|
@ -28,6 +29,7 @@ function process(orders)
|
||||||
write_standings()
|
write_standings()
|
||||||
|
|
||||||
-- save the game
|
-- save the game
|
||||||
|
outfile = "" .. get_turn()
|
||||||
if write_game(outfile)~=0 then
|
if write_game(outfile)~=0 then
|
||||||
print("could not write game")
|
print("could not write game")
|
||||||
return -1
|
return -1
|
||||||
|
|
Loading…
Reference in a new issue