first prototype of wormholes

This commit is contained in:
Enno Rehling 2004-02-21 22:25:00 +00:00
parent 7cca06e400
commit 012da64223
11 changed files with 245 additions and 11 deletions

View File

@ -25,6 +25,9 @@
#include <modules/gmcmd.h> #include <modules/gmcmd.h>
#include <modules/infocmd.h> #include <modules/infocmd.h>
#ifdef WORMHOLE_MODULE
#include <modules/wormhole.h>
#endif
/* gamecode includes */ /* gamecode includes */
#include "economy.h" #include "economy.h"
@ -3671,6 +3674,9 @@ processorders (void)
puts(" - Attribute altern"); puts(" - Attribute altern");
ageing(); ageing();
#ifdef WORMHOLE_MODULE
create_wormholes();
#endif
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich /* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
* Beschreibungen geändert haben */ * Beschreibungen geändert haben */
update_spells(); update_spells();

View File

@ -70,7 +70,7 @@ bt_find(const char* name)
return btl?btl->type:NULL; return btl?btl->type:NULL;
} }
static void void
bt_register(building_type * type) bt_register(building_type * type)
{ {
struct building_typelist * btl = malloc(sizeof(building_type)); struct building_typelist * btl = malloc(sizeof(building_type));

View File

@ -59,6 +59,7 @@ typedef struct building_type {
extern const building_type * bt_find(const char* name); extern const building_type * bt_find(const char* name);
extern void register_buildings(void); extern void register_buildings(void);
extern void bt_register(building_type * type);
typedef struct building_typelist { typedef struct building_typelist {
struct building_typelist * next; struct building_typelist * next;

View File

@ -860,6 +860,7 @@ readgame(const char * filename, int backup)
int rmax = maxregions; int rmax = maxregions;
sprintf(buf, "%s/%s", datapath(), filename); sprintf(buf, "%s/%s", datapath(), filename);
log_printf("- reading game data from %s\n", filename);
if (backup) create_backup(buf); if (backup) create_backup(buf);
F = cfopen(buf, "r"); F = cfopen(buf, "r");
if (F==NULL) { if (F==NULL) {

View File

@ -123,18 +123,30 @@
<File <File
RelativePath=".\alliance.h"> RelativePath=".\alliance.h">
</File> </File>
<File
RelativePath=".\arena.h">
</File>
<File
RelativePath=".\dungeon.h">
</File>
<File <File
RelativePath=".\gmcmd.h"> RelativePath=".\gmcmd.h">
</File> </File>
<File <File
RelativePath=".\infocmd.h"> RelativePath=".\infocmd.h">
</File> </File>
<File
RelativePath=".\museum.h">
</File>
<File <File
RelativePath=".\score.h"> RelativePath=".\score.h">
</File> </File>
<File <File
RelativePath=".\weather.h"> RelativePath=".\weather.h">
</File> </File>
<File
RelativePath=".\wormhole.h">
</File>
<File <File
RelativePath=".\xecmd.h"> RelativePath=".\xecmd.h">
</File> </File>
@ -148,15 +160,9 @@
<File <File
RelativePath=".\arena.c"> RelativePath=".\arena.c">
</File> </File>
<File
RelativePath=".\arena.h">
</File>
<File <File
RelativePath=".\dungeon.c"> RelativePath=".\dungeon.c">
</File> </File>
<File
RelativePath=".\dungeon.h">
</File>
<File <File
RelativePath=".\gmcmd.c"> RelativePath=".\gmcmd.c">
</File> </File>
@ -166,15 +172,15 @@
<File <File
RelativePath=".\museum.c"> RelativePath=".\museum.c">
</File> </File>
<File
RelativePath=".\museum.h">
</File>
<File <File
RelativePath=".\score.c"> RelativePath=".\score.c">
</File> </File>
<File <File
RelativePath=".\weather.c"> RelativePath=".\weather.c">
</File> </File>
<File
RelativePath=".\wormhole.c">
</File>
<File <File
RelativePath=".\xecmd.c"> RelativePath=".\xecmd.c">
</File> </File>

View 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

View File

@ -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

View File

@ -44,6 +44,7 @@
#define MUSEUM_MODULE #define MUSEUM_MODULE
#define ARENA_MODULE #define ARENA_MODULE
#define WORMHOLE_MODULE
#define MAILITPATH "/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin" #define MAILITPATH "/usr/sbin:$HOME/eressea/bin:/bin:/usr/bin:/usr/local/bin"

View File

@ -44,6 +44,9 @@
#ifdef MUSEUM_MODULE #ifdef MUSEUM_MODULE
#include <modules/museum.h> #include <modules/museum.h>
#endif #endif
#ifdef WORMHOLE_MODULE
#include <modules/wormhole.h>
#endif
#ifdef ARENA_MODULE #ifdef ARENA_MODULE
#include <modules/arena.h> #include <modules/arena.h>
#endif #endif
@ -185,6 +188,9 @@ game_init(void)
#ifdef ARENA_MODULE #ifdef ARENA_MODULE
register_arena(); register_arena();
#endif #endif
#ifdef WORMHOLE_MODULE
register_wormholes();
#endif
#ifdef REMOVE_THIS #ifdef REMOVE_THIS
render_init(); render_init();
{ {

View File

@ -47,6 +47,9 @@
#ifdef MUSEUM_MODULE #ifdef MUSEUM_MODULE
#include <modules/museum.h> #include <modules/museum.h>
#endif #endif
#ifdef WORMHOLE_MODULE
#include <modules/wormhole.h>
#endif
#ifdef ARENA_MODULE #ifdef ARENA_MODULE
#include <modules/arena.h> #include <modules/arena.h>
#endif #endif
@ -199,6 +202,10 @@ game_init(void)
#ifdef ARENA_MODULE #ifdef ARENA_MODULE
register_arena(); register_arena();
#endif #endif
#ifdef WORMHOLE_MODULE
register_wormholes();
#endif
#ifdef REMOVE_THIS #ifdef REMOVE_THIS
render_init(); render_init();
{ {

View File

@ -41,6 +41,9 @@
#ifdef ARENA_MODULE #ifdef ARENA_MODULE
#include <modules/arena.h> #include <modules/arena.h>
#endif #endif
#ifdef WORMHOLE_MODULE
#include <modules/wormhole.h>
#endif
/* kernel includes */ /* kernel includes */
#include <item.h> #include <item.h>
@ -1710,6 +1713,9 @@ main(int argc, char *argv[])
#ifdef ARENA_MODULE #ifdef ARENA_MODULE
register_arena(); register_arena();
#endif #endif
#ifdef WORMHOLE_MODULE
register_wormholes();
#endif
/* register_dungeon(); */ /* register_dungeon(); */
init_data(xmlfile); init_data(xmlfile);