moving monsters to eressea

This commit is contained in:
Enno Rehling 2010-02-27 08:28:59 +00:00
parent 8baf1aff88
commit 9ee6fc250c
17 changed files with 1184 additions and 1204 deletions

View file

@ -306,6 +306,26 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\monsters.c"
>
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
ExcludedFromBuild="true"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\spells\regioncurse.c"
>

View file

@ -1,9 +1,10 @@
#include <platform.h>
#include <kernel/types.h>
#include "spells/shipcurse.h"
#include <kernel/ship.h>
#include <kernel/unit.h>
#include <kernel/faction.h>
#include <tolua.h>
@ -19,6 +20,37 @@ tolua_levitate_ship(lua_State * L)
return 1;
}
extern void spawn_undead(void);
extern void spawn_dragons(void);
extern void plan_monsters(struct faction * f);
static int
tolua_planmonsters(lua_State * L)
{
faction * f = (faction *)tolua_tousertype(L, 1, get_monsters());
if (f) {
plan_monsters(f);
}
return 0;
}
static int
tolua_spawn_dragons(lua_State * L)
{
spawn_dragons();
return 0;
}
static int
tolua_spawn_undead(lua_State * L)
{
spawn_undead();
return 0;
}
void
bind_eressea(struct lua_State * L)
{
@ -26,6 +58,9 @@ bind_eressea(struct lua_State * L)
tolua_beginmodule(L, NULL);
{
tolua_function(L, TOLUA_CAST "levitate_ship", tolua_levitate_ship);
tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters);
tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead);
tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons);
}
tolua_endmodule(L);
}

1003
src/eressea/src/monsters.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -12,3 +12,4 @@
#include "main.c"
#include "bindings.c"
#include "monsters.c"

View file

@ -222,49 +222,6 @@ tolua_message_region(lua_State * L)
return 0;
}
static void
free_script(attrib * a)
{
lua_State * L = (lua_State *)global.vm_state;
if (a->data.i>0) {
luaL_unref(L, LUA_REGISTRYINDEX, a->data.i);
}
}
attrib_type at_script = {
"script",
NULL, free_script, NULL,
NULL, NULL, ATF_UNIQUE
};
static int
call_script(lua_State * L, struct unit * u)
{
const attrib * a = a_findc(u->attribs, &at_script);
if (a==NULL) a = a_findc(u->race->attribs, &at_script);
if (a!=NULL && a->data.i>0) {
lua_rawgeti(L, LUA_REGISTRYINDEX, a->data.i);
if (lua_pcall(L, 1, 0, 0)!=0) {
const char* error = lua_tostring(L, -1);
log_error(("call_script (%s): %s", unitname(u), error));
lua_pop(L, 1);
}
}
return -1;
}
static void
setscript(lua_State * L, struct attrib ** ap)
{
attrib * a = a_find(*ap, &at_script);
if (a == NULL) {
a = a_add(ap, a_new(&at_script));
} else if (a->data.i>0) {
luaL_unref(L, LUA_REGISTRYINDEX, a->data.i);
}
a->data.i = luaL_ref(L, LUA_REGISTRYINDEX);
}
static int
tolua_update_guards(lua_State * L)
{
@ -480,46 +437,6 @@ tolua_levitate_ship(lua_State * L)
}
#endif
static int
tolua_set_unitscript(lua_State * L)
{
struct unit * u = (struct unit *)tolua_tousertype(L, 1, 0);
if (u) {
lua_pushvalue(L, 2);
setscript(L, &u->attribs);
lua_pop(L, 1);
}
return 0;
}
static int
tolua_set_racescript(lua_State * L)
{
const char * rcname = tolua_tostring(L, 1, 0);
race * rc = rc_find(rcname);
if (rc!=NULL) {
lua_pushvalue(L, 2);
setscript(L, &rc->attribs);
lua_pop(L, 1);
}
return 0;
}
static int
tolua_spawn_dragons(lua_State * L)
{
spawn_dragons();
return 0;
}
static int
tolua_spawn_undead(lua_State * L)
{
spawn_undead();
return 0;
}
static int
tolua_spawn_braineaters(lua_State * L)
{
@ -528,22 +445,6 @@ tolua_spawn_braineaters(lua_State * L)
return 0;
}
static int
tolua_planmonsters(lua_State * L)
{
faction * f = get_monsters();
if (f!=NULL) {
unit * u;
plan_monsters();
for (u=f->units;u;u=u->nextF) {
call_script(L, u);
}
}
return 0;
}
static int
tolua_init_reports(lua_State* L)
{
@ -1185,13 +1086,7 @@ tolua_eressea_open(lua_State* L)
tolua_function(L, TOLUA_CAST "message_region", tolua_message_region);
/* scripted monsters */
tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters);
tolua_function(L, TOLUA_CAST "spawn_braineaters", tolua_spawn_braineaters);
tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead);
tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons);
tolua_function(L, TOLUA_CAST "set_race_brain", tolua_set_racescript);
tolua_function(L, TOLUA_CAST "set_unit_brain", tolua_set_unitscript);
#ifdef TODO_FOSS
/* spells and stuff */

View file

@ -4069,7 +4069,7 @@ init_processor(void)
p+=10;
add_proc_global(p, &encounters, "Zufallsbegegnungen");
p+=10;
add_proc_unit(p, &monsters_kill_peasants, "Monster fressen und vertreiben Bauern");
add_proc_unit(p, &monster_kills_peasants, "Monster fressen und vertreiben Bauern");
p+=10;
add_proc_global(p, &randomevents, "Zufallsereignisse");

File diff suppressed because it is too large Load diff

View file

@ -25,16 +25,8 @@
extern "C" {
#endif
#define DRAGON_RANGE 20 /* Max. Distanz zum nächsten Drachenziel */
void age_illusion(struct unit *u);
void monsters_kill_peasants(struct unit * u);
void plan_monsters(void);
struct unit *random_unit(const struct region * r);
extern void spawn_undead(void);
extern void spawn_dragons(void);
void monster_kills_peasants(struct unit * u);
boolean monster_is_waiting(const struct unit * u);
#ifdef __cplusplus
}

View file

@ -425,6 +425,37 @@ chaosterrain(void)
return types[rng_int() % numtypes];
}
static unit *
random_unit(const region * r)
{
int c = 0;
int n;
unit *u;
for (u = r->units; u; u = u->next) {
if (u->race != new_race[RC_SPELL]) {
c += u->number;
}
}
if (c == 0) {
return NULL;
}
n = rng_int() % c;
c = 0;
u = r->units;
while (u && c < n) {
if (u->race != new_race[RC_SPELL]) {
c += u->number;
}
u = u->next;
}
return u;
}
void
chaos(region * r)
{
@ -978,38 +1009,6 @@ godcurse(void)
}
static unit *
split_unit(region * r, unit *u)
{
unit *u2 = create_unit(r, u->faction, 0, u->race, 0, u->name, u);
int newsize = u->number/2;
if (u->display) {
free(u2->display);
u2->display = strdup(u->display);
}
transfermen(u, u2, newsize);
return u2;
}
static void
check_split(void)
{
region *r;
unit *u;
for(r=regions;r;r=r->next) {
for(u=r->units;u;u=u->next) {
if(is_monsters(u->faction)) {
if(u->number > u->race->splitsize) {
unit * u2 = split_unit(r, u);
fset(u2, UFL_ISNEW|UFL_MOVED);
}
}
}
}
}
/** handles the "orcish" curse that makes units grow like old orks
* This would probably be better handled in an age-function for the curse,
* but it's now being called by randomevents()
@ -1273,5 +1272,4 @@ randomevents(void)
#endif
dissolve_units();
check_split();
}

View file

@ -92,9 +92,6 @@
#include <util/patricia.h>
#endif
/* exported variables */
region *regions;
faction *factions;
struct settings global = {
"Eressea", /* gamename */
};

View file

@ -166,9 +166,6 @@ extern int findoption(const char *s, const struct locale * lang);
/* special units */
void make_undead_unit(struct unit *);
extern struct region *regions;
extern struct faction *factions;
void addstrlist(strlist ** SP, const char *s);
int armedmen(const struct unit * u, boolean siege_weapons);

View file

@ -49,6 +49,8 @@
#include <string.h>
#include <stdlib.h>
faction *factions;
/** remove the faction from memory.
* this frees all memory that's only accessible through the faction,
* but you should still call funhash and remove the faction from the

View file

@ -103,6 +103,8 @@ typedef struct faction {
struct seen_region ** seen;
} faction;
extern struct faction *factions;
typedef struct faction_list {
struct faction_list * next;
struct faction * data;

View file

@ -64,6 +64,8 @@
extern int dice_rand(const char *s);
region *regions;
int
get_maxluxuries()
{

View file

@ -137,6 +137,8 @@ typedef struct region {
#endif
} region;
extern struct region *regions;
typedef struct region_list {
struct region_list * next;
struct region * data;

View file

@ -31,23 +31,23 @@
void
age_firedragon(unit *u)
{
if (u->number>0 && rng_int()%100 < age_chance(u->age, DRAGONAGE, 1)) {
double q = (double) u->hp / (double) (unit_max_hp(u) * u->number);
u->race = new_race[RC_DRAGON];
u->irace = NULL;
scale_number(u,1);
u->hp = (int) (unit_max_hp(u) * u->number * q);
}
if (u->number>0 && rng_int()%100 < age_chance(u->age, DRAGONAGE, 1)) {
double q = (double) u->hp / (double) (unit_max_hp(u) * u->number);
u->race = new_race[RC_DRAGON];
u->irace = NULL;
scale_number(u,1);
u->hp = (int) (unit_max_hp(u) * u->number * q);
}
}
void
age_dragon(unit *u)
{
if (u->number>0 && rng_int()%100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double) u->hp / (double) (unit_max_hp(u) * u->number);
u->race = new_race[RC_WYRM];
u->irace = NULL;
u->hp = (int) (unit_max_hp(u) * u->number * q);
}
if (u->number>0 && rng_int()%100 < age_chance(u->age, WYRMAGE, 1)) {
double q = (double) u->hp / (double) (unit_max_hp(u) * u->number);
u->race = new_race[RC_WYRM];
u->irace = NULL;
u->hp = (int) (unit_max_hp(u) * u->number * q);
}
}

View file

@ -30,13 +30,13 @@
void
age_illusion(unit *u)
{
if (u->faction->race!=new_race[RC_ILLUSION]) {
if (u->age == ILLUSIONMAX) {
ADDMSG(&u->faction->msgs, msg_message("warnillusiondissolve",
if (u->faction->race!=new_race[RC_ILLUSION]) {
if (u->age == ILLUSIONMAX) {
ADDMSG(&u->faction->msgs, msg_message("warnillusiondissolve",
"unit", u));
} else if (u->age > ILLUSIONMAX) {
set_number(u, 0);
ADDMSG(&u->faction->msgs, msg_message("illusiondissolve", "unit", u));
}
}
} else if (u->age > ILLUSIONMAX) {
set_number(u, 0);
ADDMSG(&u->faction->msgs, msg_message("illusiondissolve", "unit", u));
}
}
}