forked from github/server
first prototype of wormholes
This commit is contained in:
parent
7cca06e400
commit
012da64223
|
@ -25,6 +25,9 @@
|
|||
|
||||
#include <modules/gmcmd.h>
|
||||
#include <modules/infocmd.h>
|
||||
#ifdef WORMHOLE_MODULE
|
||||
#include <modules/wormhole.h>
|
||||
#endif
|
||||
|
||||
/* gamecode includes */
|
||||
#include "economy.h"
|
||||
|
@ -3671,6 +3674,9 @@ processorders (void)
|
|||
puts(" - Attribute altern");
|
||||
ageing();
|
||||
|
||||
#ifdef WORMHOLE_MODULE
|
||||
create_wormholes();
|
||||
#endif
|
||||
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
|
||||
* Beschreibungen geändert haben */
|
||||
update_spells();
|
||||
|
|
|
@ -70,7 +70,7 @@ bt_find(const char* name)
|
|||
return btl?btl->type:NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
bt_register(building_type * type)
|
||||
{
|
||||
struct building_typelist * btl = malloc(sizeof(building_type));
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef struct building_type {
|
|||
|
||||
extern const building_type * bt_find(const char* name);
|
||||
extern void register_buildings(void);
|
||||
extern void bt_register(building_type * type);
|
||||
|
||||
typedef struct building_typelist {
|
||||
struct building_typelist * next;
|
||||
|
|
|
@ -860,6 +860,7 @@ readgame(const char * filename, int backup)
|
|||
int rmax = maxregions;
|
||||
|
||||
sprintf(buf, "%s/%s", datapath(), filename);
|
||||
log_printf("- reading game data from %s\n", filename);
|
||||
if (backup) create_backup(buf);
|
||||
F = cfopen(buf, "r");
|
||||
if (F==NULL) {
|
||||
|
|
|
@ -123,18 +123,30 @@
|
|||
<File
|
||||
RelativePath=".\alliance.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\arena.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dungeon.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gmcmd.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\infocmd.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\museum.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\score.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\weather.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\wormhole.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\xecmd.h">
|
||||
</File>
|
||||
|
@ -148,15 +160,9 @@
|
|||
<File
|
||||
RelativePath=".\arena.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\arena.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dungeon.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\dungeon.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\gmcmd.c">
|
||||
</File>
|
||||
|
@ -166,15 +172,15 @@
|
|||
<File
|
||||
RelativePath=".\museum.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\museum.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\score.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\weather.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\wormhole.c">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\xecmd.c">
|
||||
</File>
|
||||
|
|
|
@ -0,0 +1,170 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| Eressea PBEM host | Enno Rehling <enno@eressea-pbem.de>
|
||||
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
| |
|
||||
+-------------------+
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <eressea.h>
|
||||
|
||||
#ifdef WORMHOLE_MODULE
|
||||
#include "wormhole.h"
|
||||
|
||||
/* kernel includes */
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <stdlib.h>
|
||||
|
||||
static boolean
|
||||
good_region(const region * r)
|
||||
{
|
||||
return (r->units!=NULL && r->land!=NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
cmp_age(const void * v1, const void *v2)
|
||||
{
|
||||
const region * r1 = (const region*)v1;
|
||||
const region * r2 = (const region*)v2;
|
||||
if (r1->age<r2->age) return -1;
|
||||
if (r1->age>r2->age) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static building_type bt_wormhole = {
|
||||
"wormhole", BTF_NOBUILD|BTF_UNIQUE|BTF_INDESTRUCTIBLE,
|
||||
1, 4, 4,
|
||||
0, 0, 0, 0.0
|
||||
};
|
||||
|
||||
typedef struct wormhole_data {
|
||||
building * entry;
|
||||
building * exit;
|
||||
} wormhole_data;
|
||||
|
||||
static void
|
||||
wormhole_init(struct attrib *a)
|
||||
{
|
||||
a->data.v = calloc(1, sizeof(wormhole_data));
|
||||
}
|
||||
|
||||
static void
|
||||
wormhole_done(struct attrib * a)
|
||||
{
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static int
|
||||
wormhole_age(struct attrib * a)
|
||||
{
|
||||
wormhole_data * data = (wormhole_data*)a->data.v;
|
||||
destroy_building(data->entry);
|
||||
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
wormhole_write(const struct attrib * a, FILE* F)
|
||||
{
|
||||
wormhole_data * data = (wormhole_data*)a->data.v;
|
||||
write_building_reference(data->entry, F);
|
||||
write_building_reference(data->exit, F);
|
||||
}
|
||||
|
||||
int
|
||||
wormhole_read(struct attrib * a, FILE* F)
|
||||
{
|
||||
wormhole_data * data = (wormhole_data*)a->data.v;
|
||||
|
||||
read_building_reference(&data->entry, F);
|
||||
read_building_reference(&data->exit, F);
|
||||
/* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static attrib_type at_wormhole = {
|
||||
"wormhole",
|
||||
wormhole_init,
|
||||
wormhole_done,
|
||||
wormhole_age,
|
||||
wormhole_write,
|
||||
wormhole_read,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
static void
|
||||
make_wormhole(region * r1, region * r2)
|
||||
{
|
||||
building * b1 = new_building(&bt_wormhole, r1, NULL);
|
||||
building * b2 = new_building(&bt_wormhole, r2, NULL);
|
||||
attrib * a1 = a_add(&b1->attribs, a_new(&at_wormhole));
|
||||
attrib * a2 = a_add(&b2->attribs, a_new(&at_wormhole));
|
||||
wormhole_data * d1 = (wormhole_data*)a1->data.v;
|
||||
wormhole_data * d2 = (wormhole_data*)a2->data.v;
|
||||
d1->entry = d2->exit = b1;
|
||||
d2->entry = d1->exit = b2;
|
||||
/* ADDMSG() */
|
||||
}
|
||||
|
||||
void
|
||||
create_wormholes(void)
|
||||
{
|
||||
#define WORMHOLE_CHANCE 10000
|
||||
region_list *rptr, * rlist = NULL;
|
||||
region * r = regions;
|
||||
int i = 0, count = 0;
|
||||
region ** match;
|
||||
|
||||
/*
|
||||
* select a list of regions. we'll sort them by age later.
|
||||
*/
|
||||
while (r!=NULL) {
|
||||
int next = rand() % (2*WORMHOLE_CHANCE);
|
||||
while (r!=NULL && (next!=0 || !good_region(r))) {
|
||||
if (good_region(r)) {
|
||||
--next;
|
||||
}
|
||||
r=r->next;
|
||||
}
|
||||
if (r==NULL) break;
|
||||
add_regionlist(&rlist, r);
|
||||
++count;
|
||||
r=r->next;
|
||||
}
|
||||
|
||||
match = (region**)malloc(sizeof(region*) * count);
|
||||
qsort(match, count, sizeof(region *), cmp_age);
|
||||
rptr = rlist;
|
||||
while (i!=count) {
|
||||
match[i++] = rptr->data;
|
||||
rptr = rptr->next;
|
||||
}
|
||||
free_regionlist(rlist);
|
||||
|
||||
count /= 2;
|
||||
for (i=0;i!=count;++i) {
|
||||
make_wormhole(match[i], match[i+count]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
register_wormholes(void)
|
||||
{
|
||||
bt_register(&bt_wormhole);
|
||||
at_register(&at_wormhole);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,30 @@
|
|||
/* vi: set ts=2:
|
||||
*
|
||||
*
|
||||
* Eressea PB(E)M host Copyright (C) 1998-2003
|
||||
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||
* Henning Peters (faroul@beyond.kn-bremen.de)
|
||||
* Enno Rehling (enno@eressea-pbem.de)
|
||||
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
||||
*
|
||||
* This program may not be used, modified or distributed without
|
||||
* prior permission by the authors of Eressea.
|
||||
*/
|
||||
#ifndef H_MOD_WORMHOLE
|
||||
#define H_MOD_WORMHOLE
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef WORMHOLE_MODULE
|
||||
#error "must define WORMHOLE_MODULE to use this module"
|
||||
#endif
|
||||
|
||||
extern void create_wormholes(void);
|
||||
extern void register_wormholes(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -44,6 +44,7 @@
|
|||
|
||||
#define MUSEUM_MODULE
|
||||
#define ARENA_MODULE
|
||||
#define WORMHOLE_MODULE
|
||||
|
||||
#define MAILITPATH "/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin"
|
||||
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
#ifdef MUSEUM_MODULE
|
||||
#include <modules/museum.h>
|
||||
#endif
|
||||
#ifdef WORMHOLE_MODULE
|
||||
#include <modules/wormhole.h>
|
||||
#endif
|
||||
#ifdef ARENA_MODULE
|
||||
#include <modules/arena.h>
|
||||
#endif
|
||||
|
@ -185,6 +188,9 @@ game_init(void)
|
|||
#ifdef ARENA_MODULE
|
||||
register_arena();
|
||||
#endif
|
||||
#ifdef WORMHOLE_MODULE
|
||||
register_wormholes();
|
||||
#endif
|
||||
#ifdef REMOVE_THIS
|
||||
render_init();
|
||||
{
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#ifdef MUSEUM_MODULE
|
||||
#include <modules/museum.h>
|
||||
#endif
|
||||
#ifdef WORMHOLE_MODULE
|
||||
#include <modules/wormhole.h>
|
||||
#endif
|
||||
#ifdef ARENA_MODULE
|
||||
#include <modules/arena.h>
|
||||
#endif
|
||||
|
@ -199,6 +202,10 @@ game_init(void)
|
|||
#ifdef ARENA_MODULE
|
||||
register_arena();
|
||||
#endif
|
||||
#ifdef WORMHOLE_MODULE
|
||||
register_wormholes();
|
||||
#endif
|
||||
|
||||
#ifdef REMOVE_THIS
|
||||
render_init();
|
||||
{
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
#ifdef ARENA_MODULE
|
||||
#include <modules/arena.h>
|
||||
#endif
|
||||
#ifdef WORMHOLE_MODULE
|
||||
#include <modules/wormhole.h>
|
||||
#endif
|
||||
|
||||
/* kernel includes */
|
||||
#include <item.h>
|
||||
|
@ -1708,7 +1711,10 @@ main(int argc, char *argv[])
|
|||
register_museum();
|
||||
#endif
|
||||
#ifdef ARENA_MODULE
|
||||
register_arena();
|
||||
register_arena();
|
||||
#endif
|
||||
#ifdef WORMHOLE_MODULE
|
||||
register_wormholes();
|
||||
#endif
|
||||
/* register_dungeon(); */
|
||||
|
||||
|
|
Loading…
Reference in New Issue