- code to seed adamantium

- cleaner definition of raw materials
This commit is contained in:
Enno Rehling 2008-06-08 10:17:29 +00:00
parent ac595313cf
commit 1c139de354
12 changed files with 92 additions and 101 deletions

View file

@ -84,22 +84,6 @@ typedef struct xml_context {
xmlNsPtr ns_xml;
} xml_context;
#if 0
static const xmlChar *
xml_s(const char * str)
{
static xmlChar buffer[1024];
const char * inbuf = str;
char * outbuf = (char *)buffer;
size_t inbytes = strlen(str)+1;
size_t outbytes = sizeof(buffer) - 1;
unicode_latin1_to_utf8(outbuf, &outbytes, inbuf, &inbytes);
buffer[outbytes] = 0;
return buffer;
}
#endif
static const xmlChar *
xml_i(double number)
{

View file

@ -60,6 +60,23 @@ update_resource(struct rawmaterial * res, double modifier)
assert(res->amount>0);
}
void
add_resource(region * r, int level, int base, int divisor, const resource_type * rtype)
{
struct rawmaterial * rm = calloc(sizeof(struct rawmaterial), 1);
rm->next = r->resources;
r->resources = rm;
rm->level = level;
rm->startlevel = level;
rm->base = base;
rm->divisor = divisor;
rm->flags = 0;
rm->type = rmt_get(rtype);
update_resource(rm, 1.0);
rm->type->terraform(rm, r);
}
void
terraform_resources(region * r)
{
@ -78,18 +95,7 @@ terraform_resources(region * r)
if (rm) continue;
if (chance(production->chance)) {
rm = calloc(sizeof(struct rawmaterial), 1);
rm->next = r->resources;
r->resources = rm;
rm->level = dice_rand(production->startlevel);
rm->startlevel = rm->level;
rm->base = dice_rand(production->base);
rm->divisor = dice_rand(production->divisor);
rm->flags = 0;
rm->type = rmt_get(production->type);
update_resource(rm, 1.0);
rm->type->terraform(rm, r);
add_resource(r, dice_rand(production->startlevel), dice_rand(production->base), dice_rand(production->divisor), production->type);
}
}
}
@ -131,7 +137,7 @@ visible_default(const rawmaterial *res, int skilllevel)
/* resources are visible, if skill equals minimum skill to mine them
* plus current level of difficulty */
{
const struct item_type * itype = olditemtype[res->type->_itype];
const struct item_type * itype = res->type->rtype->itype;
if (res->level<=1 && res->level + itype->construction->minskill <= skilllevel+1) {
assert (res->amount>0);
return res->amount;
@ -168,33 +174,6 @@ rm_get(region * r, const struct resource_type * rtype)
return rm;
}
struct rawmaterial_type rm_stones = {
"rm_stone",
I_STONE, NULL,
terraform_default,
NULL,
use_default,
visible_default
};
struct rawmaterial_type rm_iron = {
"rm_iron",
I_IRON, NULL,
terraform_default,
NULL,
use_default,
visible_default
};
struct rawmaterial_type rm_laen = {
"rm_laen",
I_LAEN, NULL,
terraform_default,
NULL,
use_default,
visible_default
};
struct rawmaterial_type * rawmaterialtypes = 0;
struct rawmaterial_type *
@ -213,18 +192,23 @@ rmt_get(const struct resource_type * rtype)
return rmt;
}
struct rawmaterial_type *
rmt_create(const struct resource_type * rtype, const char * name)
{
rawmaterial_type * rmtype = malloc(sizeof(rawmaterial_type));
rmtype->name = strdup(name);
rmtype->rtype = rtype;
rmtype->terraform = terraform_default;
rmtype->update = NULL;
rmtype->use = use_default;
rmtype->visible = visible_default;
rmtype->next = rawmaterialtypes;
rawmaterialtypes = rmtype;
return rmtype;
}
static void
add_rawmaterial(struct rawmaterial_type * rmtype)
{
rmtype->rtype = item2resource(olditemtype[rmtype->_itype]);
rmtype->next = rawmaterialtypes;
rawmaterialtypes = rmtype;
}
void
init_rawmaterials(void)
{
add_rawmaterial(&rm_stones);
add_rawmaterial(&rm_iron);
add_rawmaterial(&rm_laen);
rmtype->rtype = rmtype->rtype;
}

View file

@ -32,8 +32,7 @@ typedef struct rawmaterial {
} rawmaterial;
typedef struct rawmaterial_type {
const char * name;
item_t _itype; /* what you'll be producing. hack - needs resource_type */
char * name;
const struct resource_type * rtype;
void (*terraform) (struct rawmaterial *, const struct region *);
@ -52,13 +51,11 @@ extern void terraform_resources(struct region * r);
extern void read_resources(struct region * r);
extern void write_resources(struct region * r);
extern struct rawmaterial * rm_get(struct region *, const struct resource_type *);
extern void init_rawmaterials(void);
extern struct rawmaterial_type * rmt_find(const char * str);
extern struct rawmaterial_type * rmt_get(const struct resource_type *);
extern struct rawmaterial_type rm_stones;
extern struct rawmaterial_type rm_iron;
extern struct rawmaterial_type rm_laen;
extern void add_resource(struct region * r, int level, int base, int divisor, const struct resource_type * rtype);
extern struct rawmaterial_type * rmt_create(const struct resource_type * rtype, const char * name);
#ifdef __cplusplus
}

View file

@ -21,6 +21,7 @@ without prior permission by the authors of Eressea.
#include "message.h"
#include "race.h"
#include "region.h"
#include "resources.h"
#include "ship.h"
#include "terrain.h"
#include "skill.h"
@ -950,6 +951,13 @@ parse_resources(xmlDocPtr doc)
if (name) xmlFree(name);
if (appearance) xmlFree(appearance);
name = xmlGetProp(node, BAD_CAST "material");
if (name) {
rmt_create(rtype, (const char *)name);
xmlFree(name);
}
if (gamecode_enabled) {
/* reading eressea/resources/resource/function */
xpath->node = node;

View file

@ -18,6 +18,7 @@
#include <kernel/alliance.h>
#include <kernel/item.h>
#include <kernel/region.h>
#include <kernel/resources.h>
#include <kernel/plane.h>
#include <kernel/faction.h>
#include <kernel/race.h>
@ -25,7 +26,10 @@
#include <kernel/terrainid.h>
#include <kernel/unit.h>
#include <attributes/key.h>
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/goodies.h>
#include <util/lists.h>
@ -64,6 +68,20 @@ random_terrain(boolean distribution)
return terrain;
}
int
seed_adamantium(region * r, int base)
{
const resource_type * rtype = rt_find("adamantium");
rawmaterial * rm;
for (rm = r->resources;rm;rm=rm->next) {
if (rm->type->rtype==rtype) break;
}
if (!rm) {
add_resource(r, 1, base, 150, rtype);
}
return 0;
}
static int
count_demand(const region *r)

View file

@ -38,6 +38,8 @@ extern void get_island(struct region * root, struct region_list ** rlist);
extern int fix_demand(struct region *r);
extern const struct terrain_type * random_terrain(boolean use_distribution);
extern int seed_adamantium(struct region * r, int base);
#ifdef __cplusplus
}
#endif

View file

@ -376,25 +376,6 @@ growing_trees(void)
return 0;
}
static int fix_adamantium(void)
{
faction * f;
for (f=factions;f;f=f->next) {
const struct item_type * itype;
int o = 1;
int p = (f->no % 5)?1:0;
int a = (f->no % 5)?0:1;
itype = it_find("adamantium");
i_change(&f->items, itype, o-i_get(f->items, itype));
itype = it_find("adamantiumaxe");
i_change(&f->items, itype, a-i_get(f->items, itype));
itype = it_find("adamantiumplate");
i_change(&f->items, itype, p-i_get(f->items, itype));
}
return 0;
}
#include <triggers/gate.h>
#include <triggers/unguard.h>
typedef struct gate_data {
@ -914,7 +895,6 @@ korrektur(void)
do_once("asfi", &fix_astral_firewalls);
fix_astralplane();
fix_toads();
do_once("admt", &fix_adamantium);
/* fix_heroes(); */
verify_owners(false);

View file

@ -217,7 +217,6 @@ is_function(struct lua_State * luaState, const char * fname)
if (type(fun)==LUA_TFUNCTION) {
return true;
}
log_warning(("Lua global object %s is not a function, type is %u\n", fname, type(fun)));
if (type(fun)!=LUA_TNIL) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, type(fun)));
}

View file

@ -20,8 +20,10 @@ using namespace luabind;
#include <util/language.h>
#include <util/rng.h>
#include <kernel/skill.h>
#include <kernel/region.h>
#include <kernel/skill.h>
#include <kernel/terrainid.h>
#include <modules/autoseed.h>
static const char *
loc_getskill(const char * loc, const char * locstring)
@ -41,6 +43,22 @@ loc_getkeyword(const char * loc, const char * locstring)
return keywords[result];
}
static void
adamantium(region * r)
{
region_list *rp, *rlist = NULL;
get_island(r, &rlist);
for (rp=rlist;rp;rp=rp->next) {
region * ri = rp->data;
if (ri->terrain==newterrain(T_MOUNTAIN)) {
int base = 1 << (rng_int() % 4);
seed_adamantium(r, base);
}
}
free_regionlist(rlist);
}
void
bind_test(lua_State * L)
{
@ -48,6 +66,7 @@ bind_test(lua_State * L)
def("loc_skill", &loc_getskill),
def("loc_keyword", &loc_getkeyword),
def("reorder_units", &reorder_units),
def("seed_adamantium", &adamantium),
def("rng_int", &rng_int)
];
}

View file

@ -236,7 +236,6 @@ game_init(void)
init_archetypes();
init_attributes();
init_itemtypes();
init_rawmaterials();
init_gmcmd();
#if INFOCMD_MODULE

View file

@ -164,7 +164,7 @@
</resource>
<!-- christmas items: end -->
<resource name="adamantium" limited="yes">
<resource name="adamantium" limited="yes" material="rm_adamantium">
<item weight="200" score="200">
<construction skill="mining" minskill="8" reqsize="1"/>
</item>
@ -176,7 +176,8 @@
<resource name="adamantiumaxe">
<item weight="100" score="500">
<construction skill="weaponsmithing" minskill="8" reqsize="1">
<requirement type="adamantium" quantity="2"/>
<requirement type="adamantium" quantity="1"/>
<requirement type="log" quantity="1"/>
</construction>
<weapon cut="true" skill="melee" offmod="2" defmod="-2" magres="0.30">
<damage type="rider" value="3d4+15"/>

View file

@ -79,7 +79,7 @@
<item weight="5000" notlost="yes" big="yes" score="6000" capacity="7000" animal="yes"/>
</resource>
<resource name="iron" limited="yes">
<resource name="iron" limited="yes" material="rm_iron">
<item weight="500" score="10">
<construction skill="mining" minskill="1" reqsize="1"/>
</item>
@ -91,7 +91,7 @@
</resourcelimit>
</resource>
<resource name="laen" limited="yes">
<resource name="laen" limited="yes" material="rm_laen">
<item weight="200" score="100">
<construction skill="mining" minskill="7" reqsize="1"/>
</item>
@ -100,7 +100,7 @@
</resourcelimit>
</resource>
<resource name="stone" limited="yes">
<resource name="stone" limited="yes" material="rm_stone">
<item weight="6000" score="10" big="yes">
<construction skill="quarrying" minskill="1" reqsize="1"/>
</item>