Insekten bekommen Winterwarnung, obwohl es Sommer ist

calendar erweitert, so dass an keiner andren Stelle im Code mehr gerechnet werden muss.
This commit is contained in:
Enno Rehling 2005-06-05 13:34:08 +00:00
parent f33d400576
commit 12b2db11fa
9 changed files with 78 additions and 83 deletions

View File

@ -455,7 +455,7 @@ recruit(unit * u, struct order * ord, request ** recruitorders)
#endif
if (rc == new_race[RC_INSECT]) {
if (month_season[month(0)] == 0 && rterrain(r) != T_DESERT) {
if (get_gamedate(turn, 0)->season == 0 && rterrain(r) != T_DESERT) {
#ifdef INSECT_POTION
boolean usepotion = false;
unit *u2;
@ -2454,7 +2454,9 @@ breedtrees(region *r, unit *u, int raw)
{
int n, i, skill, planted = 0;
const item_type * itype;
int current_season = season(turn);
static int current_season = -1;
if (current_season<0) current_season = get_gamedate(turn, NULL)->season;
/* Bäume züchten geht nur im Frühling */
if (current_season != SEASON_SPRING){

View File

@ -41,6 +41,7 @@
#include <kernel/battle.h>
#include <kernel/border.h>
#include <kernel/building.h>
#include <kernel/calendar.h>
#include <kernel/faction.h>
#include <kernel/group.h>
#include <kernel/item.h>
@ -867,18 +868,19 @@ iron(region * r)
}
#endif /* NEW_RESOURCEGROWTH */
/* ------------------------------------------------------------- */
extern int season(int turn);
void
demographics(void)
{
region *r;
#if GROWING_TREES
int current_season = season(turn);
int last_weeks_season = season(turn-1);
static int last_weeks_season = -1;
static int current_season = -1;
if (current_season<0) {
current_season = get_gamedate(turn, NULL)->season;
last_weeks_season = get_gamedate(turn-1, NULL)->season;
}
#endif
for (r = regions; r; r = r->next) {

View File

@ -186,47 +186,20 @@ read_datenames(const char *filename)
return 0;
}
int
season(int turn)
{
int year,month;
int t = turn - FirstTurn();
year = t/(months_per_year * weeks_per_month) + 1;
month = (t - (year-1) * months_per_year * weeks_per_month)/weeks_per_month;
assert(month >= 0 && month < months_per_year);
return month_season[month];
}
static void
get_gamedate(int * year, int * month, int * week)
{
int weeks_per_year = months_per_year * weeks_per_month;
int t = turn - FirstTurn();
if (t<0) t = turn;
*week = t%weeks_per_month; /* 0 - weeks_per_month-1 */
*month = (t/weeks_per_month + first_month)%months_per_year; /* 0 - months_per_year-1 */
*year = t/(weeks_per_year) + 1;
}
static char *
gamedate_season(const struct locale * lang)
{
static char buf[256];
int year, month, week;
gamedate gd;
get_gamedate(&year, &month, &week);
get_gamedate(turn, &gd);
sprintf(buf, LOC(lang, "nr_calendar_season"),
LOC(lang, weeknames[week]),
LOC(lang, monthnames[month]),
year,
LOC(lang, weeknames[gd.week]),
LOC(lang, monthnames[gd.month]),
gd.year,
LOC(lang, agename),
LOC(lang, seasonnames[month_season[month]]));
LOC(lang, seasonnames[gd.season]));
return buf;
}
@ -235,13 +208,13 @@ static char *
gamedate2(const struct locale * lang)
{
static char buf[256];
int year, month, week;
gamedate gd;
get_gamedate(&year, &month, &week);
get_gamedate(turn, &gd);
sprintf(buf, "in %s des Monats %s im Jahre %d %s.",
LOC(lang, weeknames2[week]),
LOC(lang, monthnames[month]),
year,
LOC(lang, weeknames2[gd.week]),
LOC(lang, monthnames[gd.month]),
gd.year,
LOC(lang, agename));
return buf;
}
@ -250,10 +223,10 @@ static char *
gamedate_short(const struct locale * lang)
{
static char buf[256];
int year, month, week;
gamedate gd;
get_gamedate(&year, &month, &week);
sprintf(buf, "%d/%s/%d", week+1, LOC(lang, monthnames[month]), year);
get_gamedate(turn, &gd);
sprintf(buf, "%d/%s/%d", gd.week+1, LOC(lang, monthnames[gd.month]), gd.year);
return buf;
}
@ -2084,16 +2057,22 @@ report(FILE *F, faction * f, struct seen_region ** seen, const faction_list * ad
/* Insekten-Winter-Warnung */
if(f->race == new_race[RC_INSECT]) {
if(month_season[month(1)] == 0) {
static int thisseason = -1;
if (thisseason<0) thisseason = get_gamedate(turn+1, 0)->season;
if (thisseason == 0) {
strcpy(buf, "Es ist Winter, und Insekten können nur in Wüsten oder mit "
"Hilfe des Nestwärme-Tranks Personen rekrutieren.");
centre(F, buf, true);
rnl(F);
} else if(month_season[month(2)] == 0) {
strcpy(buf, "Es ist Spätherbst, und diese Woche ist die letzte vor dem "
"Winter, in der Insekten rekrutieren können.");
centre(F, buf, true);
rnl(F);
} else {
static int nextseason = -1;
if (nextseason<0) nextseason = get_gamedate(turn+2, 0)->season;
if (nextseason == 0) {
strcpy(buf, "Es ist Spätherbst, und diese Woche ist die letzte vor dem "
"Winter, in der Insekten rekrutieren können.");
centre(F, buf, true);
rnl(F);
}
}
}

View File

@ -13,3 +13,20 @@ int *month_season = NULL;
char *agename = NULL;
int seasons = 0;
gamedate *
get_gamedate(int turn, gamedate * gd)
{
static gamedate staticdate;
int weeks_per_year = months_per_year * weeks_per_month;
int t = turn - first_turn;
if (gd==NULL) gd = &staticdate;
if (t<0) t = turn;
gd->week = t%weeks_per_month; /* 0 - weeks_per_month-1 */
gd->month = (t/weeks_per_month + first_month)%months_per_year; /* 0 - months_per_year-1 */
gd->year = t/(weeks_per_year) + 1;
gd->season = month_season[gd->month];
return gd;
}

View File

@ -17,4 +17,13 @@ extern char **weeknames;
extern char **weeknames2;
extern int weeks_per_month;
typedef struct gamedate {
int year;
int season;
int month;
int week;
} gamedate;
extern gamedate * get_gamedate(int turn, gamedate * gd);
#endif

View File

@ -193,12 +193,6 @@ AllianceRestricted(void)
return value;
}
int
FirstTurn(void)
{
return first_turn;
}
int
LongHunger(const struct unit * u) {
static int value = -1;
@ -2414,7 +2408,7 @@ init_data(const char * filename)
l = read_xml(zText);
if (l) return l;
if (turn<FirstTurn()) turn = FirstTurn();
if (turn<first_turn) turn = first_turn;
return 0;
}
@ -3028,21 +3022,6 @@ add_income(unit * u, int type, int want, int qty)
u, u->region, type, want, qty));
}
int
month(int offset)
{
int t = turn + offset - FirstTurn();
int year, r, month;
if (t<0) t = turn;
year = t/(months_per_year * weeks_per_month) + 1;
r = t - (year-1) * months_per_year * weeks_per_month;
month = r/weeks_per_month;
return month;
}
void
reorder_owners(region * r)
{

View File

@ -1128,7 +1128,6 @@ extern struct message * movement_error(struct unit * u, const char * token, stru
extern boolean move_blocked(const struct unit * u, const struct region *src, const struct region *dest);
extern void add_income(struct unit * u, int type, int want, int qty);
extern int month(int offset);
extern const char * basepath(void);
extern const char * resourcepath(void);
extern void kernel_init(void);
@ -1175,7 +1174,6 @@ extern void set_param(struct param ** p, const char * name, const char * data);
extern const char* get_param(const struct param * p, const char * name);
extern boolean ExpensiveMigrants(void);
extern int FirstTurn(void);
extern int NMRTimeout(void);
extern int LongHunger(const struct unit * u);
extern boolean TradeDisabled(void);

View File

@ -26,6 +26,7 @@
#include "border.h"
#include "build.h"
#include "building.h"
#include "calendar.h"
#include "curse.h"
#include "faction.h"
#include "item.h"
@ -1515,9 +1516,16 @@ sail(unit * u, order * ord, boolean move_on_land, region_list **routep)
}
if (!flying_ship(sh)) {
static int stormyness = -1;
int stormchance;
if (stormyness==-1) {
int thismonth = get_gamedate(turn, 0)->month;
stormyness = storms[thismonth] * 5;
}
/* storms should be the first thing we do. */
int stormchance = storms[month(0)] * 5 / shipspeed(sh, u);
stormchance = stormyness / shipspeed(sh, u);
if (check_leuchtturm(next_point, NULL)) stormchance /= 3;
if (rand()%10000 < stormchance && current_point->terrain == T_OCEAN) {
@ -2223,8 +2231,9 @@ regain_orientation(region * r)
ship *sh;
curse *c;
unit *u, *cap;
static int thismonth = get_gamedate(turn, 0)->month;
for(sh = r->ships; sh; sh = sh->next) {
for (sh = r->ships; sh; sh = sh->next) {
c = get_curse(sh->attribs, C_DISORIENTATION, 0);
if(!c) continue;
@ -2237,7 +2246,7 @@ regain_orientation(region * r)
cap = shipowner(r, sh);
if(r->terrain != T_OCEAN || rand() % 10 >= storms[month(0)]) {
if (r->terrain != T_OCEAN || rand() % 10 >= storms[thismonth]) {
remove_curse(&sh->attribs, C_DISORIENTATION, 0);
ADDMSG(&cap->faction->msgs, msg_message("shipnoconf", "ship", sh));
continue;

View File

@ -37,7 +37,7 @@ extern const char *coasts[];
/* kann_finden speedups */
extern boolean kann_finden(struct faction * f1, struct faction * f2);
extern struct unit * can_find(struct faction *, struct faction *);
extern int season(int turn);
/* funktionen zum schreiben eines reports */
extern int read_datenames(const char *filename);
void sparagraph(struct strlist ** SP, const char *s, int indent, char mark);