forked from github/server
renaming border->connection (f*cking curses!)
added a callback mechanism to make region info displayable from Lua. Awesome.
This commit is contained in:
parent
8ffafd2815
commit
60e99b9a00
23 changed files with 270 additions and 192 deletions
|
@ -6,7 +6,7 @@
|
|||
#include "common/kernel/alliance.c"
|
||||
#include "common/kernel/battle.c"
|
||||
#include "common/kernel/binarystore.c"
|
||||
#include "common/kernel/border.c"
|
||||
#include "common/kernel/connection.c"
|
||||
#include "common/kernel/build.c"
|
||||
#include "common/kernel/building.c"
|
||||
#include "common/kernel/calendar.c"
|
||||
|
|
|
@ -33,7 +33,7 @@ without prior permission by the authors of Eressea.
|
|||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/group.h>
|
||||
|
@ -1045,7 +1045,7 @@ cr_borders(seen_region ** seen, const region * r, const faction * f, int seemode
|
|||
for (d = 0; d != MAXDIRECTIONS; d++)
|
||||
{ /* Nachbarregionen, die gesehen werden, ermitteln */
|
||||
const region * r2 = rconnect(r, d);
|
||||
const border * b;
|
||||
const connection * b;
|
||||
if (!r2) continue;
|
||||
if (seemode==see_neighbour) {
|
||||
seen_region * sr = find_seen(seen, r2);
|
||||
|
@ -1069,7 +1069,7 @@ cr_borders(seen_region ** seen, const region * r, const faction * f, int seemode
|
|||
}
|
||||
}
|
||||
if (cs) {
|
||||
const char * bname = mkname("border", b->type->name(b, r, f, GF_PURE));
|
||||
const char * bname = mkname("connection", b->type->name(b, r, f, GF_PURE));
|
||||
fprintf(F, "GRENZE %d\n", ++g);
|
||||
fprintf(F, "\"%s\";typ\n", LOC(default_locale, bname));
|
||||
fprintf(F, "%d;richtung\n", d);
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/battle.h>
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/faction.h>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
|
@ -809,7 +809,7 @@ prices(FILE * F, const region * r, const faction * f)
|
|||
}
|
||||
|
||||
boolean
|
||||
see_border(const border * b, const faction * f, const region * r)
|
||||
see_border(const connection * b, const faction * f, const region * r)
|
||||
{
|
||||
boolean cs = b->type->fvisible(b, f, r);
|
||||
if (!cs) {
|
||||
|
@ -856,7 +856,7 @@ describe(FILE * F, const seen_region * sr, faction * f)
|
|||
for (d = 0; d != MAXDIRECTIONS; d++) {
|
||||
/* Nachbarregionen, die gesehen werden, ermitteln */
|
||||
region *r2 = rconnect(r, d);
|
||||
border *b;
|
||||
connection *b;
|
||||
see[d] = true;
|
||||
if (!r2) continue;
|
||||
for (b=get_borders(r, r2);b;) {
|
||||
|
|
|
@ -31,7 +31,7 @@ without prior permission by the authors of Eressea.
|
|||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/group.h>
|
||||
|
|
|
@ -256,14 +256,6 @@
|
|||
RelativePath=".\kernel\binarystore.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\kernel\border.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\kernel\border.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\kernel\build.c"
|
||||
>
|
||||
|
@ -296,6 +288,14 @@
|
|||
RelativePath=".\kernel\command.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\kernel\connection.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\kernel\connection.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\kernel\curse.c"
|
||||
>
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
/* kernel includes */
|
||||
#include "alchemy.h"
|
||||
#include "alliance.h"
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
#include "building.h"
|
||||
#include "curse.h"
|
||||
#include "faction.h"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
|
||||
#include "region.h"
|
||||
#include "save.h"
|
||||
|
@ -38,7 +38,7 @@
|
|||
unsigned int nextborder = 0;
|
||||
|
||||
#define BORDER_MAXHASH 8191
|
||||
border * borders[BORDER_MAXHASH];
|
||||
connection * borders[BORDER_MAXHASH];
|
||||
border_type * bordertypes;
|
||||
|
||||
|
||||
|
@ -48,10 +48,10 @@ free_borders(void)
|
|||
int i;
|
||||
for (i=0;i!=BORDER_MAXHASH;++i) {
|
||||
while (borders[i]) {
|
||||
border * b = borders[i];
|
||||
connection * b = borders[i];
|
||||
borders[i] = b->nexthash;
|
||||
while (b) {
|
||||
border * bf = b;
|
||||
connection * bf = b;
|
||||
b = b->next;
|
||||
assert(b==NULL || b->nexthash==NULL);
|
||||
if (bf->type->destroy) {
|
||||
|
@ -63,14 +63,14 @@ free_borders(void)
|
|||
}
|
||||
}
|
||||
|
||||
border *
|
||||
connection *
|
||||
find_border(unsigned int id)
|
||||
{
|
||||
int key;
|
||||
for (key=0;key!=BORDER_MAXHASH;key++) {
|
||||
border * bhash;
|
||||
connection * bhash;
|
||||
for (bhash=borders[key];bhash!=NULL;bhash=bhash->nexthash) {
|
||||
border * b;
|
||||
connection * b;
|
||||
for (b=bhash;b;b=b->next) {
|
||||
if (b->id==id) return b;
|
||||
}
|
||||
|
@ -83,48 +83,48 @@ int
|
|||
resolve_borderid(variant id, void * addr)
|
||||
{
|
||||
int result = 0;
|
||||
border * b = NULL;
|
||||
connection * b = NULL;
|
||||
if (id.i!=0) {
|
||||
b = find_border(id.i);
|
||||
if (b==NULL) {
|
||||
result = -1;
|
||||
}
|
||||
}
|
||||
*(border**)addr = b;
|
||||
*(connection**)addr = b;
|
||||
return result;
|
||||
}
|
||||
|
||||
static border **
|
||||
static connection **
|
||||
get_borders_i(const region * r1, const region * r2)
|
||||
{
|
||||
border ** bp;
|
||||
connection ** bp;
|
||||
int key = reg_hashkey(r1);
|
||||
int k2 = reg_hashkey(r2);
|
||||
|
||||
key = MIN(k2, key) % BORDER_MAXHASH;
|
||||
bp = &borders[key];
|
||||
while (*bp) {
|
||||
border * b = *bp;
|
||||
connection * b = *bp;
|
||||
if ((b->from==r1 && b->to==r2) || (b->from==r2 && b->to==r1)) break;
|
||||
bp = &b->nexthash;
|
||||
}
|
||||
return bp;
|
||||
}
|
||||
|
||||
border *
|
||||
connection *
|
||||
get_borders(const region * r1, const region * r2)
|
||||
{
|
||||
border ** bp = get_borders_i(r1, r2);
|
||||
connection ** bp = get_borders_i(r1, r2);
|
||||
return *bp;
|
||||
}
|
||||
|
||||
border *
|
||||
connection *
|
||||
new_border(border_type * type, region * from, region * to)
|
||||
{
|
||||
border * b = calloc(1, sizeof(struct border));
|
||||
connection * b = calloc(1, sizeof(struct connection));
|
||||
|
||||
if (from && to) {
|
||||
border ** bp = get_borders_i(from, to);
|
||||
connection ** bp = get_borders_i(from, to);
|
||||
while (*bp) bp = &(*bp)->next;
|
||||
*bp = b;
|
||||
}
|
||||
|
@ -138,11 +138,11 @@ new_border(border_type * type, region * from, region * to)
|
|||
}
|
||||
|
||||
void
|
||||
erase_border(border * b)
|
||||
erase_border(connection * b)
|
||||
{
|
||||
if (b->from && b->to) {
|
||||
border ** bp = get_borders_i(b->from, b->to);
|
||||
assert(*bp!=NULL || !"error: border is not registered");
|
||||
connection ** bp = get_borders_i(b->from, b->to);
|
||||
assert(*bp!=NULL || !"error: connection is not registered");
|
||||
if (*bp==b) {
|
||||
/* it is the first in the list, so it is in the nexthash list */
|
||||
if (b->next) {
|
||||
|
@ -155,7 +155,7 @@ erase_border(border * b)
|
|||
while (*bp && *bp != b) {
|
||||
bp = &(*bp)->next;
|
||||
}
|
||||
assert(*bp==b || !"error: border is not registered");
|
||||
assert(*bp==b || !"error: connection is not registered");
|
||||
*bp = b->next;
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +186,7 @@ find_bordertype(const char * name)
|
|||
}
|
||||
|
||||
void
|
||||
b_read(border * b, storage * store)
|
||||
b_read(connection * b, storage * store)
|
||||
{
|
||||
int result = 0;
|
||||
switch (b->type->datatype) {
|
||||
|
@ -200,14 +200,14 @@ b_read(border * b, storage * store)
|
|||
break;
|
||||
case VAR_VOIDPTR:
|
||||
default:
|
||||
assert(!"invalid variant type in border");
|
||||
assert(!"invalid variant type in connection");
|
||||
result = 0;
|
||||
}
|
||||
assert(result>=0 || "EOF encountered?");
|
||||
}
|
||||
|
||||
void
|
||||
b_write(const border * b, storage * store)
|
||||
b_write(const connection * b, storage * store)
|
||||
{
|
||||
switch (b->type->datatype) {
|
||||
case VAR_NONE:
|
||||
|
@ -220,20 +220,20 @@ b_write(const border * b, storage * store)
|
|||
break;
|
||||
case VAR_VOIDPTR:
|
||||
default:
|
||||
assert(!"invalid variant type in border");
|
||||
assert(!"invalid variant type in connection");
|
||||
}
|
||||
}
|
||||
|
||||
boolean b_transparent(const border * b, const struct faction * f) { unused(b); unused(f); return true; }
|
||||
boolean b_opaque(const border * b, const struct faction * f) { unused(b); unused(f); return false; }
|
||||
boolean b_blockall(const border * b, const unit * u, const region * r) { unused(u); unused(r); unused(b); return true; }
|
||||
boolean b_blocknone(const border * b, const unit * u, const region * r) { unused(u); unused(r); unused(b); return false; }
|
||||
boolean b_rvisible(const border * b, const region * r) { return (boolean)(b->to==r || b->from==r); }
|
||||
boolean b_fvisible(const border * b, const struct faction * f, const region * r) { unused(r); unused(f); unused(b); return true; }
|
||||
boolean b_uvisible(const border * b, const unit * u) { unused(u); unused(b); return true; }
|
||||
boolean b_rinvisible(const border * b, const region * r) { unused(r); unused(b); return false; }
|
||||
boolean b_finvisible(const border * b, const struct faction * f, const region * r) { unused(r); unused(f); unused(b); return false; }
|
||||
boolean b_uinvisible(const border * b, const unit * u) { unused(u); unused(b); return false; }
|
||||
boolean b_transparent(const connection * b, const struct faction * f) { unused(b); unused(f); return true; }
|
||||
boolean b_opaque(const connection * b, const struct faction * f) { unused(b); unused(f); return false; }
|
||||
boolean b_blockall(const connection * b, const unit * u, const region * r) { unused(u); unused(r); unused(b); return true; }
|
||||
boolean b_blocknone(const connection * b, const unit * u, const region * r) { unused(u); unused(r); unused(b); return false; }
|
||||
boolean b_rvisible(const connection * b, const region * r) { return (boolean)(b->to==r || b->from==r); }
|
||||
boolean b_fvisible(const connection * b, const struct faction * f, const region * r) { unused(r); unused(f); unused(b); return true; }
|
||||
boolean b_uvisible(const connection * b, const unit * u) { unused(u); unused(b); return true; }
|
||||
boolean b_rinvisible(const connection * b, const region * r) { unused(r); unused(b); return false; }
|
||||
boolean b_finvisible(const connection * b, const struct faction * f, const region * r) { unused(r); unused(f); unused(b); return false; }
|
||||
boolean b_uinvisible(const connection * b, const unit * u) { unused(u); unused(b); return false; }
|
||||
|
||||
/**************************************/
|
||||
/* at_countdown - legacy, do not use */
|
||||
|
@ -255,9 +255,9 @@ age_borders(void)
|
|||
int i;
|
||||
|
||||
for (i=0;i!=BORDER_MAXHASH;++i) {
|
||||
border * bhash = borders[i];
|
||||
connection * bhash = borders[i];
|
||||
for (;bhash;bhash=bhash->nexthash) {
|
||||
border * b = bhash;
|
||||
connection * b = bhash;
|
||||
for (;b;b=b->next) {
|
||||
if (b->type->age) {
|
||||
if (b->type->age(b)==AT_AGE_REMOVE) {
|
||||
|
@ -272,7 +272,7 @@ age_borders(void)
|
|||
}
|
||||
while (deleted) {
|
||||
border_list * blist = deleted->next;
|
||||
border * b = deleted->data;
|
||||
connection * b = deleted->data;
|
||||
erase_border(b);
|
||||
free(deleted);
|
||||
deleted = blist;
|
||||
|
@ -287,7 +287,7 @@ age_borders(void)
|
|||
#include "faction.h"
|
||||
|
||||
static const char *
|
||||
b_namewall(const border * b, const region * r, const struct faction * f, int gflags)
|
||||
b_namewall(const connection * b, const region * r, const struct faction * f, int gflags)
|
||||
{
|
||||
const char * bname = "wall";
|
||||
|
||||
|
@ -296,7 +296,7 @@ b_namewall(const border * b, const region * r, const struct faction * f, int gfl
|
|||
unused(b);
|
||||
if (gflags & GF_ARTICLE) bname = "a_wall";
|
||||
if (gflags & GF_PURE) return bname;
|
||||
return LOC(f->locale, mkname("border", bname));
|
||||
return LOC(f->locale, mkname("connection", bname));
|
||||
}
|
||||
|
||||
border_type bt_wall = {
|
||||
|
@ -328,18 +328,18 @@ border_type bt_noway = {
|
|||
};
|
||||
|
||||
static const char *
|
||||
b_namefogwall(const border * b, const region * r, const struct faction * f, int gflags)
|
||||
b_namefogwall(const connection * b, const region * r, const struct faction * f, int gflags)
|
||||
{
|
||||
unused(f);
|
||||
unused(b);
|
||||
unused(r);
|
||||
if (gflags & GF_PURE) return "fogwall";
|
||||
if (gflags & GF_ARTICLE) return LOC(f->locale, mkname("border", "a_fogwall"));
|
||||
return LOC(f->locale, mkname("border", "fogwall"));
|
||||
if (gflags & GF_ARTICLE) return LOC(f->locale, mkname("connection", "a_fogwall"));
|
||||
return LOC(f->locale, mkname("connection", "fogwall"));
|
||||
}
|
||||
|
||||
static boolean
|
||||
b_blockfogwall(const border * b, const unit * u, const region * r)
|
||||
b_blockfogwall(const connection * b, const unit * u, const region * r)
|
||||
{
|
||||
unused(b);
|
||||
unused(r);
|
||||
|
@ -363,16 +363,16 @@ border_type bt_fogwall = {
|
|||
};
|
||||
|
||||
static const char *
|
||||
b_nameillusionwall(const border * b, const region * r, const struct faction * f, int gflags)
|
||||
b_nameillusionwall(const connection * b, const region * r, const struct faction * f, int gflags)
|
||||
{
|
||||
int fno = b->data.i;
|
||||
unused(b);
|
||||
unused(r);
|
||||
if (gflags & GF_PURE) return (f && fno==f->no)?"illusionwall":"wall";
|
||||
if (gflags & GF_ARTICLE) {
|
||||
return LOC(f->locale, mkname("border", (f && fno==f->subscription)?"an_illusionwall":"a_wall"));
|
||||
return LOC(f->locale, mkname("connection", (f && fno==f->subscription)?"an_illusionwall":"a_wall"));
|
||||
}
|
||||
return LOC(f->locale, mkname("border", (f && fno==f->no)?"illusionwall":"wall"));
|
||||
return LOC(f->locale, mkname("connection", (f && fno==f->no)?"illusionwall":"wall"));
|
||||
}
|
||||
|
||||
border_type bt_illusionwall = {
|
||||
|
@ -393,13 +393,13 @@ border_type bt_illusionwall = {
|
|||
* special quest door
|
||||
***/
|
||||
|
||||
boolean b_blockquestportal(const border * b, const unit * u, const region * r) {
|
||||
boolean b_blockquestportal(const connection * b, const unit * u, const region * r) {
|
||||
if(b->data.i > 0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char *
|
||||
b_namequestportal(const border * b, const region * r, const struct faction * f, int gflags)
|
||||
b_namequestportal(const connection * b, const region * r, const struct faction * f, int gflags)
|
||||
{
|
||||
const char * bname;
|
||||
int lock = b->data.i;
|
||||
|
@ -420,7 +420,7 @@ b_namequestportal(const border * b, const region * r, const struct faction * f,
|
|||
}
|
||||
}
|
||||
if (gflags & GF_PURE) return bname;
|
||||
return LOC(f->locale, mkname("border", bname));
|
||||
return LOC(f->locale, mkname("connection", bname));
|
||||
}
|
||||
|
||||
border_type bt_questportal = {
|
||||
|
@ -442,7 +442,7 @@ border_type bt_questportal = {
|
|||
***/
|
||||
|
||||
static const char *
|
||||
b_nameroad(const border * b, const region * r, const struct faction * f, int gflags)
|
||||
b_nameroad(const connection * b, const region * r, const struct faction * f, int gflags)
|
||||
{
|
||||
region * r2 = (r==b->to)?b->from:b->to;
|
||||
int local = (r==b->from)?b->data.sa[0]:b->data.sa[1];
|
||||
|
@ -451,51 +451,51 @@ b_nameroad(const border * b, const region * r, const struct faction * f, int gfl
|
|||
unused(f);
|
||||
if (gflags & GF_PURE) return "road";
|
||||
if (gflags & GF_ARTICLE) {
|
||||
if (!(gflags & GF_DETAILED)) return LOC(f->locale, mkname("border", "a_road"));
|
||||
if (!(gflags & GF_DETAILED)) return LOC(f->locale, mkname("connection", "a_road"));
|
||||
else if (r->terrain->max_road<=local) {
|
||||
int remote = (r2==b->from)?b->data.sa[0]:b->data.sa[1];
|
||||
if (r2->terrain->max_road<=remote) {
|
||||
return LOC(f->locale, mkname("border", "a_road"));
|
||||
return LOC(f->locale, mkname("connection", "a_road"));
|
||||
} else {
|
||||
return LOC(f->locale, mkname("border", "an_incomplete_road"));
|
||||
return LOC(f->locale, mkname("connection", "an_incomplete_road"));
|
||||
}
|
||||
} else {
|
||||
int percent = MAX(1, 100*local/r->terrain->max_road);
|
||||
if (local) {
|
||||
snprintf(buffer, sizeof(buffer), LOC(f->locale, mkname("border", "a_road_percent")), percent);
|
||||
snprintf(buffer, sizeof(buffer), LOC(f->locale, mkname("connection", "a_road_percent")), percent);
|
||||
} else {
|
||||
return LOC(f->locale, mkname("border", "a_road_connection"));
|
||||
return LOC(f->locale, mkname("connection", "a_road_connection"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gflags & GF_PLURAL) return LOC(f->locale, mkname("border", "roads"));
|
||||
else return LOC(f->locale, mkname("border", "road"));
|
||||
else if (gflags & GF_PLURAL) return LOC(f->locale, mkname("connection", "roads"));
|
||||
else return LOC(f->locale, mkname("connection", "road"));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static void
|
||||
b_readroad(border * b, storage * store)
|
||||
b_readroad(connection * b, storage * store)
|
||||
{
|
||||
b->data.sa[0] = (short)store->r_int(store);
|
||||
b->data.sa[1] = (short)store->r_int(store);
|
||||
}
|
||||
|
||||
static void
|
||||
b_writeroad(const border * b, storage * store)
|
||||
b_writeroad(const connection * b, storage * store)
|
||||
{
|
||||
store->w_int(store, b->data.sa[0]);
|
||||
store->w_int(store, b->data.sa[1]);
|
||||
}
|
||||
|
||||
static boolean
|
||||
b_validroad(const border * b)
|
||||
b_validroad(const connection * b)
|
||||
{
|
||||
if (b->data.sa[0]==SHRT_MAX) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean
|
||||
b_rvisibleroad(const border * b, const region * r)
|
||||
b_rvisibleroad(const connection * b, const region * r)
|
||||
{
|
||||
int x = b->data.i;
|
||||
x = (r==b->from)?b->data.sa[0]:b->data.sa[1];
|
||||
|
@ -528,9 +528,9 @@ write_borders(struct storage * store)
|
|||
{
|
||||
int i;
|
||||
for (i=0;i!=BORDER_MAXHASH;++i) {
|
||||
border * bhash;
|
||||
connection * bhash;
|
||||
for (bhash=borders[i];bhash;bhash=bhash->nexthash) {
|
||||
border * b;
|
||||
connection * b;
|
||||
for (b=bhash;b!=NULL;b=b->next) {
|
||||
if (b->type->valid && !b->type->valid(b)) continue;
|
||||
store->w_tok(store, b->type->__name);
|
||||
|
@ -552,7 +552,7 @@ read_borders(struct storage * store)
|
|||
for (;;) {
|
||||
unsigned int bid = 0;
|
||||
char zText[32];
|
||||
border * b;
|
||||
connection * b;
|
||||
region * from, * to;
|
||||
border_type * type;
|
||||
|
||||
|
@ -576,9 +576,9 @@ read_borders(struct storage * store)
|
|||
|
||||
type = find_bordertype(zText);
|
||||
if (type==NULL) {
|
||||
log_error(("[read_borders] unknown border type %s in %s\n", zText,
|
||||
log_error(("[read_borders] unknown connection type %s in %s\n", zText,
|
||||
regionname(from, NULL)));
|
||||
assert(type || !"border type not registered");
|
||||
assert(type || !"connection type not registered");
|
||||
}
|
||||
|
||||
if (to==from && type && from) {
|
|
@ -23,46 +23,46 @@ extern "C" {
|
|||
|
||||
extern unsigned int nextborder;
|
||||
|
||||
typedef struct border {
|
||||
struct border_type * type; /* the type of this border */
|
||||
struct border * next; /* next border between these regions */
|
||||
struct border * nexthash; /* next border between these regions */
|
||||
typedef struct connection {
|
||||
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 */
|
||||
variant data;
|
||||
unsigned int id; /* unique id */
|
||||
} border;
|
||||
} connection;
|
||||
|
||||
typedef struct border_list {
|
||||
struct border_list * next;
|
||||
struct border * data;
|
||||
struct connection * data;
|
||||
} border_list;
|
||||
|
||||
typedef struct border_type {
|
||||
const char* __name; /* internal use only */
|
||||
variant_type datatype;
|
||||
boolean (*transparent)(const border *, const struct faction *);
|
||||
boolean (*transparent)(const connection *, const struct faction *);
|
||||
/* is it possible to see through this? */
|
||||
void (*init)(border *);
|
||||
/* constructor: initialize the border. allocate extra memory if needed */
|
||||
void (*destroy)(border *);
|
||||
void (*init)(connection *);
|
||||
/* constructor: initialize the connection. allocate extra memory if needed */
|
||||
void (*destroy)(connection *);
|
||||
/* destructor: remove all extra memory for destruction */
|
||||
void (*read)(border *, struct storage *);
|
||||
void (*write)(const border *, struct storage *);
|
||||
boolean (*block)(const border *, const struct unit *, const struct region * r);
|
||||
void (*read)(connection *, struct storage *);
|
||||
void (*write)(const connection *, struct storage *);
|
||||
boolean (*block)(const connection *, const struct unit *, const struct region * r);
|
||||
/* return true if it blocks movement of u from
|
||||
* r to the opposite struct region.
|
||||
* warning: struct unit may be NULL.
|
||||
*/
|
||||
const char *(*name)(const border * b, const struct region * r, const struct faction * f, int gflags);
|
||||
const char *(*name)(const connection * b, const struct region * r, const struct faction * f, int gflags);
|
||||
/* for example "a wall of fog" or "a doorway from r1 to r2"
|
||||
* may depend on the struct faction, for example "a wall" may
|
||||
* turn out to be "an illusionary wall"
|
||||
*/
|
||||
boolean (*rvisible)(const border *, const struct region *);
|
||||
boolean (*rvisible)(const connection *, const struct region *);
|
||||
/* is it visible to everyone in r ?
|
||||
* if not, it may still be fvisible() for some f.
|
||||
*/
|
||||
boolean (*fvisible)(const border *, const struct faction *, const struct region *);
|
||||
boolean (*fvisible)(const connection *, const struct faction *, const struct region *);
|
||||
/* is it visible to units of f in r?
|
||||
* the function shall not check for
|
||||
* existence of a struct unit in r. Example: a spell
|
||||
|
@ -71,32 +71,32 @@ extern "C" {
|
|||
* the reporting function will have to assure).
|
||||
* if not true, it may still be uvisible() for some u.
|
||||
*/
|
||||
boolean (*uvisible)(const border *, const struct unit *);
|
||||
boolean (*uvisible)(const connection *, const struct unit *);
|
||||
/* is it visible to u ?
|
||||
* a doorway may only be visible to a struct unit with perception > 5
|
||||
*/
|
||||
boolean (*valid)(const border *);
|
||||
/* is the border in a valid state,
|
||||
boolean (*valid)(const connection *);
|
||||
/* is the connection in a valid state,
|
||||
* or should it be erased at the end of this turn to save space?
|
||||
*/
|
||||
struct region * (*move)(const border *, struct unit * u, struct region * from, struct region * to, boolean routing);
|
||||
/* executed when the units traverses this border */
|
||||
int (*age)(struct border *);
|
||||
/* return 0 if border needs to be removed. >0 if still aging, <0 if not aging */
|
||||
struct region * (*move)(const connection *, struct unit * u, struct region * from, struct region * to, boolean routing);
|
||||
/* executed when the units traverses this connection */
|
||||
int (*age)(struct connection *);
|
||||
/* return 0 if connection needs to be removed. >0 if still aging, <0 if not aging */
|
||||
struct border_type * next; /* for internal use only */
|
||||
} border_type;
|
||||
|
||||
|
||||
extern border * find_border(unsigned int id);
|
||||
extern connection * find_border(unsigned int id);
|
||||
int resolve_borderid(variant data, void * addr);
|
||||
extern void free_borders(void);
|
||||
|
||||
extern border * get_borders(const struct region * r1, const struct region * r2);
|
||||
extern connection * get_borders(const struct region * r1, const struct region * r2);
|
||||
/* returns the list of borders between r1 and r2 or r2 and r1 */
|
||||
extern border * new_border(border_type * type, struct region * from, struct region * to);
|
||||
/* creates a border of the specified type */
|
||||
extern void erase_border(border * b);
|
||||
/* remove the border from memory */
|
||||
extern connection * new_border(border_type * type, struct region * from, struct region * to);
|
||||
/* creates a connection of the specified type */
|
||||
extern void erase_border(connection * b);
|
||||
/* remove the connection from memory */
|
||||
extern border_type * find_bordertype(const char * name);
|
||||
extern void register_bordertype(border_type * type);
|
||||
/* register a new bordertype */
|
||||
|
@ -106,18 +106,18 @@ extern "C" {
|
|||
extern void age_borders(void);
|
||||
|
||||
/* provide default implementations for some member functions: */
|
||||
extern void b_read(border * b, struct storage * store);
|
||||
extern void b_write(const border * b, struct storage * store);
|
||||
extern boolean b_blockall(const border *, const struct unit *, const struct region *);
|
||||
extern boolean b_blocknone(const border *, const struct unit *, const struct region *);
|
||||
extern boolean b_rvisible(const border *, const struct region * r);
|
||||
extern boolean b_fvisible(const border *, const struct faction * f, const struct region *);
|
||||
extern boolean b_uvisible(const border *, const struct unit * u);
|
||||
extern boolean b_rinvisible(const border *, const struct region * r);
|
||||
extern boolean b_finvisible(const border *, const struct faction * f, const struct region *);
|
||||
extern boolean b_uinvisible(const border *, const struct unit * u);
|
||||
extern boolean b_transparent(const border *, const struct faction *);
|
||||
extern boolean b_opaque(const border *, const struct faction *); /* !transparent */
|
||||
extern void b_read(connection * b, struct storage * store);
|
||||
extern void b_write(const connection * b, struct storage * store);
|
||||
extern boolean b_blockall(const connection *, const struct unit *, const struct region *);
|
||||
extern boolean b_blocknone(const connection *, const struct unit *, const struct region *);
|
||||
extern boolean b_rvisible(const connection *, const struct region * r);
|
||||
extern boolean b_fvisible(const connection *, const struct faction * f, const struct region *);
|
||||
extern boolean b_uvisible(const connection *, const struct unit * u);
|
||||
extern boolean b_rinvisible(const connection *, const struct region * r);
|
||||
extern boolean b_finvisible(const connection *, const struct faction * f, const struct region *);
|
||||
extern boolean b_uinvisible(const connection *, const struct unit * u);
|
||||
extern boolean b_transparent(const connection *, const struct faction *);
|
||||
extern boolean b_opaque(const connection *, const struct faction *); /* !transparent */
|
||||
|
||||
extern border_type bt_fogwall;
|
||||
extern border_type bt_noway;
|
|
@ -29,7 +29,7 @@
|
|||
#include "alliance.h"
|
||||
#include "alchemy.h"
|
||||
#include "battle.h"
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
#include "building.h"
|
||||
#include "calendar.h"
|
||||
#include "curse.h"
|
||||
|
@ -2793,7 +2793,7 @@ movewhere(const unit *u, const char * token, region * r, region** resultp)
|
|||
boolean
|
||||
move_blocked(const unit * u, const region *r, const region *r2)
|
||||
{
|
||||
border * b;
|
||||
connection * b;
|
||||
curse * c;
|
||||
static const curse_type * fogtrap_ct = NULL;
|
||||
|
||||
|
@ -2994,7 +2994,7 @@ attrib_init(void)
|
|||
at_register(&at_maxmagicians);
|
||||
at_register(&at_npcfaction);
|
||||
|
||||
/* border-typen */
|
||||
/* connection-typen */
|
||||
register_bordertype(&bt_noway);
|
||||
register_bordertype(&bt_fogwall);
|
||||
register_bordertype(&bt_wall);
|
||||
|
|
|
@ -345,7 +345,7 @@ extern void add_income(struct unit * u, int type, int want, int qty);
|
|||
enum {
|
||||
E_MOVE_OK = 0, /* possible to move */
|
||||
E_MOVE_NOREGION, /* no region exists in this direction */
|
||||
E_MOVE_BLOCKED /* cannot see this region, there is a blocking border. */
|
||||
E_MOVE_BLOCKED /* cannot see this region, there is a blocking connection. */
|
||||
};
|
||||
extern int movewhere(const struct unit *u, const char * token, struct region * r, struct region** resultp);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "move.h"
|
||||
|
||||
#include "alchemy.h"
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
#include "build.h"
|
||||
#include "building.h"
|
||||
#include "calendar.h"
|
||||
|
@ -1199,7 +1199,7 @@ cap_route(region * r, const region_list * route, const region_list * route_end,
|
|||
static region *
|
||||
next_region(unit * u, region * current, region * next)
|
||||
{
|
||||
border * b;
|
||||
connection * b;
|
||||
|
||||
b = get_borders(current, next);
|
||||
while (b!=NULL) {
|
||||
|
@ -1394,7 +1394,7 @@ travel_route(unit * u, const region_list * route_begin, const region_list * rout
|
|||
while (iroute && iroute!=route_end) {
|
||||
region * next = iroute->data;
|
||||
direction_t reldir = reldirection(current, next);
|
||||
border * b = get_borders(current, next);
|
||||
connection * b = get_borders(current, next);
|
||||
|
||||
/* check if we are caught by guarding units */
|
||||
if (iroute!=route_begin && mode!=TRAVEL_RUNNING && mode!=TRAVEL_TRANSPORTED) {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "region.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
#include "building.h"
|
||||
#include "curse.h"
|
||||
#include "equipment.h"
|
||||
|
@ -780,7 +780,7 @@ attrib_type at_travelunit = {
|
|||
void
|
||||
rsetroad(region * r, direction_t d, short val)
|
||||
{
|
||||
border * b;
|
||||
connection * b;
|
||||
region * r2 = rconnect(r, d);
|
||||
|
||||
if (!r2) return;
|
||||
|
@ -795,7 +795,7 @@ short
|
|||
rroad(const region * r, direction_t d)
|
||||
{
|
||||
int rval;
|
||||
border * b;
|
||||
connection * b;
|
||||
region * r2 = rconnect(r, d);
|
||||
|
||||
if (!r2) return 0;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/* kernel includes */
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -1183,7 +1183,7 @@ view_default(struct seen_region ** seen, region *r, faction *f)
|
|||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * r2 = rconnect(r, dir);
|
||||
if (r2) {
|
||||
border * b = get_borders(r, r2);
|
||||
connection * b = get_borders(r, r2);
|
||||
while (b) {
|
||||
if (!b->type->transparent(b, f)) break;
|
||||
b = b->next;
|
||||
|
@ -1200,7 +1200,7 @@ view_neighbours(struct seen_region ** seen, region * r, faction * f)
|
|||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * r2 = rconnect(r, dir);
|
||||
if (r2) {
|
||||
border * b = get_borders(r, r2);
|
||||
connection * b = get_borders(r, r2);
|
||||
while (b) {
|
||||
if (!b->type->transparent(b, f)) break;
|
||||
b = b->next;
|
||||
|
@ -1212,7 +1212,7 @@ view_neighbours(struct seen_region ** seen, region * r, faction * f)
|
|||
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
|
||||
region * r3 = rconnect(r2, dir);
|
||||
if (r3) {
|
||||
border * b = get_borders(r2, r3);
|
||||
connection * b = get_borders(r2, r3);
|
||||
while (b) {
|
||||
if (!b->type->transparent(b, f)) break;
|
||||
b = b->next;
|
||||
|
@ -1237,7 +1237,7 @@ recurse_regatta(struct seen_region ** seen, region *center, region *r, faction *
|
|||
if (r2) {
|
||||
int ndist = distance(center, r2);
|
||||
if (ndist>dist && fval(r2->terrain, SEA_REGION)) {
|
||||
border * b = get_borders(r, r2);
|
||||
connection * b = get_borders(r, r2);
|
||||
while (b) {
|
||||
if (!b->type->transparent(b, f)) break;
|
||||
b = b->next;
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "alchemy.h"
|
||||
#include "alliance.h"
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
#include "building.h"
|
||||
#include "faction.h"
|
||||
#include "group.h"
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include "faction.h"
|
||||
#include "group.h"
|
||||
#include "karma.h"
|
||||
#include "border.h"
|
||||
#include "connection.h"
|
||||
#include "item.h"
|
||||
#include "move.h"
|
||||
#include "order.h"
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
#define STORAGE_VERSION 328 /* with storage.h, some things are stored smarter (ids as base36, fractions as float) */
|
||||
#define INTPAK_VERSION 329 /* in binary, ints can get packed */
|
||||
#define NOZEROIDS_VERSION 330 /* zero is not a valid ID for anything (including factions) */
|
||||
#define NOBORDERATTRIBS_VERSION 331 /* border::attribs has been moved to userdata */
|
||||
#define NOBORDERATTRIBS_VERSION 331 /* connection::attribs has been moved to userdata */
|
||||
#define UIDHASH_VERSION 332 /* borders use the region.uid to store */
|
||||
#define REGIONOWNER_VERSION 333 /* regions have owners and morale */
|
||||
#define ALLIANCELEADER_VERSION 333 /* alliances have a leader */
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
/* kernel includes */
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/battle.h> /* für lovar */
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/spellid.h>
|
||||
|
@ -2622,7 +2622,7 @@ sp_summondragon(castorder *co)
|
|||
|
||||
typedef struct wallcurse {
|
||||
curse * buddy;
|
||||
border * wall;
|
||||
connection * wall;
|
||||
} wallcurse;
|
||||
|
||||
void
|
||||
|
@ -2655,7 +2655,7 @@ cw_init(attrib * a) {
|
|||
|
||||
void
|
||||
cw_write(const attrib * a, storage * store) {
|
||||
border * b = ((wallcurse*)((curse*)a->data.v)->data.v)->wall;
|
||||
connection * b = ((wallcurse*)((curse*)a->data.v)->data.v)->wall;
|
||||
curse_write(a, store);
|
||||
store->w_int(store, b->id);
|
||||
}
|
||||
|
@ -2705,7 +2705,7 @@ resolve_buddy(variant data, void * addr)
|
|||
bresolve * br = (bresolve*)data.v;
|
||||
|
||||
if (br->id>=0) {
|
||||
border * b = find_border(br->id);
|
||||
connection * b = find_border(br->id);
|
||||
|
||||
if (b && b->from && b->to) {
|
||||
attrib * a = a_find(b->from->attribs, &at_cursewall);
|
||||
|
@ -2741,7 +2741,7 @@ resolve_buddy(variant data, void * addr)
|
|||
}
|
||||
|
||||
static const char *
|
||||
b_namefirewall(const border * b, const region * r, const faction * f, int gflags)
|
||||
b_namefirewall(const connection * b, const region * r, const faction * f, int gflags)
|
||||
{
|
||||
const char * bname;
|
||||
unused(f);
|
||||
|
@ -2751,11 +2751,11 @@ b_namefirewall(const border * b, const region * r, const faction * f, int gflags
|
|||
else bname = "firewall";
|
||||
|
||||
if (gflags & GF_PURE) return bname;
|
||||
return LOC(f->locale, mkname("border", bname));
|
||||
return LOC(f->locale, mkname("connection", bname));
|
||||
}
|
||||
|
||||
static void
|
||||
wall_init(border * b)
|
||||
wall_init(connection * b)
|
||||
{
|
||||
wall_data * fd = (wall_data*)calloc(sizeof(wall_data), 1);
|
||||
fd->countdown = -1; /* infinite */
|
||||
|
@ -2763,13 +2763,13 @@ wall_init(border * b)
|
|||
}
|
||||
|
||||
static void
|
||||
wall_destroy(border * b)
|
||||
wall_destroy(connection * b)
|
||||
{
|
||||
free(b->data.v);
|
||||
}
|
||||
|
||||
static void
|
||||
wall_read(border * b, storage * store)
|
||||
wall_read(connection * b, storage * store)
|
||||
{
|
||||
wall_data * fd = (wall_data*)b->data.v;
|
||||
variant mno;
|
||||
|
@ -2791,7 +2791,7 @@ wall_read(border * b, storage * store)
|
|||
}
|
||||
|
||||
static void
|
||||
wall_write(const border * b, storage * store)
|
||||
wall_write(const connection * b, storage * store)
|
||||
{
|
||||
wall_data * fd = (wall_data*)b->data.v;
|
||||
write_unit_reference(fd->mage, store);
|
||||
|
@ -2800,7 +2800,7 @@ wall_write(const border * b, storage * store)
|
|||
}
|
||||
|
||||
static int
|
||||
wall_age(border * b)
|
||||
wall_age(connection * b)
|
||||
{
|
||||
wall_data * fd = (wall_data*)b->data.v;
|
||||
--fd->countdown;
|
||||
|
@ -2808,7 +2808,7 @@ wall_age(border * b)
|
|||
}
|
||||
|
||||
static region *
|
||||
wall_move(const border * b, struct unit * u, struct region * from, struct region * to, boolean routing)
|
||||
wall_move(const connection * b, struct unit * u, struct region * from, struct region * to, boolean routing)
|
||||
{
|
||||
wall_data * fd = (wall_data*)b->data.v;
|
||||
if (!routing && fd->active) {
|
||||
|
@ -2848,7 +2848,7 @@ border_type bt_firewall = {
|
|||
static int
|
||||
sp_firewall(castorder *co)
|
||||
{
|
||||
border * b;
|
||||
connection * b;
|
||||
wall_data * fd;
|
||||
region *r = co->rt;
|
||||
unit *mage = co->magician.u;
|
||||
|
@ -2904,7 +2904,7 @@ sp_firewall(castorder *co)
|
|||
/* ------------------------------------------------------------- */
|
||||
|
||||
static const char *
|
||||
wisps_name(const border * b, const region * r, const faction * f, int gflags)
|
||||
wisps_name(const connection * b, const region * r, const faction * f, int gflags)
|
||||
{
|
||||
const char * bname;
|
||||
unused(f);
|
||||
|
@ -2916,7 +2916,7 @@ wisps_name(const border * b, const region * r, const faction * f, int gflags)
|
|||
bname = "wisps";
|
||||
}
|
||||
if (gflags & GF_PURE) return bname;
|
||||
return LOC(f->locale, mkname("border", bname));
|
||||
return LOC(f->locale, mkname("connection", bname));
|
||||
}
|
||||
|
||||
typedef struct wisps_data {
|
||||
|
@ -2925,7 +2925,7 @@ typedef struct wisps_data {
|
|||
} wisps_data;
|
||||
|
||||
static region *
|
||||
wisps_move(const border * b, struct unit * u, struct region * from, struct region * next, boolean routing)
|
||||
wisps_move(const connection * b, struct unit * u, struct region * from, struct region * next, boolean routing)
|
||||
{
|
||||
direction_t reldir = reldirection(from, next);
|
||||
wisps_data * wd = (wisps_data*)b->data.v;
|
||||
|
@ -2946,7 +2946,7 @@ wisps_move(const border * b, struct unit * u, struct region * from, struct regio
|
|||
}
|
||||
|
||||
static void
|
||||
wisps_init(border * b)
|
||||
wisps_init(connection * b)
|
||||
{
|
||||
wisps_data * wd = (wisps_data*)calloc(sizeof(wisps_data), 1);
|
||||
|
||||
|
@ -2973,7 +2973,7 @@ border_type bt_wisps = {
|
|||
static int
|
||||
sp_wisps(castorder *co)
|
||||
{
|
||||
border * b;
|
||||
connection * b;
|
||||
wall_data * fd;
|
||||
region * r2;
|
||||
direction_t dir;
|
||||
|
@ -8804,7 +8804,7 @@ static spelldata spelldaten[] =
|
|||
};
|
||||
|
||||
static boolean
|
||||
chaosgate_valid(const border * b)
|
||||
chaosgate_valid(const connection * b)
|
||||
{
|
||||
const attrib * a = a_findc(b->from->attribs, &at_direction);
|
||||
if (!a) a = a_findc(b->to->attribs, &at_direction);
|
||||
|
@ -8813,7 +8813,7 @@ chaosgate_valid(const border * b)
|
|||
}
|
||||
|
||||
struct region *
|
||||
chaosgate_move(const border * b, struct unit * u, struct region * from, struct region * to, boolean routing)
|
||||
chaosgate_move(const connection * b, struct unit * u, struct region * from, struct region * to, boolean routing)
|
||||
{
|
||||
if (!routing) {
|
||||
int maxhp = u->hp / 4;
|
||||
|
|
|
@ -69,17 +69,6 @@
|
|||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
typedef struct window {
|
||||
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
||||
void (*paint)(struct window * win, const struct state * st);
|
||||
|
||||
WINDOW * handle;
|
||||
struct window * next;
|
||||
struct window * prev;
|
||||
boolean initialized;
|
||||
int update;
|
||||
} window;
|
||||
|
||||
extern const char * g_reportdir;
|
||||
extern const char * g_datadir;
|
||||
extern const char * g_basedir;
|
||||
|
@ -385,7 +374,7 @@ paint_info_region(window * wnd, const state * st)
|
|||
|
||||
unused(st);
|
||||
werase(win);
|
||||
wborder(win, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
wxborder(win);
|
||||
if (mr && mr->r) {
|
||||
const region * r = mr->r;
|
||||
if (r->land) {
|
||||
|
@ -439,6 +428,20 @@ paint_info_region(window * wnd, const state * st)
|
|||
}
|
||||
}
|
||||
|
||||
static void (*paint_info)(struct window * wnd, const struct state * st);
|
||||
|
||||
static void
|
||||
paint_info_default(window * wnd, const state * st)
|
||||
{
|
||||
if (paint_info) paint_info(wnd, st);
|
||||
else paint_info_region(wnd, st);
|
||||
}
|
||||
|
||||
void set_info_function(void (*callback)(struct window *, const struct state *))
|
||||
{
|
||||
paint_info = callback;
|
||||
}
|
||||
|
||||
static char *
|
||||
askstring(WINDOW * win, const char * q, char * buffer, size_t size)
|
||||
{
|
||||
|
@ -1177,7 +1180,7 @@ run_mapper(void)
|
|||
st->wnd_map->paint = &paint_map;
|
||||
st->wnd_map->update = 1;
|
||||
st->wnd_info = win_create(hwininfo);
|
||||
st->wnd_info->paint = &paint_info_region;
|
||||
st->wnd_info->paint = &paint_info_default;
|
||||
st->wnd_info->handlekey = &handle_info_region;
|
||||
st->wnd_info->update = 1;
|
||||
st->wnd_status = win_create(hwinstatus);
|
||||
|
|
|
@ -69,13 +69,32 @@ typedef struct state {
|
|||
struct window * wnd_status;
|
||||
} state;
|
||||
|
||||
typedef struct window {
|
||||
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
||||
void (*paint)(struct window * win, const struct state * st);
|
||||
|
||||
WINDOW * handle;
|
||||
struct window * next;
|
||||
struct window * prev;
|
||||
boolean initialized;
|
||||
int update;
|
||||
} window;
|
||||
|
||||
extern map_region * cursor_region(const view * v, const coordinate * c);
|
||||
extern void cnormalize(const coordinate * c, int * x, int * y);
|
||||
extern state * current_state;
|
||||
|
||||
extern void set_info_function(void (*callback)(struct window *, const struct state *));
|
||||
|
||||
#define TWIDTH 2 /* width of tile */
|
||||
#define THEIGHT 1 /* height of tile */
|
||||
|
||||
#if WIN32
|
||||
#define wxborder(win) wborder(win, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
#else
|
||||
#define wxborder(win) wborder(win, '|', '|', '-', '-', '+', '+', '+', '+')
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
/* kernel includes */
|
||||
#include <kernel/alchemy.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/equipment.h>
|
||||
|
@ -553,21 +553,21 @@ fix_astralplane(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern border *borders[];
|
||||
extern connection *borders[];
|
||||
|
||||
#define BORDER_MAXHASH 8191
|
||||
static void
|
||||
fix_road_borders(void)
|
||||
{
|
||||
#define MAXDEL 10000
|
||||
border *deleted[MAXDEL];
|
||||
connection *deleted[MAXDEL];
|
||||
int hash;
|
||||
int fixes = 0;
|
||||
|
||||
for (hash=0; hash<BORDER_MAXHASH && fixes!=MAXDEL; hash++) {
|
||||
border * blist;
|
||||
connection * blist;
|
||||
for (blist=borders[hash];blist && fixes!=MAXDEL;blist=blist->nexthash) {
|
||||
border * b;
|
||||
connection * b;
|
||||
for (b=blist;b && fixes!=MAXDEL;b=b->next) {
|
||||
if (b->type == &bt_road) {
|
||||
int x1, x2, y1, y2;
|
||||
|
@ -806,7 +806,7 @@ fix_chaosgates(void)
|
|||
spec_direction * sd = (spec_direction *)a->data.v;
|
||||
region * r2 = findregion(sd->x, sd->y);
|
||||
if (r2!=NULL) {
|
||||
border * b = get_borders(r, r2);
|
||||
connection * b = get_borders(r, r2);
|
||||
while (b) {
|
||||
if (b->type==&bt_chaosgate) break;
|
||||
b = b->next;
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#include <gamecode/xmlreport.h>
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/border.h>
|
||||
#include <kernel/connection.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/calendar.h>
|
||||
#include <kernel/faction.h>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <config.h>
|
||||
#include <curses.h>
|
||||
|
||||
#include "bind_gmtool.h"
|
||||
#include "../gmtool.h"
|
||||
|
@ -8,6 +9,7 @@
|
|||
#include <kernel/region.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <modules/autoseed.h>
|
||||
#include <util/log.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
@ -165,6 +167,59 @@ tolua_make_island(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int paint_handle;
|
||||
static struct lua_State * paint_state;
|
||||
|
||||
static void
|
||||
lua_paint_info(struct window * wnd, const struct state * st)
|
||||
{
|
||||
struct lua_State * L = paint_state;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
|
||||
tolua_pushnumber(L, st->cursor.x);
|
||||
tolua_pushnumber(L, st->cursor.y);
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("paint function failed: %s\n", error));
|
||||
lua_pop(L, 1);
|
||||
tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
|
||||
} else {
|
||||
const char* result = lua_tostring(L, -1);
|
||||
WINDOW * win = wnd->handle;
|
||||
int size = getmaxx(win)-2;
|
||||
int line = 0, maxline = getmaxy(win)-2;
|
||||
const char * str = result;
|
||||
wxborder(win);
|
||||
|
||||
while (*str && line<maxline) {
|
||||
const char * end = strchr(str, '\n');
|
||||
if (!end) break;
|
||||
else {
|
||||
size_t len = end-str;
|
||||
int bytes = MIN((int)len, size);
|
||||
mvwaddnstr(win, line++, 1, str, bytes);
|
||||
wclrtoeol(win);
|
||||
str = end + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_set_display(lua_State * L)
|
||||
{
|
||||
int type = lua_type(L, 1);
|
||||
if (type==LUA_TFUNCTION) {
|
||||
lua_pushvalue(L, 1);
|
||||
paint_handle = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
paint_state = L;
|
||||
|
||||
set_info_function(&lua_paint_info);
|
||||
} else {
|
||||
set_info_function(NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_make_block(lua_State * L)
|
||||
{
|
||||
|
@ -190,15 +245,16 @@ tolua_gmtool_open(lua_State* L)
|
|||
tolua_module(L, TOLUA_CAST "gmtool", 0);
|
||||
tolua_beginmodule(L, TOLUA_CAST "gmtool");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "open", tolua_state_open);
|
||||
tolua_function(L, TOLUA_CAST "close", tolua_state_close);
|
||||
tolua_function(L, TOLUA_CAST "open", &tolua_state_open);
|
||||
tolua_function(L, TOLUA_CAST "close", &tolua_state_close);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "editor", tolua_run_mapper);
|
||||
tolua_function(L, TOLUA_CAST "get_selection", tolua_selected_regions);
|
||||
tolua_function(L, TOLUA_CAST "get_cursor", tolua_current_region);
|
||||
tolua_function(L, TOLUA_CAST "highlight", tolua_highlight_region);
|
||||
tolua_function(L, TOLUA_CAST "select", tolua_select_region);
|
||||
tolua_function(L, TOLUA_CAST "select_at", tolua_select_coordinate);
|
||||
tolua_function(L, TOLUA_CAST "editor", &tolua_run_mapper);
|
||||
tolua_function(L, TOLUA_CAST "get_selection", &tolua_selected_regions);
|
||||
tolua_function(L, TOLUA_CAST "get_cursor", &tolua_current_region);
|
||||
tolua_function(L, TOLUA_CAST "highlight", &tolua_highlight_region);
|
||||
tolua_function(L, TOLUA_CAST "select", &tolua_select_region);
|
||||
tolua_function(L, TOLUA_CAST "select_at", &tolua_select_coordinate);
|
||||
tolua_function(L, TOLUA_CAST "set_display", &tolua_set_display);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "make_block", &tolua_make_block);
|
||||
tolua_function(L, TOLUA_CAST "make_island", &tolua_make_island);
|
||||
|
|
Loading…
Add table
Reference in a new issue