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