2010-08-08 10:06:34 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef H_KRNL_BORDER
|
|
|
|
#define H_KRNL_BORDER
|
|
|
|
|
|
|
|
#include <util/variant.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern unsigned int nextborder;
|
|
|
|
|
|
|
|
typedef struct connection {
|
2011-03-07 08:02:35 +01:00
|
|
|
struct border_type *type; /* the type of this connection */
|
|
|
|
struct connection *next; /* next connection between these regions */
|
|
|
|
struct connection *nexthash; /* next connection between these regions */
|
|
|
|
struct region *from, *to; /* borders can be directed edges */
|
2010-08-08 10:06:34 +02:00
|
|
|
variant data;
|
2011-03-07 08:02:35 +01:00
|
|
|
unsigned int id; /* unique id */
|
2010-08-08 10:06:34 +02:00
|
|
|
} connection;
|
|
|
|
|
|
|
|
typedef struct border_type {
|
2011-03-07 08:02:35 +01:00
|
|
|
const char *__name; /* internal use only */
|
2010-08-08 10:06:34 +02:00
|
|
|
variant_type datatype;
|
2012-06-24 07:41:07 +02:00
|
|
|
bool(*transparent) (const connection *, const struct faction *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* is it possible to see through this? */
|
2011-03-07 08:02:35 +01:00
|
|
|
void (*init) (connection *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* constructor: initialize the connection. allocate extra memory if needed */
|
2011-03-07 08:02:35 +01:00
|
|
|
void (*destroy) (connection *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* destructor: remove all extra memory for destruction */
|
2011-03-07 08:02:35 +01:00
|
|
|
void (*read) (connection *, struct storage *);
|
|
|
|
void (*write) (const connection *, struct storage *);
|
2012-06-24 07:41:07 +02:00
|
|
|
bool(*block) (const connection *, const struct unit *,
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct region * r);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* return true if it blocks movement of u from
|
2011-03-07 08:02:35 +01:00
|
|
|
* r to the opposite struct region.
|
|
|
|
* warning: struct unit may be NULL.
|
|
|
|
*/
|
|
|
|
const char *(*name) (const connection * b, const struct region * r,
|
|
|
|
const struct faction * f, int gflags);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* for example "a wall of fog" or "a doorway from r1 to r2"
|
2011-03-07 08:02:35 +01:00
|
|
|
* may depend on the struct faction, for example "a wall" may
|
|
|
|
* turn out to be "an illusionary wall"
|
|
|
|
*/
|
2012-06-24 07:41:07 +02:00
|
|
|
bool(*rvisible) (const connection *, const struct region *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* is it visible to everyone in r ?
|
2011-03-07 08:02:35 +01:00
|
|
|
* if not, it may still be fvisible() for some f.
|
|
|
|
*/
|
2012-06-24 07:41:07 +02:00
|
|
|
bool(*fvisible) (const connection *, const struct faction *,
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct region *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* is it visible to units of f in r?
|
2011-03-07 08:02:35 +01:00
|
|
|
* the function shall not check for
|
|
|
|
* existence of a struct unit in r. Example: a spell
|
|
|
|
* may be visible only to the struct faction that created it and thus
|
|
|
|
* appear in it's report (if there is a struct unit of f in r, which
|
|
|
|
* the reporting function will have to assure).
|
|
|
|
* if not true, it may still be uvisible() for some u.
|
|
|
|
*/
|
2012-06-24 07:41:07 +02:00
|
|
|
bool(*uvisible) (const connection *, const struct unit *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* is it visible to u ?
|
2011-03-07 08:02:35 +01:00
|
|
|
* a doorway may only be visible to a struct unit with perception > 5
|
|
|
|
*/
|
2012-06-24 07:41:07 +02:00
|
|
|
bool(*valid) (const connection *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* is the connection in a valid state,
|
2011-03-07 08:02:35 +01:00
|
|
|
* or should it be erased at the end of this turn to save space?
|
|
|
|
*/
|
|
|
|
struct region *(*move) (const connection *, struct unit * u,
|
2012-06-24 07:41:07 +02:00
|
|
|
struct region * from, struct region * to, bool routing);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* executed when the units traverses this connection */
|
2011-03-07 08:02:35 +01:00
|
|
|
int (*age) (struct connection *);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* return 0 if connection needs to be removed. >0 if still aging, <0 if not aging */
|
2011-03-07 08:02:35 +01:00
|
|
|
struct border_type *next; /* for internal use only */
|
2010-08-08 10:06:34 +02:00
|
|
|
} border_type;
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
extern connection *find_border(unsigned int id);
|
|
|
|
int resolve_borderid(variant data, void *addr);
|
2010-08-08 10:06:34 +02:00
|
|
|
extern void free_borders(void);
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
extern connection *get_borders(const struct region *r1,
|
|
|
|
const struct region *r2);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* returns the list of borders between r1 and r2 or r2 and r1 */
|
2011-03-07 08:02:35 +01:00
|
|
|
extern connection *new_border(border_type * type, struct region *from,
|
|
|
|
struct region *to);
|
2010-08-08 10:06:34 +02:00
|
|
|
/* creates a connection of the specified type */
|
|
|
|
extern void erase_border(connection * b);
|
|
|
|
/* remove the connection from memory */
|
2011-03-07 08:02:35 +01:00
|
|
|
extern border_type *find_bordertype(const char *name);
|
2010-08-08 10:06:34 +02:00
|
|
|
extern void register_bordertype(border_type * type);
|
|
|
|
/* register a new bordertype */
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
extern int read_borders(struct storage *store);
|
|
|
|
extern void write_borders(struct storage *store);
|
2010-08-08 10:06:34 +02:00
|
|
|
extern void age_borders(void);
|
|
|
|
|
|
|
|
/* provide default implementations for some member functions: */
|
2011-03-07 08:02:35 +01:00
|
|
|
extern void b_read(connection * b, struct storage *store);
|
|
|
|
extern void b_write(const connection * b, struct storage *store);
|
2012-06-24 07:41:07 +02:00
|
|
|
extern bool b_blockall(const connection *, const struct unit *,
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct region *);
|
2012-06-24 07:41:07 +02:00
|
|
|
extern bool b_blocknone(const connection *, const struct unit *,
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct region *);
|
2012-06-24 07:41:07 +02:00
|
|
|
extern bool b_rvisible(const connection *, const struct region *r);
|
|
|
|
extern bool b_fvisible(const connection *, const struct faction *f,
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct region *);
|
2012-06-24 07:41:07 +02:00
|
|
|
extern bool b_uvisible(const connection *, const struct unit *u);
|
|
|
|
extern bool b_rinvisible(const connection *, const struct region *r);
|
|
|
|
extern bool b_finvisible(const connection *, const struct faction *f,
|
2011-03-07 08:02:35 +01:00
|
|
|
const struct region *);
|
2012-06-24 07:41:07 +02:00
|
|
|
extern bool b_uinvisible(const connection *, const struct unit *u);
|
|
|
|
extern bool b_transparent(const connection *, const struct faction *);
|
|
|
|
extern bool b_opaque(const connection *, const struct faction *); /* !transparent */
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
extern border_type bt_fogwall;
|
|
|
|
extern border_type bt_noway;
|
|
|
|
extern border_type bt_wall;
|
|
|
|
extern border_type bt_illusionwall;
|
|
|
|
extern border_type bt_road;
|
|
|
|
extern border_type bt_questportal;
|
|
|
|
|
|
|
|
extern struct attrib_type at_countdown;
|
|
|
|
|
|
|
|
/* game-specific callbacks */
|
2011-03-07 08:02:35 +01:00
|
|
|
extern void (*border_convert_cb) (struct connection * con,
|
|
|
|
struct attrib * attr);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|