Merge pull request #943 from eressea/2758-smurf

fix smurfication
This commit is contained in:
Enno Rehling 2021-06-15 19:26:23 +02:00 committed by GitHub
commit eadad871ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 9 deletions

View File

@ -105,11 +105,6 @@ int handle_triggers(trigger ** triggers, void *param)
** at_eventhandler
**/
typedef struct handler_info {
char *event;
trigger *triggers;
} handler_info;
static void init_handler(variant *var)
{
var->v = calloc(1, sizeof(handler_info));

View File

@ -37,6 +37,11 @@ extern "C" {
variant data;
} event_arg;
typedef struct handler_info {
char *event;
trigger *triggers;
} handler_info;
trigger *t_new(trigger_type * ttype);
void t_free(trigger * t);
void t_add(trigger ** tlist, trigger * t);

View File

@ -374,6 +374,26 @@ static void write_skills(gamedata *data, const unit *u) {
}
}
static void fix_smurfication(unit *u) {
if (u->attribs) {
attrib *a;
for (a = a_find(u->attribs, &at_eventhandler); a && a->type == &at_eventhandler; a = a->next) {
handler_info *info = (handler_info *)a->data.v;
if (0 == strcmp("timer", info->event)) {
trigger *t;
for (t = info->triggers; t; t = t->next) {
if (t->type == &tt_changerace) {
/* is a smurf, but will change back */
return;
}
}
}
}
}
log_error("%s was a %s in a %s faction", unitname(u), u->_race->_name, u->faction->race->_name);
u->_race = u->faction->race;
}
unit *read_unit(gamedata *data)
{
unit *u;
@ -532,10 +552,7 @@ unit *read_unit(gamedata *data)
if (rc_demon) {
const struct race *rc = u_race(u);
if (rc == rc_smurf) {
if (!u->attribs) {
log_error("%s was a %s in a %s faction", unitname(u), rc->_name, u->faction->race->_name);
u->_race = u->faction->race;
}
fix_smurfication(u);
}
if (rc == rc_demon) {
if (data->version < FIX_SHAPESHIFT_VERSION) {