Feature #77 ยป 0011-Store-activity-triggering-actions-to-savegame.patch
server/savegame/savecompat.c | ||
---|---|---|
free(savemod);
|
||
}
|
||
}
|
||
/* Add actions for unit activities */
|
||
if (format_class == SAVEGAME_3) {
|
||
loading->activities.size
|
||
= secfile_lookup_int_default(loading->file, 0,
|
||
"savefile.activities_size");
|
||
if (loading->activities.size) {
|
||
loading->activities.order
|
||
= secfile_lookup_str_vec(loading->file, &loading->activities.size,
|
||
"savefile.activities_vector");
|
||
sg_failure_ret(loading->activities.size != 0,
|
||
"Failed to load activity order: %s",
|
||
secfile_error());
|
||
}
|
||
loading->action.size = secfile_lookup_int_default(loading->file, 0,
|
||
"savefile.action_size");
|
||
sg_failure_ret(loading->action.size > 0,
|
||
"Failed to load action order: %s",
|
||
secfile_error());
|
||
if (loading->action.size) {
|
||
const char **modname;
|
||
int j;
|
||
modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
|
||
"savefile.action_vector");
|
||
loading->action.order = fc_calloc(loading->action.size,
|
||
sizeof(*loading->action.order));
|
||
for (j = 0; j < loading->action.size; j++) {
|
||
struct action *real_action = action_by_rule_name(modname[j]);
|
||
if (real_action) {
|
||
loading->action.order[j] = real_action->id;
|
||
} else {
|
||
log_sg("Unknown action \'%s\'", modname[j]);
|
||
loading->action.order[j] = ACTION_NONE;
|
||
}
|
||
}
|
||
free(modname);
|
||
}
|
||
player_slots_iterate(pslot) {
|
||
int plrno = player_slot_index(pslot);
|
||
int nunits;
|
||
int unro;
|
||
if (secfile_section_lookup(loading->file, "player%d", plrno) == nullptr) {
|
||
continue;
|
||
}
|
||
nunits = secfile_lookup_int_default(loading->file, 0,
|
||
"player%d.nunits", plrno);
|
||
for (unro = 0; unro < nunits; unro++) {
|
||
int ei;
|
||
int i;
|
||
enum unit_activity activity;
|
||
enum gen_action act;
|
||
ei = secfile_lookup_int_default(loading->file, -1,
|
||
"player%d.u%d.activity", plrno, unro);
|
||
if (ei >= 0 && ei < loading->activities.size) {
|
||
activity = unit_activity_by_name(loading->activities.order[ei],
|
||
fc_strcasecmp);
|
||
act = activity_default_action(activity);
|
||
for (i = 0; i < loading->action.size; i++) {
|
||
if (act == loading->action.order[i]) {
|
||
secfile_insert_int(loading->file, i, "player%d.u%d.action",
|
||
plrno, unro);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} player_slots_iterate_end;
|
||
}
|
||
}
|
||
/************************************************************************//**
|
||
... | ... | |
secfile_insert_bool(loading->file, FALSE, "map.altitude");
|
||
/* Add actions for unit activities */
|
||
loading->activities.size
|
||
= secfile_lookup_int_default(loading->file, 0,
|
||
"savefile.activities_size");
|
||
if (loading->activities.size) {
|
||
loading->activities.order
|
||
= secfile_lookup_str_vec(loading->file, &loading->activities.size,
|
||
"savefile.activities_vector");
|
||
sg_failure_ret(loading->activities.size != 0,
|
||
"Failed to load activity order: %s",
|
||
secfile_error());
|
||
}
|
||
loading->action.size = secfile_lookup_int_default(loading->file, 0,
|
||
"savefile.action_size");
|
||
sg_failure_ret(loading->action.size > 0,
|
||
"Failed to load action order: %s",
|
||
secfile_error());
|
||
if (loading->action.size) {
|
||
const char **modname;
|
||
int j;
|
||
modname = secfile_lookup_str_vec(loading->file, &loading->action.size,
|
||
"savefile.action_vector");
|
||
loading->action.order = fc_calloc(loading->action.size,
|
||
sizeof(*loading->action.order));
|
||
for (j = 0; j < loading->action.size; j++) {
|
||
struct action *real_action = action_by_rule_name(modname[j]);
|
||
if (real_action) {
|
||
loading->action.order[j] = real_action->id;
|
||
} else {
|
||
log_sg("Unknown action \'%s\'", modname[j]);
|
||
loading->action.order[j] = ACTION_NONE;
|
||
}
|
||
}
|
||
free(modname);
|
||
}
|
||
player_slots_iterate(pslot) {
|
||
int plrno = player_slot_index(pslot);
|
||
int nunits;
|
||
int unro;
|
||
if (secfile_section_lookup(loading->file, "player%d", plrno) == nullptr) {
|
||
continue;
|
||
}
|
||
nunits = secfile_lookup_int_default(loading->file, 0,
|
||
"player%d.nunits", plrno);
|
||
for (unro = 0; unro < nunits; unro++) {
|
||
int ei;
|
||
int i;
|
||
enum unit_activity activity;
|
||
enum gen_action act;
|
||
ei = secfile_lookup_int_default(loading->file, -1,
|
||
"player%d.u%d.activity", plrno, unro);
|
||
if (ei >= 0 && ei < loading->activities.size) {
|
||
activity = unit_activity_by_name(loading->activities.order[ei],
|
||
fc_strcasecmp);
|
||
act = activity_default_action(activity);
|
||
for (i = 0; i < loading->action.size; i++) {
|
||
if (act == loading->action.order[i]) {
|
||
secfile_insert_int(loading->file, i, "player%d.u%d.action",
|
||
plrno, unro);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} player_slots_iterate_end;
|
||
} /* Version < 3.2.92 */
|
||
#endif /* FREECIV_DEV_SAVE_COMPAT_3_3 */
|
server/savegame/savegame3.c | ||
---|---|---|
int natnbr;
|
||
int unconverted;
|
||
const char *str;
|
||
enum gen_action action;
|
||
sg_warn_ret_val(secfile_lookup_int(loading->file, &punit->id, "%s.id",
|
||
unitstr), FALSE, "%s", secfile_error());
|
||
... | ... | |
"%s", secfile_error());
|
||
activity = unit_activity_by_name(loading->activities.order[ei],
|
||
fc_strcasecmp);
|
||
sg_warn_ret_val(secfile_lookup_int(loading->file, &ei,
|
||
"%s.action", unitstr), FALSE,
|
||
"%s", secfile_error());
|
||
action = loading->action.order[ei];
|
||
punit->server.birth_turn
|
||
= secfile_lookup_int_default(loading->file, game.info.turn,
|
||
... | ... | |
if (extra_id != -2) {
|
||
if (extra_id >= 0 && extra_id < loading->extra.size) {
|
||
pextra = loading->extra.order[extra_id];
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity_targeted(punit, activity, pextra,
|
||
activity_default_action(activity));
|
||
set_unit_activity_targeted(punit, activity, pextra, action);
|
||
} else if (activity == ACTIVITY_IRRIGATE) {
|
||
struct extra_type *tgt = next_extra_for_tile(unit_tile(punit),
|
||
EC_IRRIGATION,
|
||
unit_owner(punit),
|
||
punit);
|
||
if (tgt != NULL) {
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity_targeted(punit, ACTIVITY_IRRIGATE, tgt,
|
||
activity_default_action(ACTIVITY_IRRIGATE));
|
||
set_unit_activity_targeted(punit, ACTIVITY_IRRIGATE, tgt, action);
|
||
} else {
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity(punit, ACTIVITY_CULTIVATE,
|
||
activity_default_action(ACTIVITY_CULTIVATE));
|
||
set_unit_activity(punit, ACTIVITY_CULTIVATE, action);
|
||
}
|
||
} else if (activity == ACTIVITY_MINE) {
|
||
struct extra_type *tgt = next_extra_for_tile(unit_tile(punit),
|
||
... | ... | |
unit_owner(punit),
|
||
punit);
|
||
if (tgt != NULL) {
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity_targeted(punit, ACTIVITY_MINE, tgt,
|
||
activity_default_action(ACTIVITY_MINE));
|
||
set_unit_activity_targeted(punit, ACTIVITY_MINE, tgt, action);
|
||
} else {
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity(punit, ACTIVITY_PLANT,
|
||
activity_default_action(ACTIVITY_PLANT));
|
||
set_unit_activity(punit, ACTIVITY_PLANT, action);
|
||
}
|
||
} else {
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity(punit, activity,
|
||
activity_default_action(activity));
|
||
set_unit_activity(punit, activity, action);
|
||
}
|
||
} else {
|
||
/* FIXME: Correct action from the savegame */
|
||
set_unit_activity_targeted(punit, activity, NULL,
|
||
activity_default_action(activity));
|
||
set_unit_activity_targeted(punit, activity, NULL, action);
|
||
} /* activity_tgt == NULL */
|
||
sg_warn_ret_val(secfile_lookup_int(loading->file, &punit->activity_count,
|
||
... | ... | |
secfile_insert_int(saving->file, punit->activity, "%s.activity", buf);
|
||
secfile_insert_int(saving->file, punit->activity_count,
|
||
"%s.activity_count", buf);
|
||
secfile_insert_int(saving->file, punit->action, "%s.action", buf);
|
||
if (punit->activity_target == NULL) {
|
||
secfile_insert_int(saving->file, -1, "%s.activity_tgt", buf);
|
||
} else {
|