Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 3063 Fix problem where toads did not get a timeout to change back #1111

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions scripts/debug.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'eressea.path'
require 'eressea'
require 'eressea.xmlconf'

function gmtool_on_keypressed(keycode)
local warp = require('eressea.warpgate')
if keycode == gmtool.KEY_F1 then
warp.gm_edit()
end
end

eressea.read_game(get_turn() .. ".dat")
dump_unit("jiha")
1 change: 0 additions & 1 deletion src/attributes/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "iceberg.h"
#include "key.h"
#include "stealth.h"
#include "magic.h"
#include "movement.h"
#include "otherfaction.h"
#include "racename.h"
Expand Down
4 changes: 0 additions & 4 deletions src/attributes/attributes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once
#ifndef H_ATTRIBUTE_ATTRIBUTES
#define H_ATTRIBUTE_ATTRIBUTES

struct attrib_type;
struct region;
Expand All @@ -12,5 +10,3 @@ void set_observer(struct region *r, struct faction *f, int perception, int turns
int get_observer(const struct region *r, const struct faction *f);

extern struct attrib_type at_unitdissolve;

#endif
9 changes: 9 additions & 0 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,14 @@ static int tolua_get_unit(lua_State * L)
return 1;
}

static int tolua_dump_unit(lua_State * L)
{
int no = tolua_toid(L, 1, 0);
unit *u = findunit(no);
dump_unit(u);
return 0;
}

static int tolua_alliance_create(lua_State * L)
{
int id = (int)tolua_tonumber(L, 1, 0);
Expand Down Expand Up @@ -984,6 +992,7 @@ int tolua_bindings_open(lua_State * L, const dictionary *inifile)
} tolua_endmodule(L);
tolua_function(L, "get_region_by_id", tolua_get_region_byid);
tolua_function(L, "get_unit", tolua_get_unit);
tolua_function(L, "dump_unit", tolua_dump_unit);
tolua_function(L, "get_alliance", tolua_get_alliance);
tolua_function(L, "get_ship", tolua_get_ship);
tolua_function(L, "get_building", tolua_get_building);
Expand Down
10 changes: 10 additions & 0 deletions src/kernel/attrib.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,13 @@ void attrib_done(void) {
cb_clear(&cb_deprecated);
hmfree(at_hash);
}

void dump_attrib(const attrib *a) {
if (a) {
fprintf(stdout, "- %s\n", a->type->name);
if (a->type->dump) {
a->type->dump(a);
}
}
else fputs("null", stdout);
}
135 changes: 65 additions & 70 deletions src/kernel/attrib.h
Original file line number Diff line number Diff line change
@@ -1,77 +1,76 @@
#ifndef ATTRIB_H
#define ATTRIB_H
#pragma once

#include <stdbool.h>
#include "../util/variant.h"
#ifdef __cplusplus
extern "C" {
#endif

union variant;
struct gamedata;
struct storage;
typedef void(*afun) (void);

typedef struct attrib {
const struct attrib_type *type;
union variant data;
/* internal data, do not modify: */
struct attrib *next; /* next attribute in the list */
struct attrib *nexttype; /* skip to attribute of a different type */
} attrib;

#include <stdbool.h>

union variant;
struct gamedata;
struct storage;
typedef void(*afun) (void);

typedef struct attrib {
const struct attrib_type *type;
union variant data;
/* internal data, do not modify: */
struct attrib *next; /* next attribute in the list */
struct attrib *nexttype; /* skip to attribute of a different type */
} attrib;

#define ATF_UNIQUE (1<<0) /* only one per attribute-list */
#define ATF_PRESERVE (1<<1) /* preserve order in list. append to back */
#define ATF_USER_DEFINED (1<<2) /* use this to make udf */

typedef struct attrib_type {
const char *name;
void(*initialize) (union variant *);
void(*finalize) (union variant *);
int(*age) (struct attrib *, void *owner);
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
void(*write) (const union variant *, const void *owner, struct storage *);
int(*read) (union variant *, void *owner, struct gamedata *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
void(*upgrade) (struct attrib **alist, struct attrib *a);
unsigned int flags;
} attrib_type;

void at_register(attrib_type * at);
void at_deprecate(const char * name, int (*reader)(variant *, void *, struct gamedata *));
struct attrib_type *at_find(const char *name);

void write_attribs(struct storage *store, struct attrib *alist, const void *owner);
int read_attribs(struct gamedata *store, struct attrib **alist, void *owner);

attrib *a_select(attrib * a, const void *data, bool(*compare) (const attrib *, const void *));
attrib *a_find(attrib * a, const attrib_type * at);
attrib *a_add(attrib ** pa, attrib * at);
int a_remove(attrib ** pa, attrib * at);
void a_removeall(attrib ** a, const attrib_type * at);
attrib *a_new(const attrib_type * at);
int a_age(attrib ** attribs, void *owner);

void a_free_voidptr(union variant *v);
int a_read_orig(struct gamedata *data, attrib ** attribs, void *owner);
int a_read(struct gamedata *data, attrib ** attribs, void *owner);
void a_write(struct storage *store, const attrib * attribs, const void *owner);

int a_readint(union variant *v, void *owner, struct gamedata *);
void a_writeint(const union variant *v, const void *owner,
struct storage *store);
int a_readshorts(union variant *v, void *owner, struct gamedata *);
void a_writeshorts(const union variant *v, const void *owner,
struct storage *store);
int a_readchars(union variant *v, void *owner, struct gamedata *);
void a_writechars(const union variant *v, const void *owner,
struct storage *store);
int a_readstring(union variant *v, void *owner, struct gamedata *);
void a_writestring(const union variant *v, const void *owner,
struct storage *);
void a_finalizestring(union variant *v);

void attrib_done(void);
typedef struct attrib_type {
const char *name;
void(*initialize) (union variant *);
void(*finalize) (union variant *);
int(*age) (struct attrib *, void *owner);
/* age returns 0 if the attribute needs to be removed, !=0 otherwise */
void(*write) (const union variant *, const void *owner, struct storage *);
int(*read) (union variant *, void *owner, struct gamedata *); /* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
void(*upgrade) (struct attrib **alist, struct attrib *a);
unsigned int flags;
void(*dump) (const struct attrib *a);
} attrib_type;

void at_register(attrib_type * at);
void at_deprecate(const char * name, int (*reader)(variant *, void *, struct gamedata *));
struct attrib_type *at_find(const char *name);

void write_attribs(struct storage *store, struct attrib *alist, const void *owner);
int read_attribs(struct gamedata *store, struct attrib **alist, void *owner);

attrib *a_select(attrib * a, const void *data, bool(*compare) (const attrib *, const void *));
attrib *a_find(attrib * a, const attrib_type * at);
attrib *a_add(attrib ** pa, attrib * at);
int a_remove(attrib ** pa, attrib * at);
void a_removeall(attrib ** a, const attrib_type * at);
attrib *a_new(const attrib_type * at);
int a_age(attrib ** attribs, void *owner);

void a_free_voidptr(union variant *v);
int a_read_orig(struct gamedata *data, attrib ** attribs, void *owner);
int a_read(struct gamedata *data, attrib ** attribs, void *owner);
void a_write(struct storage *store, const attrib * attribs, const void *owner);

int a_readint(union variant *v, void *owner, struct gamedata *);
void a_writeint(const union variant *v, const void *owner,
struct storage *store);
int a_readshorts(union variant *v, void *owner, struct gamedata *);
void a_writeshorts(const union variant *v, const void *owner,
struct storage *store);
int a_readchars(union variant *v, void *owner, struct gamedata *);
void a_writechars(const union variant *v, const void *owner,
struct storage *store);
int a_readstring(union variant *v, void *owner, struct gamedata *);
void a_writestring(const union variant *v, const void *owner,
struct storage *);
void a_finalizestring(union variant *v);

void attrib_done(void);

void dump_attrib(const struct attrib *a);
#define DEFAULT_AGE NULL
#define DEFAULT_INIT NULL
#define DEFAULT_FINALIZE NULL
Expand All @@ -85,7 +84,3 @@ extern "C" {
#define AT_AGE_REMOVE 0 /* remove the attribute after calling age() */
#define AT_AGE_KEEP 1 /* keep the attribute for another turn */

#ifdef __cplusplus
}
#endif
#endif
14 changes: 13 additions & 1 deletion src/kernel/curse.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,26 @@ void curse_write(const variant * var, const void *owner, struct storage *store)
}
}

static void curse_dump(const attrib *a)
{
curse *c = (curse *)a->data.v;
const curse_type *ct = c->type;
fprintf(stdout, " type: %s\n", ct->cname);
fprintf(stdout, " mage: %s\n", unitname(c->magician));
fprintf(stdout, " duration: %d\n", c->duration);
fprintf(stdout, " effect: %lf\n", c->effect);
fprintf(stdout, " vigour: %lf\n", c->vigour);
}

attrib_type at_curse = {
"curse",
curse_init,
curse_done,
curse_age,
curse_write,
curse_read,
NULL
NULL,
.dump = curse_dump,
};

/* ------------------------------------------------------------- */
Expand Down
25 changes: 20 additions & 5 deletions src/kernel/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,32 @@ static int read_handler(variant *var, void *owner, gamedata *data)
return AT_READ_FAIL;
}

void dump_trigger(const trigger *t, int indent)
{
fprintf(stdout, "%*s- trigger: %s\n", indent, "", t->type->name);
if (t->type->dump) {
t->type->dump(t, indent + 2);
}
}

static void dump_handler(const attrib *a)
{
const handler_info *hi = (const handler_info *)a->data.v;
const trigger *t;
fprintf(stdout, " event: %s\n", hi->event);
for (t = hi->triggers; t; t = t->next) {
dump_trigger(t, 2);
}
}

attrib_type at_eventhandler = {
"eventhandler",
init_handler,
free_handler,
NULL,
write_handler,
read_handler
read_handler,
.dump = dump_handler
};

struct trigger **get_triggers(struct attrib *ap, const char *eventname)
Expand Down Expand Up @@ -260,7 +279,3 @@ const trigger_type * tt)
tp = &t->next;
}
}

/***
** default events
**/
Loading