2001-01-25 10:37:55 +01:00
|
|
|
|
/* vi: set ts=2:
|
|
|
|
|
*
|
2001-04-14 13:39:14 +02:00
|
|
|
|
*
|
2003-07-29 11:48:03 +02:00
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
2001-01-25 10:37:55 +01:00
|
|
|
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
|
|
|
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
|
|
|
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
|
|
|
|
* Enno Rehling (enno@eressea-pbem.de)
|
|
|
|
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
|
|
|
|
*
|
|
|
|
|
* This program may not be used, modified or distributed without
|
|
|
|
|
* prior permission by the authors of Eressea.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include "eressea.h"
|
|
|
|
|
#include "building.h"
|
2004-06-13 12:21:48 +02:00
|
|
|
|
#include "attrib.h"
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include "item.h"
|
|
|
|
|
#include "curse.h" /* f<>r C_NOCOST */
|
|
|
|
|
#include "unit.h"
|
|
|
|
|
#include "region.h"
|
|
|
|
|
#include "skill.h"
|
2005-07-23 20:18:53 +02:00
|
|
|
|
#include "magic.h"
|
2001-01-25 10:37:55 +01:00
|
|
|
|
#include "save.h"
|
|
|
|
|
|
|
|
|
|
/* util includes */
|
2006-01-27 00:05:40 +01:00
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/event.h>
|
|
|
|
|
#include <util/functions.h>
|
|
|
|
|
#include <util/language.h>
|
|
|
|
|
#include <util/resolve.h>
|
|
|
|
|
#include <util/umlaut.h>
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2005-10-23 13:27:55 +02:00
|
|
|
|
#include <limits.h>
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
/* attributes includes */
|
|
|
|
|
#include <attributes/matmod.h>
|
|
|
|
|
|
2005-01-07 18:02:32 +01:00
|
|
|
|
static const char * NULLSTRING = "(null)";
|
|
|
|
|
|
2004-07-11 01:06:58 +02:00
|
|
|
|
static void
|
|
|
|
|
lc_init(struct attrib *a)
|
|
|
|
|
{
|
|
|
|
|
a->data.v = calloc(1, sizeof(building_action));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
lc_done(struct attrib *a)
|
|
|
|
|
{
|
|
|
|
|
building_action * data = (building_action*)a->data.v;
|
|
|
|
|
if (data->fname) free(data->fname);
|
2005-01-07 18:02:32 +01:00
|
|
|
|
if (data->param) free(data->param);
|
2004-07-11 01:06:58 +02:00
|
|
|
|
free(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
lc_write(const struct attrib * a, FILE* F)
|
|
|
|
|
{
|
|
|
|
|
building_action * data = (building_action*)a->data.v;
|
|
|
|
|
const char * fname = data->fname;
|
2005-01-07 18:02:32 +01:00
|
|
|
|
const char * fparam = data->param;
|
2004-07-11 01:06:58 +02:00
|
|
|
|
building * b = data->b;
|
|
|
|
|
|
|
|
|
|
write_building_reference(b, F);
|
|
|
|
|
fwritestr(F, fname);
|
2005-01-07 18:02:32 +01:00
|
|
|
|
#if RELEASE_VERSION>=BACTION_VERSION
|
2005-03-24 00:39:26 +01:00
|
|
|
|
fputc(' ', F);
|
2005-01-07 18:02:32 +01:00
|
|
|
|
fwritestr(F, fparam?fparam:NULLSTRING);
|
|
|
|
|
#endif
|
2004-07-11 01:06:58 +02:00
|
|
|
|
fputc(' ', F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
lc_read(struct attrib * a, FILE* F)
|
|
|
|
|
{
|
|
|
|
|
char lbuf[256];
|
|
|
|
|
building_action * data = (building_action*)a->data.v;
|
|
|
|
|
|
|
|
|
|
read_building_reference(&data->b, F);
|
|
|
|
|
freadstr(F, lbuf, sizeof(lbuf));
|
|
|
|
|
data->fname = strdup(lbuf);
|
2005-01-07 18:02:32 +01:00
|
|
|
|
if (global.data_version>=BACTION_VERSION) {
|
|
|
|
|
freadstr(F, lbuf, sizeof(lbuf));
|
|
|
|
|
if (strcmp(lbuf, NULLSTRING)==0) data->param = NULL;
|
|
|
|
|
else data->param = strdup(lbuf);
|
|
|
|
|
} else {
|
|
|
|
|
data->param = strdup(NULLSTRING);
|
|
|
|
|
}
|
2004-07-11 01:06:58 +02:00
|
|
|
|
return AT_READ_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrib_type at_building_action = {
|
|
|
|
|
"lcbuilding",
|
|
|
|
|
lc_init, lc_done,
|
|
|
|
|
NULL,
|
|
|
|
|
lc_write, lc_read
|
|
|
|
|
};
|
|
|
|
|
|
2006-02-11 17:11:16 +01:00
|
|
|
|
typedef struct building_typelist {
|
|
|
|
|
struct building_typelist * next;
|
|
|
|
|
building_type * type;
|
|
|
|
|
} building_typelist;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2006-02-11 17:11:16 +01:00
|
|
|
|
static building_typelist *buildingtypes;
|
|
|
|
|
|
|
|
|
|
building_type *
|
2001-01-25 10:37:55 +01:00
|
|
|
|
bt_find(const char* name)
|
|
|
|
|
{
|
|
|
|
|
const struct building_typelist * btl = buildingtypes;
|
2001-04-16 16:34:19 +02:00
|
|
|
|
|
|
|
|
|
if (global.data_version < RELEASE_VERSION) {
|
|
|
|
|
const char * translation[3][2] = {
|
|
|
|
|
{ "illusion", "illusioncastle" },
|
|
|
|
|
{ "generic", "genericbuilding" },
|
|
|
|
|
{ NULL, NULL }
|
|
|
|
|
};
|
|
|
|
|
int i;
|
|
|
|
|
for (i=0;translation[i][0];++i) {
|
|
|
|
|
/* calling a building "illusion" was a bad idea" */
|
|
|
|
|
if (strcmp(translation[i][0], name)==0) {
|
|
|
|
|
name = translation[i][1];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
while (btl && strcasecmp(btl->type->_name, name)) btl = btl->next;
|
|
|
|
|
if (!btl) {
|
|
|
|
|
btl = buildingtypes;
|
|
|
|
|
while (btl && strncasecmp(btl->type->_name, name, strlen(name))) btl = btl->next;
|
|
|
|
|
}
|
|
|
|
|
return btl?btl->type:NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-21 23:25:00 +01:00
|
|
|
|
void
|
2002-03-27 22:49:27 +01:00
|
|
|
|
bt_register(building_type * type)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
struct building_typelist * btl = malloc(sizeof(building_type));
|
2002-03-27 22:49:27 +01:00
|
|
|
|
if (type->init) type->init(type);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
btl->type = type;
|
|
|
|
|
btl->next = buildingtypes;
|
|
|
|
|
buildingtypes = btl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
buildingcapacity(const building * b)
|
|
|
|
|
{
|
|
|
|
|
if (b->type->capacity>=0) {
|
2005-01-19 21:33:13 +01:00
|
|
|
|
if (b->type->maxcapacity>=0) {
|
|
|
|
|
return min(b->type->maxcapacity, b->size * b->type->capacity);
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return b->size * b->type->capacity;
|
|
|
|
|
}
|
2005-01-19 21:33:13 +01:00
|
|
|
|
if (b->size>=b->type->maxsize) {
|
|
|
|
|
if (b->type->maxcapacity>=0) {
|
|
|
|
|
return b->type->maxcapacity;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrib_type at_building_generic_type = {
|
|
|
|
|
"building_generic_type", NULL, NULL, NULL, a_writestring, a_readstring, ATF_UNIQUE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const char *
|
2005-07-23 20:18:53 +02:00
|
|
|
|
buildingtype(const building_type * btype, const building * b, int bsize)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
const char * s = NULL;
|
2005-12-11 16:30:05 +01:00
|
|
|
|
static boolean init_generic = false;
|
2002-03-27 22:49:27 +01:00
|
|
|
|
static const struct building_type * bt_generic;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2005-12-11 16:30:05 +01:00
|
|
|
|
if (!init_generic) {
|
|
|
|
|
init_generic = true;
|
2005-07-23 20:18:53 +02:00
|
|
|
|
bt_generic = bt_find("generic");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (btype == bt_generic) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
const attrib *a = a_find(b->attribs, &at_building_generic_type);
|
|
|
|
|
if (a) s = (const char*)a->data.v;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-10 01:13:39 +01:00
|
|
|
|
if (btype->name) s = btype->name(bsize);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
if (s==NULL) s = btype->_name;
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-26 08:42:58 +02:00
|
|
|
|
#define BMAXHASH 7919
|
2001-01-25 10:37:55 +01:00
|
|
|
|
static building *buildhash[BMAXHASH];
|
|
|
|
|
void
|
|
|
|
|
bhash(building * b)
|
|
|
|
|
{
|
2004-03-28 22:53:47 +02:00
|
|
|
|
building *old = buildhash[b->no % BMAXHASH];
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2004-03-28 22:53:47 +02:00
|
|
|
|
buildhash[b->no % BMAXHASH] = b;
|
|
|
|
|
b->nexthash = old;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
bunhash(building * b)
|
|
|
|
|
{
|
|
|
|
|
building **show;
|
|
|
|
|
|
|
|
|
|
for (show = &buildhash[b->no % BMAXHASH]; *show; show = &(*show)->nexthash) {
|
|
|
|
|
if ((*show)->no == b->no)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (*show) {
|
|
|
|
|
assert(*show == b);
|
|
|
|
|
*show = (*show)->nexthash;
|
|
|
|
|
b->nexthash = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static building *
|
|
|
|
|
bfindhash(int i)
|
|
|
|
|
{
|
|
|
|
|
building *old;
|
|
|
|
|
|
|
|
|
|
for (old = buildhash[i % BMAXHASH]; old; old = old->nexthash)
|
|
|
|
|
if (old->no == i)
|
|
|
|
|
return old;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
building *
|
|
|
|
|
findbuilding(int i)
|
|
|
|
|
{
|
|
|
|
|
return bfindhash(i);
|
|
|
|
|
}
|
|
|
|
|
/* ** old building types ** */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Building: Fortification */
|
|
|
|
|
enum {
|
|
|
|
|
B_SITE,
|
2001-12-10 01:13:39 +01:00
|
|
|
|
B_TRADEPOST,
|
2001-01-25 10:37:55 +01:00
|
|
|
|
B_FORTIFICATION,
|
|
|
|
|
B_TOWER,
|
|
|
|
|
B_CASTLE,
|
|
|
|
|
B_FORTRESS,
|
|
|
|
|
B_CITADEL,
|
|
|
|
|
MAXBUILDINGS
|
|
|
|
|
};
|
|
|
|
|
|
2002-03-27 22:49:27 +01:00
|
|
|
|
static int
|
|
|
|
|
sm_smithy(const unit * u, const region * r, skill_t sk, int value) /* skillmod */
|
|
|
|
|
{
|
|
|
|
|
if (sk==SK_WEAPONSMITH || sk==SK_ARMORER) {
|
|
|
|
|
if (u->region == r) return value + 1;
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
static int
|
|
|
|
|
mm_smithy(const unit * u, const resource_type * rtype, int value) /* material-mod */
|
|
|
|
|
{
|
|
|
|
|
if (rtype == oldresourcetype[R_IRON]) return value * 2;
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
static void
|
|
|
|
|
init_smithy(struct building_type * bt)
|
|
|
|
|
{
|
2004-01-24 12:04:59 +01:00
|
|
|
|
a_add(&bt->attribs, make_skillmod(NOSKILL, SMF_PRODUCTION, sm_smithy, 1.0, 0));
|
2002-03-27 22:49:27 +01:00
|
|
|
|
a_add(&bt->attribs, make_matmod(mm_smithy));
|
|
|
|
|
}
|
2002-03-31 14:04:46 +02:00
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
static const char *
|
2001-12-10 01:13:39 +01:00
|
|
|
|
castle_name(int bsize)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
const char * fname[MAXBUILDINGS] = {
|
|
|
|
|
"site",
|
2001-12-10 01:13:39 +01:00
|
|
|
|
"tradepost",
|
2001-01-25 10:37:55 +01:00
|
|
|
|
"fortification",
|
|
|
|
|
"tower",
|
|
|
|
|
"castle",
|
|
|
|
|
"fortress",
|
|
|
|
|
"citadel" };
|
2002-03-27 22:49:27 +01:00
|
|
|
|
const construction * ctype;
|
|
|
|
|
static const struct building_type * bt_castle;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
int i = 0;
|
2002-03-27 22:49:27 +01:00
|
|
|
|
|
|
|
|
|
if (!bt_castle) bt_castle = bt_find("castle");
|
|
|
|
|
assert(bt_castle);
|
|
|
|
|
ctype = bt_castle->construction;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
while (ctype &&
|
|
|
|
|
ctype->maxsize != -1
|
|
|
|
|
&& ctype->maxsize<=bsize) {
|
|
|
|
|
bsize-=ctype->maxsize;
|
|
|
|
|
ctype=ctype->improvement;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
2001-12-10 01:13:39 +01:00
|
|
|
|
return fname[i];
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-23 13:27:55 +02:00
|
|
|
|
#ifdef WDW_PYRAMID
|
2005-09-11 22:16:04 +02:00
|
|
|
|
|
2005-10-23 13:27:55 +02:00
|
|
|
|
static const char *
|
|
|
|
|
pyramid_name(int bsize)
|
2005-09-11 22:16:04 +02:00
|
|
|
|
{
|
2005-10-23 13:27:55 +02:00
|
|
|
|
static const struct building_type * bt_pyramid;
|
|
|
|
|
static char p_name_buf[32];
|
|
|
|
|
int level=0;
|
|
|
|
|
const construction * ctype;
|
|
|
|
|
|
|
|
|
|
if(!bt_pyramid) bt_pyramid = bt_find("pyramid");
|
|
|
|
|
assert(bt_pyramid);
|
|
|
|
|
|
|
|
|
|
ctype = bt_pyramid->construction;
|
|
|
|
|
|
|
|
|
|
while (ctype && ctype->maxsize != -1 && ctype->maxsize<=bsize) {
|
|
|
|
|
bsize-=ctype->maxsize;
|
|
|
|
|
ctype=ctype->improvement;
|
|
|
|
|
++level;
|
2005-09-11 22:16:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-23 13:27:55 +02:00
|
|
|
|
sprintf(p_name_buf, "pyramid%d", level);
|
|
|
|
|
|
|
|
|
|
return p_name_buf;
|
2005-09-11 22:16:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2005-10-23 13:27:55 +02:00
|
|
|
|
wdw_pyramid_level(const struct building *b)
|
2005-09-11 22:16:04 +02:00
|
|
|
|
{
|
2005-10-23 13:27:55 +02:00
|
|
|
|
const construction *ctype = b->type->construction;
|
|
|
|
|
int completed = b->size;
|
|
|
|
|
int level = 0;
|
|
|
|
|
|
|
|
|
|
while(ctype->improvement != NULL &&
|
|
|
|
|
ctype->improvement != ctype &&
|
|
|
|
|
ctype->maxsize > 0 &&
|
|
|
|
|
ctype->maxsize <= completed)
|
|
|
|
|
{
|
|
|
|
|
++level;
|
|
|
|
|
completed-=ctype->maxsize;
|
|
|
|
|
ctype = ctype->improvement;
|
2005-09-11 22:16:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-23 13:27:55 +02:00
|
|
|
|
return level;
|
2005-09-11 22:16:04 +02:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
/* for finding out what was meant by a particular building string */
|
|
|
|
|
|
|
|
|
|
static local_names * bnames;
|
|
|
|
|
|
|
|
|
|
const building_type *
|
2002-09-02 22:36:12 +02:00
|
|
|
|
findbuildingtype(const char * name, const struct locale * lang)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
2005-06-10 00:10:35 +02:00
|
|
|
|
variant type;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
local_names * bn = bnames;
|
|
|
|
|
|
|
|
|
|
while (bn) {
|
|
|
|
|
if (bn->lang==lang) break;
|
|
|
|
|
bn=bn->next;
|
|
|
|
|
}
|
|
|
|
|
if (!bn) {
|
|
|
|
|
struct building_typelist * btl = buildingtypes;
|
|
|
|
|
bn = calloc(sizeof(local_names), 1);
|
|
|
|
|
bn->next = bnames;
|
|
|
|
|
bn->lang = lang;
|
|
|
|
|
while (btl) {
|
|
|
|
|
const char * n = locale_string(lang, btl->type->_name);
|
2005-06-10 00:10:35 +02:00
|
|
|
|
type.v = (void*)btl->type;
|
|
|
|
|
addtoken(&bn->names, n, type);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
btl=btl->next;
|
|
|
|
|
}
|
|
|
|
|
bnames = bn;
|
|
|
|
|
}
|
2005-06-10 00:10:35 +02:00
|
|
|
|
if (findtoken(&bn->names, name, &type)==E_TOK_NOMATCH) return NULL;
|
|
|
|
|
return (const building_type*)type.v;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-27 22:49:27 +01:00
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
void
|
2002-03-27 22:49:27 +01:00
|
|
|
|
register_buildings(void)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
2002-03-27 22:49:27 +01:00
|
|
|
|
register_function((pf_generic)init_smithy, "init_smithy");
|
|
|
|
|
register_function((pf_generic)castle_name, "castle_name");
|
2005-10-23 13:27:55 +02:00
|
|
|
|
#ifdef WDW_PYRAMID
|
|
|
|
|
register_function((pf_generic)pyramid_name, "pyramid_name");
|
2005-09-11 22:16:04 +02:00
|
|
|
|
#endif
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *
|
2005-06-10 00:10:35 +02:00
|
|
|
|
resolve_building(variant id) {
|
|
|
|
|
return findbuilding(id.i);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2001-05-11 22:19:22 +02:00
|
|
|
|
write_building_reference(const struct building * b, FILE * F)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
|
|
|
|
fprintf(F, "%s ", b?itoa36(b->no):"0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2001-05-11 22:19:22 +02:00
|
|
|
|
read_building_reference(struct building ** b, FILE * F)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
{
|
2005-06-10 00:10:35 +02:00
|
|
|
|
variant var;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
char zText[10];
|
|
|
|
|
fscanf(F, "%s ", zText);
|
2005-06-10 00:10:35 +02:00
|
|
|
|
var.i = atoi36(zText);
|
|
|
|
|
if (var.i==0) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
*b = NULL;
|
2002-04-07 02:44:01 +02:00
|
|
|
|
return AT_READ_FAIL;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2005-06-10 00:10:35 +02:00
|
|
|
|
*b = findbuilding(var.i);
|
|
|
|
|
if (*b==NULL) ur_add(var, (void**)b, resolve_building);
|
2002-04-07 02:44:01 +02:00
|
|
|
|
return AT_READ_OK;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-21 16:09:06 +01:00
|
|
|
|
void
|
|
|
|
|
free_buildinglist(building_list *blist)
|
|
|
|
|
{
|
|
|
|
|
while (blist) {
|
|
|
|
|
building_list * rl2 = blist->next;
|
|
|
|
|
free(blist);
|
|
|
|
|
blist = rl2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
add_buildinglist(building_list **blist, building *b)
|
|
|
|
|
{
|
|
|
|
|
building_list *rl2 = (building_list*)malloc(sizeof(building_list));
|
|
|
|
|
|
|
|
|
|
rl2->data = b;
|
|
|
|
|
rl2->next = *blist;
|
|
|
|
|
|
|
|
|
|
*blist = rl2;
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-25 10:37:55 +01:00
|
|
|
|
building *
|
|
|
|
|
new_building(const struct building_type * btype, region * r, const struct locale * lang)
|
|
|
|
|
{
|
|
|
|
|
building *b = (building *) calloc(1, sizeof(building));
|
|
|
|
|
|
|
|
|
|
b->no = newcontainerid();
|
|
|
|
|
bhash(b);
|
|
|
|
|
|
|
|
|
|
b->type = btype;
|
|
|
|
|
set_string(&b->display, "");
|
|
|
|
|
b->region = r;
|
|
|
|
|
addlist(&r->buildings, b);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
static char buffer[IDSIZE + 1 + NAMESIZE + 1];
|
2002-03-27 22:49:27 +01:00
|
|
|
|
if (b->type->name)
|
2001-12-10 01:13:39 +01:00
|
|
|
|
sprintf(buffer, "%s", locale_string(lang, btype->_name));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
else
|
2005-07-23 20:18:53 +02:00
|
|
|
|
sprintf(buffer, "%s", LOC(lang, buildingtype(btype, b, 0)));
|
2001-01-25 10:37:55 +01:00
|
|
|
|
set_string(&b->name, buffer);
|
|
|
|
|
}
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
destroy_building(building * b)
|
|
|
|
|
{
|
2006-01-29 02:55:36 +01:00
|
|
|
|
unit *u;
|
2004-10-17 23:44:26 +02:00
|
|
|
|
direction_t d;
|
|
|
|
|
static const struct building_type * bt_caravan, * bt_dam, * bt_tunnel;
|
|
|
|
|
boolean init = false;
|
|
|
|
|
|
|
|
|
|
if (!init) {
|
|
|
|
|
init = true;
|
|
|
|
|
bt_caravan = bt_find("caravan");
|
|
|
|
|
bt_dam = bt_find("dam");
|
|
|
|
|
bt_tunnel = bt_find("tunnel");
|
|
|
|
|
}
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
2006-01-29 02:55:36 +01:00
|
|
|
|
if (!bfindhash(b->no)) return;
|
|
|
|
|
for (u=b->region->units; u; u=u->next) {
|
|
|
|
|
if (u->building == b) leave(b->region, u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b->size = 0;
|
|
|
|
|
update_lighthouse(b);
|
|
|
|
|
bunhash(b);
|
|
|
|
|
|
2004-10-17 23:44:26 +02:00
|
|
|
|
/* Falls Karawanserei, Damm oder Tunnel einst<73>rzen, wird die schon
|
|
|
|
|
* gebaute Stra<EFBFBD>e zur H<EFBFBD>lfte vernichtet */
|
|
|
|
|
if (b->type == bt_caravan || b->type == bt_dam || b->type == bt_tunnel) {
|
|
|
|
|
region * r = b->region;
|
|
|
|
|
for (d=0;d!=MAXDIRECTIONS;++d) if (rroad(r, d) > 0) {
|
|
|
|
|
rsetroad(r, d, rroad(r, d) / 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-29 02:55:36 +01:00
|
|
|
|
/* Stattdessen nur aus Liste entfernen, aber im Speicher halten. */
|
|
|
|
|
choplist(&b->region->buildings, b);
|
2006-08-12 21:15:16 +02:00
|
|
|
|
handle_event(b->attribs, "destroy", b);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern attrib_type at_icastle;
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
buildingeffsize(const building * b, boolean img)
|
|
|
|
|
{
|
|
|
|
|
int i = b->size, n = 0;
|
2002-03-27 22:49:27 +01:00
|
|
|
|
const construction * cons;
|
|
|
|
|
static const struct building_type * bt_castle;
|
|
|
|
|
if (!bt_castle) bt_castle = bt_find("castle");
|
|
|
|
|
assert(bt_castle);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
|
|
|
|
|
if (b==NULL) return 0;
|
|
|
|
|
|
2002-03-27 22:49:27 +01:00
|
|
|
|
if (b->type!=bt_castle) {
|
2001-01-25 10:37:55 +01:00
|
|
|
|
if (img) {
|
|
|
|
|
const attrib * a = a_find(b->attribs, &at_icastle);
|
2002-03-27 22:49:27 +01:00
|
|
|
|
if (!a || a->data.v != bt_castle) return 0;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
} else return 0;
|
|
|
|
|
}
|
2002-03-27 22:49:27 +01:00
|
|
|
|
cons = bt_castle->construction;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
assert(cons);
|
|
|
|
|
|
|
|
|
|
while (cons && cons->maxsize != -1 && i>=cons->maxsize) {
|
|
|
|
|
i-=cons->maxsize;
|
|
|
|
|
cons = cons->improvement;
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-27 22:49:27 +01:00
|
|
|
|
return n;
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unit *
|
|
|
|
|
buildingowner(const region * r, const building * b)
|
|
|
|
|
{
|
|
|
|
|
unit *u = NULL;
|
|
|
|
|
unit *first = NULL;
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
#ifndef BROKEN_OWNERS
|
2001-01-25 10:37:55 +01:00
|
|
|
|
assert(r == b->region);
|
- Neue Messages fertig
Messages werden jetzt in einem anderen Meta-Format (message* of
message_type*) gespeichert, das man in beliebige Formate (CR oder NR)
rendern kann. crmessage.c und nrmessage.c sind die render-engines dafür.
Die Messagetypen werden in res/{de,en}/messages.xml gesammelt, ultimativ
kann das aber durchaus eine einzelne Datei sein. Die ist derzeit nicht
wirklich xml (Umlaute drin, keine Definitionsdatei), aber gut lesbar.
- make_message
Diese Funktion ersetzt new_message, und ist etwas einfacher in der Syntax:
make_message("dumb_mistake", "unit region command", u, r, cmd) erzeugt
eine neue Nachricht, die dann einfach mit add_message wie bisher an die
Nachrichtenliste gehängt werden kann.
TODO: Messages könnte man durchaus reference-counten, und in mehrere Listen
einfügen, solang sie a) mehrfachverwendet (Kampf!) und b) vom Betrachter
unabhängig sind. Das spart einigen Speicher.
- CR Version erhöht.
Weil die MESSAGETYPES Blocks anders sind als früher
- OFFENSIVE_DELAY
Verbietet Einheiten, deren Partei eine Reigon niht bewachen, den
Angriff in der Region, wenn sie sich in der Runde zuvor bewegt haben.
Status der letzten Runde wird in neuem Attribut at_moved gespeichert.
- SHORT_ATTACKS
ein define, das angibt ob Kämpfen grundsätzlich keine lange Aktion ist.
- XML Parser
xml.[hc] enthält einen XML-Parser, dem man ein plugin mit callbacks
übergibt, die nach dem Parsen eines tokens aufgerufen werden.
2001-04-12 19:21:57 +02:00
|
|
|
|
#endif
|
2001-01-25 10:37:55 +01:00
|
|
|
|
/* Pr<50>fen ob Eigent<6E>mer am leben. */
|
|
|
|
|
|
|
|
|
|
for (u = r->units; u; u = u->next) {
|
|
|
|
|
if (u->building == b) {
|
|
|
|
|
if (!first && u->number > 0)
|
|
|
|
|
first = u;
|
2003-07-29 11:48:03 +02:00
|
|
|
|
if (fval(u, UFL_OWNER) && u->number > 0)
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return u;
|
|
|
|
|
if (u->number == 0)
|
2003-07-29 11:48:03 +02:00
|
|
|
|
freset(u, UFL_OWNER);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Eigent<6E>mer tot oder kein Eigent<6E>mer vorhanden. Erste lebende Einheit
|
|
|
|
|
* nehmen. */
|
|
|
|
|
|
|
|
|
|
if (first)
|
2003-07-29 11:48:03 +02:00
|
|
|
|
fset(first, UFL_OWNER);
|
2001-01-25 10:37:55 +01:00
|
|
|
|
return first;
|
|
|
|
|
}
|