forked from github/server
- dice_rand kann einfaches multiplizieren
- als dice_roll nach lua exportiert - equipment kann in inventories getan werden - region::land bekommt ein inventory - terraform legt equipment in neue regionen kingdoms: - neues terrain berge.
This commit is contained in:
parent
a6cc57370f
commit
4635c46ec2
15 changed files with 147 additions and 34 deletions
|
@ -161,6 +161,19 @@ reset_translations(void)
|
||||||
|
|
||||||
#include "objtypes.h"
|
#include "objtypes.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_items(FILE * F, item * items, const struct locale * lang)
|
||||||
|
{
|
||||||
|
item * itm;
|
||||||
|
|
||||||
|
for (itm=items; itm; itm=itm->next) {
|
||||||
|
int in = itm->number;
|
||||||
|
const char * ic = resourcename(itm->type->rtype, in);
|
||||||
|
if (itm==items) fputs("GEGENSTAENDE\n", F);
|
||||||
|
fprintf(F, "%d;%s\n", in, add_translation(ic, LOC(lang, ic)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ)
|
print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ)
|
||||||
{
|
{
|
||||||
|
@ -1045,7 +1058,6 @@ report_computer(const char * filename, report_context * ctx)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
faction * f = ctx->f;
|
faction * f = ctx->f;
|
||||||
item * itm;
|
|
||||||
const char * prefix;
|
const char * prefix;
|
||||||
region * r;
|
region * r;
|
||||||
building *b;
|
building *b;
|
||||||
|
@ -1127,12 +1139,7 @@ report_computer(const char * filename, report_context * ctx)
|
||||||
fprintf(F, "\"%s\";Parteiname\n", f->name);
|
fprintf(F, "\"%s\";Parteiname\n", f->name);
|
||||||
fprintf(F, "\"%s\";email\n", f->email);
|
fprintf(F, "\"%s\";email\n", f->email);
|
||||||
fprintf(F, "\"%s\";banner\n", f->banner);
|
fprintf(F, "\"%s\";banner\n", f->banner);
|
||||||
for (itm=f->items; itm; itm=itm->next) {
|
print_items(F, f->items, f->locale);
|
||||||
int in = itm->number;
|
|
||||||
const char * ic = resourcename(itm->type->rtype, in);
|
|
||||||
if (itm==f->items) fputs("GEGENSTAENDE\n", F);
|
|
||||||
fprintf(F, "%d;%s\n", in, add_translation(ic, LOC(f->locale, ic)));
|
|
||||||
}
|
|
||||||
fputs("OPTIONEN\n", F);
|
fputs("OPTIONEN\n", F);
|
||||||
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]);
|
||||||
|
@ -1335,6 +1342,9 @@ report_computer(const char * filename, report_context * ctx)
|
||||||
}
|
}
|
||||||
if (pos!=cbuf) fputs(cbuf, F);
|
if (pos!=cbuf) fputs(cbuf, F);
|
||||||
}
|
}
|
||||||
|
if (r->land) {
|
||||||
|
print_items(F, r->land->items, f->locale);
|
||||||
|
}
|
||||||
print_curses(F, f, r, TYP_REGION);
|
print_curses(F, f, r, TYP_REGION);
|
||||||
cr_borders(ctx->seen, r, f, sd->mode, F);
|
cr_borders(ctx->seen, r, f, sd->mode, F);
|
||||||
if (sd->mode==see_unit && rplane(r)==get_astralplane() && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
|
if (sd->mode==see_unit && rplane(r)==get_astralplane() && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
|
||||||
|
|
|
@ -1723,7 +1723,7 @@ make_cmd(unit * u, struct order * ord)
|
||||||
static void
|
static void
|
||||||
free_luxuries(struct attrib * a)
|
free_luxuries(struct attrib * a)
|
||||||
{
|
{
|
||||||
i_freeall((item*)a->data.v);
|
i_freeall((item**)&a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
const attrib_type at_luxuries = {
|
const attrib_type at_luxuries = {
|
||||||
|
|
|
@ -155,3 +155,34 @@ equip_unit(struct unit * u, const struct equipment * eq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
equip_items(struct item ** items, const struct equipment * eq)
|
||||||
|
{
|
||||||
|
if (eq) {
|
||||||
|
itemdata * idata;
|
||||||
|
|
||||||
|
for (idata=eq->items;idata!=NULL;idata=idata->next) {
|
||||||
|
int i = dice_rand(idata->value);
|
||||||
|
if (i>0) {
|
||||||
|
i_add(items, i_new(idata->itype, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (eq->subsets) {
|
||||||
|
int i;
|
||||||
|
for (i=0;eq->subsets[i].sets;++i) {
|
||||||
|
if (chance(eq->subsets[i].chance)) {
|
||||||
|
float rnd = 1000.0f / (1+rand() % 1000);
|
||||||
|
int k;
|
||||||
|
for (k=0;eq->subsets[i].sets[k].set;++k) {
|
||||||
|
if (rnd<=eq->subsets[i].sets[k].chance) {
|
||||||
|
equip_items(items, eq->subsets[i].sets[k].set);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rnd -= eq->subsets[i].sets[k].chance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ extern "C" {
|
||||||
extern void equipment_addspell(struct equipment * eq, struct spell * sp);
|
extern void equipment_addspell(struct equipment * eq, struct spell * sp);
|
||||||
|
|
||||||
extern void equip_unit(struct unit * u, const struct equipment * eq);
|
extern void equip_unit(struct unit * u, const struct equipment * eq);
|
||||||
|
extern void equip_items(struct item ** items, const struct equipment * eq);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,7 +712,7 @@ stripfaction (faction * f)
|
||||||
|
|
||||||
while (f->attribs) a_remove (&f->attribs, f->attribs);
|
while (f->attribs) a_remove (&f->attribs, f->attribs);
|
||||||
|
|
||||||
i_freeall(f->items);
|
i_freeall(&f->items);
|
||||||
|
|
||||||
freelist(f->ursprung);
|
freelist(f->ursprung);
|
||||||
funhash(f);
|
funhash(f);
|
||||||
|
|
|
@ -526,13 +526,13 @@ i_free(item * i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
i_freeall(item *i) {
|
i_freeall(item **i) {
|
||||||
item *in;
|
item *in;
|
||||||
|
|
||||||
while(i) {
|
while(*i) {
|
||||||
in = i->next;
|
in = (*i)->next;
|
||||||
free(i);
|
free(*i);
|
||||||
i = in;
|
*i = in;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ extern item * i_add(item ** pi, item * it);
|
||||||
extern void i_merge(item ** pi, item ** si);
|
extern void i_merge(item ** pi, item ** si);
|
||||||
extern item * i_remove(item ** pi, item * it);
|
extern item * i_remove(item ** pi, item * it);
|
||||||
extern void i_free(item * i);
|
extern void i_free(item * i);
|
||||||
extern void i_freeall(item * i);
|
extern void i_freeall(item ** i);
|
||||||
extern item * i_new(const item_type * it, int number);
|
extern item * i_new(const item_type * it, int number);
|
||||||
|
|
||||||
/* convenience: */
|
/* convenience: */
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "border.h"
|
#include "border.h"
|
||||||
#include "building.h"
|
#include "building.h"
|
||||||
#include "curse.h"
|
#include "curse.h"
|
||||||
|
#include "equipment.h"
|
||||||
#include "faction.h"
|
#include "faction.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
@ -895,6 +896,7 @@ terraform_region(region * r, const terrain_type * terrain)
|
||||||
|
|
||||||
if (!fval(terrain, LAND_REGION)) {
|
if (!fval(terrain, LAND_REGION)) {
|
||||||
if (r->land!=NULL) {
|
if (r->land!=NULL) {
|
||||||
|
i_freeall(&r->land->items);
|
||||||
freeland(r->land);
|
freeland(r->land);
|
||||||
r->land = NULL;
|
r->land = NULL;
|
||||||
}
|
}
|
||||||
|
@ -910,7 +912,9 @@ terraform_region(region * r, const terrain_type * terrain)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!r->land) {
|
if (r->land) {
|
||||||
|
i_freeall(&r->land->items);
|
||||||
|
} else {
|
||||||
static struct surround {
|
static struct surround {
|
||||||
struct surround * next;
|
struct surround * next;
|
||||||
const luxury_type * type;
|
const luxury_type * type;
|
||||||
|
@ -970,7 +974,13 @@ terraform_region(region * r, const terrain_type * terrain)
|
||||||
|
|
||||||
if (fval(terrain, LAND_REGION)) {
|
if (fval(terrain, LAND_REGION)) {
|
||||||
const item_type * itype = NULL;
|
const item_type * itype = NULL;
|
||||||
if (r->terrain->herbs) {
|
char equip_hash[64];
|
||||||
|
|
||||||
|
/* TODO: put the equipment in struct terrain, faster */
|
||||||
|
sprintf(equip_hash, "terrain_%s", terrain->_name);
|
||||||
|
equip_items(&r->land->items, get_equipment(equip_hash));
|
||||||
|
|
||||||
|
if (r->terrain->herbs) {
|
||||||
int len=0;
|
int len=0;
|
||||||
while (r->terrain->herbs[len]) ++len;
|
while (r->terrain->herbs[len]) ++len;
|
||||||
if (len) itype = r->terrain->herbs[rand()%len];
|
if (len) itype = r->terrain->herbs[rand()%len];
|
||||||
|
|
|
@ -76,6 +76,7 @@ typedef struct land_region {
|
||||||
int peasants;
|
int peasants;
|
||||||
int newpeasants;
|
int newpeasants;
|
||||||
int money;
|
int money;
|
||||||
|
struct item * items; /* items that can be claimed */
|
||||||
} land_region;
|
} land_region;
|
||||||
|
|
||||||
typedef struct donation {
|
typedef struct donation {
|
||||||
|
|
|
@ -102,7 +102,8 @@ a_initmuseumgiveback(attrib *a)
|
||||||
static void
|
static void
|
||||||
a_finalizemuseumgiveback(attrib *a)
|
a_finalizemuseumgiveback(attrib *a)
|
||||||
{
|
{
|
||||||
i_freeall(((museumgiveback *)(a->data.v))->items);
|
museumgiveback *gb = (museumgiveback *)a->data.v;
|
||||||
|
i_freeall(&gb->items);
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,13 +49,14 @@ int
|
||||||
dice_rand(const char *s)
|
dice_rand(const char *s)
|
||||||
{
|
{
|
||||||
const char *c = s;
|
const char *c = s;
|
||||||
int m = 0, d = 0, k = 0, multi = 1;
|
int m = 0, d = 0, k = 0, term = 1, multi = 1;
|
||||||
int state = 1;
|
int state = 1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (isdigit((int)*c)) {
|
if (isdigit((int)*c)) {
|
||||||
k = k*10+(*c-'0');
|
k = k*10+(*c-'0');
|
||||||
} else if (*c=='+' || *c=='-' || *c==0) {
|
}
|
||||||
|
else if (*c=='+' || *c=='-' || *c==0 || *c=='*') {
|
||||||
if (state==1) /* konstante k addieren */
|
if (state==1) /* konstante k addieren */
|
||||||
m+=k*multi;
|
m+=k*multi;
|
||||||
else if (state==2) { /* dDk */
|
else if (state==2) { /* dDk */
|
||||||
|
@ -64,6 +65,10 @@ dice_rand(const char *s)
|
||||||
for (i=0;i!=d;++i) m += (1 + rand() % k)*multi;
|
for (i=0;i!=d;++i) m += (1 + rand() % k)*multi;
|
||||||
}
|
}
|
||||||
else assert(!"dice_rand: illegal token");
|
else assert(!"dice_rand: illegal token");
|
||||||
|
if (*c=='*') {
|
||||||
|
term *= m;
|
||||||
|
m = 0;
|
||||||
|
}
|
||||||
k = d = 0;
|
k = d = 0;
|
||||||
state = 1;
|
state = 1;
|
||||||
multi = (*c=='-')?-1:1;
|
multi = (*c=='-')?-1:1;
|
||||||
|
@ -77,5 +82,5 @@ dice_rand(const char *s)
|
||||||
if (*c==0) break;
|
if (*c==0) break;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
return m;
|
return m*term;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
// util includes
|
// util includes
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
|
#include <util/rand.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
@ -275,6 +276,7 @@ bind_eressea(lua_State * L)
|
||||||
def("write_game", &write_game),
|
def("write_game", &write_game),
|
||||||
def("write_passwords", &writepasswd),
|
def("write_passwords", &writepasswd),
|
||||||
def("init_reports", &init_reports),
|
def("init_reports", &init_reports),
|
||||||
|
def("dice_roll", &dice_rand),
|
||||||
def("write_reports", &lua_writereports),
|
def("write_reports", &lua_writereports),
|
||||||
def("write_report", &lua_writereport),
|
def("write_report", &lua_writereport),
|
||||||
def("init_summary", &init_summary),
|
def("init_summary", &init_summary),
|
||||||
|
|
|
@ -124,10 +124,14 @@ static int
|
||||||
region_getresource(const region& r, const char * type)
|
region_getresource(const region& r, const char * type)
|
||||||
{
|
{
|
||||||
const resource_type * rtype = rt_find(type);
|
const resource_type * rtype = rt_find(type);
|
||||||
if (rtype==rt_find("money")) return rmoney(&r);
|
if (rtype!=NULL) {
|
||||||
if (rtype==rt_find("peasant")) return rpeasants(&r);
|
if (rtype==rt_find("money")) return rmoney(&r);
|
||||||
if (strcmp(type, "grave")==0) return deathcount(&r);
|
if (rtype==rt_find("peasant")) return rpeasants(&r);
|
||||||
if (strcmp(type, "chaos")==0) return chaoscount(&r);
|
} else {
|
||||||
|
if (strcmp(type, "tree")==0) return rtrees(&r, 2);
|
||||||
|
if (strcmp(type, "grave")==0) return deathcount(&r);
|
||||||
|
if (strcmp(type, "chaos")==0) return chaoscount(&r);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,15 +139,19 @@ static void
|
||||||
region_setresource(region& r, const char * type, int value)
|
region_setresource(region& r, const char * type, int value)
|
||||||
{
|
{
|
||||||
const resource_type * rtype = rt_find(type);
|
const resource_type * rtype = rt_find(type);
|
||||||
if (rtype==rt_find("money")) rsetmoney(&r, value);
|
if (rtype!=NULL) {
|
||||||
if (rtype==rt_find("peasant")) return rsetpeasants(&r, value);
|
if (rtype==rt_find("money")) rsetmoney(&r, value);
|
||||||
if (strcmp(type, "grave")==0) {
|
if (rtype==rt_find("peasant")) return rsetpeasants(&r, value);
|
||||||
int fallen = value-deathcount(&r);
|
} else {
|
||||||
deathcounts(&r, fallen);
|
if (strcmp(type, "tree")==0) {
|
||||||
}
|
rsettrees(&r, 2, value);
|
||||||
if (strcmp(type, "chaos")==0) {
|
} else if (strcmp(type, "grave")==0) {
|
||||||
int fallen = value-chaoscount(&r);
|
int fallen = value-deathcount(&r);
|
||||||
chaoscounts(&r, fallen);
|
deathcounts(&r, fallen);
|
||||||
|
} else if (strcmp(type, "chaos")==0) {
|
||||||
|
int fallen = value-chaoscount(&r);
|
||||||
|
chaoscounts(&r, fallen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +261,26 @@ region_move(region& r, short x, short y)
|
||||||
rhash(&r);
|
rhash(&r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static eressea::list<std::string, item *, eressea::bind_items>
|
||||||
|
region_items(const region& r) {
|
||||||
|
if (r.land) {
|
||||||
|
return eressea::list<std::string, item *, eressea::bind_items>(r.land->items);
|
||||||
|
} else {
|
||||||
|
return eressea::list<std::string, item *, eressea::bind_items>(NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
region_additem(region& r, const char * iname, int number)
|
||||||
|
{
|
||||||
|
const item_type * itype = it_find(iname);
|
||||||
|
if (itype!=NULL && r.land) {
|
||||||
|
item * i = i_change(&r.land->items, itype, number);
|
||||||
|
return i?i->number:0;
|
||||||
|
} // if (itype!=NULL)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bind_region(lua_State * L)
|
bind_region(lua_State * L)
|
||||||
{
|
{
|
||||||
|
@ -286,6 +314,8 @@ bind_region(lua_State * L)
|
||||||
.def_readonly("x", ®ion::x)
|
.def_readonly("x", ®ion::x)
|
||||||
.def_readonly("y", ®ion::y)
|
.def_readonly("y", ®ion::y)
|
||||||
.def_readwrite("age", ®ion::age)
|
.def_readwrite("age", ®ion::age)
|
||||||
|
.def("add_item", ®ion_additem)
|
||||||
|
.property("items", ®ion_items, return_stl_iterator)
|
||||||
.property("plane_id", ®ion_plane)
|
.property("plane_id", ®ion_plane)
|
||||||
.property("units", ®ion_units, return_stl_iterator)
|
.property("units", ®ion_units, return_stl_iterator)
|
||||||
.property("buildings", ®ion_buildings, return_stl_iterator)
|
.property("buildings", ®ion_buildings, return_stl_iterator)
|
||||||
|
|
|
@ -6,4 +6,7 @@
|
||||||
<terrain name="plain" size="1000" shallow="no">
|
<terrain name="plain" size="1000" shallow="no">
|
||||||
</terrain>
|
</terrain>
|
||||||
|
|
||||||
|
<terrain name="mountain" size="200" shallow="yes">
|
||||||
|
</terrain>
|
||||||
|
|
||||||
</terrains>
|
</terrains>
|
||||||
|
|
|
@ -26,6 +26,24 @@ function write_emails()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function update_resources()
|
||||||
|
-- remaining contents of region pool rots
|
||||||
|
-- wood falls from trees
|
||||||
|
local r
|
||||||
|
for r in regions() do
|
||||||
|
local item
|
||||||
|
for item in r.items do
|
||||||
|
local num = math.ceil(r:get_item(item)/2)
|
||||||
|
r:add_item(item, -num)
|
||||||
|
end
|
||||||
|
|
||||||
|
local wood = math.floor(r:get_resource("tree")/20)
|
||||||
|
if wood>0 then
|
||||||
|
r.add_item("log", wood)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function update_owners()
|
function update_owners()
|
||||||
-- update the region's owners. currently uses the owner of
|
-- update the region's owners. currently uses the owner of
|
||||||
-- the largest castle.
|
-- the largest castle.
|
||||||
|
@ -60,6 +78,7 @@ function process(orders)
|
||||||
|
|
||||||
process_orders()
|
process_orders()
|
||||||
update_owners()
|
update_owners()
|
||||||
|
update_resources()
|
||||||
|
|
||||||
-- use newfactions file to place out new players
|
-- use newfactions file to place out new players
|
||||||
autoseed(basepath .. "/newfactions", true)
|
autoseed(basepath .. "/newfactions", true)
|
||||||
|
|
Loading…
Reference in a new issue