Startbedingungen können per Skript gesetzt werden.

Kompletter benötigter Skript-Support für WdW-Aussetzung fertig und getestet.
This commit is contained in:
Enno Rehling 2003-12-14 19:17:59 +00:00
parent 99bc41219b
commit 1a8e1acf74
15 changed files with 123 additions and 61 deletions

View File

@ -2353,7 +2353,7 @@ faction_id_is_unused(int id)
return (boolean)(bsearch(&id, used_faction_ids, no_used_faction_ids, return (boolean)(bsearch(&id, used_faction_ids, no_used_faction_ids,
sizeof(int), _cmp_int) == NULL); sizeof(int), _cmp_int) == NULL);
#else #else
return true; return findfaction(id)==NULL;
#endif #endif
} }

View File

@ -193,15 +193,32 @@ set_show_item(faction *f, item_t i)
a->data.v = (void*)olditemtype[i]; a->data.v = (void*)olditemtype[i];
} }
#ifdef NEW_STARTEQUIPMENT
static item * equipment;
void add_equipment(const item_type * itype, int number)
{
if (itype!=NULL) i_change(&equipment, itype, number);
}
#endif
void void
give_starting_equipment(struct region *r, struct unit *u) give_starting_equipment(struct region *r, struct unit *u)
{ {
#ifdef NEW_STARTEQUIPMENT
item * itm = equipment;
while (itm!=NULL) {
i_add(&u->items, i_new(itm->type, itm->number));
itm=itm->next;
}
#else
const item_type * token = it_find("conquesttoken"); const item_type * token = it_find("conquesttoken");
if (token!=NULL) { if (token!=NULL) {
i_add(&u->items, i_new(token, 1)); i_add(&u->items, i_new(token, 1));
} }
set_item(u, I_WOOD, 30); set_item(u, I_WOOD, 30);
set_item(u, I_STONE, 30); set_item(u, I_STONE, 30);
set_money(u, 2000 + turn * 10);
#endif
switch(old_race(u->race)) { switch(old_race(u->race)) {
case RC_DWARF: case RC_DWARF:
@ -278,8 +295,6 @@ give_starting_equipment(struct region *r, struct unit *u)
rsethorses(r, 250+rand()%51+rand()%51); rsethorses(r, 250+rand()%51+rand()%51);
break; break;
} }
set_money(u, 2000 + turn * 10);
} }
int int

View File

@ -143,7 +143,6 @@ extern int rc_specialdamage(const race *, const race *, const struct weapon_type
#define BF_RES_BASH (1<<4) /* Halber Schaden durch BASH */ #define BF_RES_BASH (1<<4) /* Halber Schaden durch BASH */
#define BF_INV_NONMAGIC (1<<5) /* Immun gegen nichtmagischen Schaden */ #define BF_INV_NONMAGIC (1<<5) /* Immun gegen nichtmagischen Schaden */
extern void give_starting_equipment(struct region *r, struct unit *u);
extern int unit_old_max_hp(struct unit * u); extern int unit_old_max_hp(struct unit * u);
extern const char * racename(const struct locale *lang, const struct unit *u, const race * rc); extern const char * racename(const struct locale *lang, const struct unit *u, const race * rc);
@ -168,6 +167,11 @@ extern int read_race_reference(const struct race ** rp, FILE * F);
extern const char * raceprefix(const struct unit *u); extern const char * raceprefix(const struct unit *u);
#ifdef NEW_STARTEQUIPMENT
extern void add_equipment(const struct item_type * itype, int number);
#endif
extern void give_starting_equipment(struct region *r, struct unit *u);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -846,7 +846,7 @@ read_alliances(FILE * F)
#endif #endif
int int
readgame(boolean backup) readgame(const char * filename, boolean backup)
{ {
int i, n, p; int i, n, p;
faction *f, **fp; faction *f, **fp;
@ -857,7 +857,7 @@ readgame(boolean backup)
FILE * F; FILE * F;
int rmax = maxregions; int rmax = maxregions;
sprintf(buf, "%s/%d", datapath(), turn); sprintf(buf, "%s/%s", datapath(), filename);
if (backup) create_backup(buf); if (backup) create_backup(buf);
F = cfopen(buf, "r"); F = cfopen(buf, "r");
if (F==NULL) { if (F==NULL) {
@ -1304,7 +1304,7 @@ export_players(const char * path)
#endif #endif
void void
writegame(char *path, char quiet) writegame(const char *filename, char quiet)
{ {
int i,n; int i,n;
faction *f; faction *f;
@ -1325,7 +1325,8 @@ writegame(char *path, char quiet)
/* write_dynamictypes(); */ /* write_dynamictypes(); */
F = cfopen(path, "w"); sprintf(buf, "%s/%s", datapath(), filename);
F = cfopen(buf, "w");
if (F==NULL) if (F==NULL)
return; return;

View File

@ -36,8 +36,8 @@ double version(void);
FILE * cfopen(const char *filename, const char *mode); FILE * cfopen(const char *filename, const char *mode);
int readorders(const char *); int readorders(const char *);
int creategame(void); int creategame(void);
int readgame(boolean backup); extern int readgame(const char * filename, boolean backup);
void writegame(char *path, char quiet); void writegame(const char *filename, char quiet);
extern void rsf(FILE * F, char *s, size_t len); extern void rsf(FILE * F, char *s, size_t len);

View File

@ -49,5 +49,6 @@
#define AUTOALLIANCE (HELP_FIGHT) #define AUTOALLIANCE (HELP_FIGHT)
#define WDW_PHOENIX #define WDW_PHOENIX
#define NEW_STARTEQUIPMENT
#define MAILITPATH "/usr/sbin:$HOME/bin:/bin:/usr/bin:/usr/local/bin" #define MAILITPATH "/usr/sbin:$HOME/bin:/bin:/usr/bin:/usr/local/bin"

View File

@ -1,16 +1,27 @@
function process(orders) function process(orders)
if read_game()~=0 then file = "" .. get_turn()
if read_game(file)~=0 then
print("could not read game") print("could not read game")
return -1 return -1
end end
-- initialize starting equipment for new players
-- probably not necessary, since mapper sets new players, not server
add_equipment("conquesttoken", 1);
add_equipment("wood", 30);
add_equipment("stone", 30);
add_equipment("money", 2000 + get_turn() * 10);
read_orders(orders) read_orders(orders)
process_orders() process_orders()
write_passwords() write_passwords()
write_reports() write_reports()
if write_game()~=0 then print(turn .. " " .. get_turn())
file = "" .. get_turn()
if write_game(file)~=0 then
print("could not write game") print("could not write game")
return -1 return -1
end end

View File

@ -4,9 +4,11 @@
// kernel includes // kernel includes
#include <gamecode/laws.h> #include <gamecode/laws.h>
#include <kernel/race.h>
#include <kernel/item.h>
#include <kernel/reports.h>
#include <kernel/save.h> #include <kernel/save.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <kernel/reports.h>
#include <util/language.h> #include <util/language.h>
// lua includes // lua includes
@ -16,6 +18,15 @@
using namespace luabind; using namespace luabind;
static int
lua_addequipment(const char * iname, int number)
{
const struct item_type * itype = it_find(iname);
if (itype==NULL) return -1;
add_equipment(itype, number);
return 0;
}
static int static int
get_turn(void) get_turn(void)
{ {
@ -23,21 +34,20 @@ get_turn(void)
} }
static int static int
read_game(void) read_game(const char * filename)
{ {
return readgame(false); return readgame(filename, false);
} }
static int static int
write_game(void) write_game(const char *filename)
{ {
char ztext[64]; char ztext[64];
free_units(); free_units();
remove_empty_factions(true); remove_empty_factions(true);
sprintf(ztext, "%s/%d", datapath(), turn); writegame(filename, 0);
writegame(ztext, 0);
return 0; return 0;
} }
@ -62,6 +72,7 @@ bind_eressea(lua_State * L)
def("write_reports", &write_reports), def("write_reports", &write_reports),
def("read_orders", &readorders), def("read_orders", &readorders),
def("process_orders", &process_orders), def("process_orders", &process_orders),
def("add_equipment", &lua_addequipment),
def("get_turn", &get_turn) def("get_turn", &get_turn)
]; ];
} }

View File

@ -15,11 +15,14 @@
using namespace luabind; using namespace luabind;
static faction * static faction *
add_faction(const char * email, const char * passwd, const char * racename, const char * lang) add_faction(const char * email, const char * racename, const char * lang)
{ {
const race * frace = findrace(racename, default_locale); const race * frace = findrace(racename, default_locale);
if (frace==NULL) frace = findrace(racename, find_locale("de"));
if (frace==NULL) frace = findrace(racename, find_locale("en"));
if (frace==NULL) return NULL;
locale * loc = find_locale(lang); locale * loc = find_locale(lang);
faction * f = addfaction(email, passwd, frace, loc, 0); faction * f = addfaction(email, NULL, frace, loc, 0);
return f; return f;
} }

View File

@ -40,6 +40,11 @@ region_setname(region& r, const char * name) {
if (r.land) rsetname((&r), name); if (r.land) rsetname((&r), name);
} }
static const char *
region_getterrain(const region& r) {
return terrain[r.terrain].name;
}
static const char * static const char *
region_getname(const region& r) { region_getname(const region& r) {
if (r.land) return r.land->name; if (r.land) return r.land->name;
@ -66,6 +71,7 @@ bind_region(lua_State * L)
class_<struct region>("region") class_<struct region>("region")
.property("name", &region_getname, &region_setname) .property("name", &region_getname, &region_setname)
.property("info", &region_getinfo, &region_setinfo) .property("info", &region_getinfo, &region_setinfo)
.property("terrain", &region_getterrain)
.def_readonly("x", &region::x) .def_readonly("x", &region::x)
.def_readonly("y", &region::y) .def_readonly("y", &region::y)
.def_readwrite("age", &region::age) .def_readwrite("age", &region::age)

View File

@ -25,7 +25,10 @@ add_unit(faction * f, region * r)
static void static void
unit_setnumber(unit& u, int number) unit_setnumber(unit& u, int number)
{ {
if (u.number==0) set_number(&u, number); if (u.number==0) {
set_number(&u, number);
u.hp = unit_max_hp(&u) * number;
}
} }
static int static int

View File

@ -706,8 +706,17 @@ main(int argc, char *argv[])
return 0; return 0;
#endif #endif
if ((i=readgame(false))!=0) return i; if ((i=readgame(false))!=0) return i;
confirm_newbies();
#ifdef NEW_STARTEQUIPMENT
add_equipment(it_find("conquesttoken"), 1);
add_equipment(it_find("wood"), 30);
add_equipment(it_find("stone"), 30);
add_equipment(it_find("money"), 2000 + turn * 10);
#endif
confirm_newbies();
update_subscriptions(); update_subscriptions();
{ {
char zText[128]; char zText[128];

View File

@ -336,6 +336,40 @@ 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_error(("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()
{ {
@ -678,40 +712,6 @@ typedef struct lostdata {
int ship; int ship;
} lostdata; } lostdata;
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_error(("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
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
@ -722,7 +722,7 @@ main(int argc, char *argv[])
updatelog = fopen("update.log", "w"); updatelog = fopen("update.log", "w");
log_open("eressea.log"); log_open("eressea.log");
printf("\n%s PBEM host\n" printf("\n%s PBEM host\n"
"Copyright (C) 1996-2001 C.Schlittchen, K.Zedel, E.Rehling, H.Peters.\n\n" "Copyright (C) 1996-2003 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");

View File

@ -1702,10 +1702,9 @@ main(int argc, char *argv[])
init_gmcmd(); init_gmcmd();
if(!*datafile) if (!*datafile) ssprintf(datafile, "%u", turn);
sprintf(datafile, "%s/%d", datapath(), turn);
readgame(backup); readgame(datafile, backup);
for (f=factions;f;f=f->next) if (f->age==0) { for (f=factions;f;f=f->next) if (f->age==0) {
++numnewbies; ++numnewbies;
} }

View File

@ -71,7 +71,6 @@ void NeuePartei(struct region * r);
void RemovePartei(void); void RemovePartei(void);
int ParteiListe(void); int ParteiListe(void);
int koor_distance(int a, int b, int x, int y); int koor_distance(int a, int b, int x, int y);
int readgame(boolean backup);
int create_backup(char *file); int create_backup(char *file);
void SpecialFunction(struct region *r); void SpecialFunction(struct region *r);