Project

General

Profile

Feature #1031 ยป 0053-Add-comment-field-for-enablers.patch

Marko Lindqvist, 10/29/2024 06:23 PM

View differences:

common/actions.c
struct action_enabler *enabler;
enabler = fc_malloc(sizeof(*enabler));
enabler->ruledit_disabled = FALSE;
enabler->rulesave.ruledit_disabled = FALSE;
enabler->rulesave.comment = nullptr;
requirement_vector_init(&enabler->actor_reqs);
requirement_vector_init(&enabler->target_reqs);
......
**************************************************************************/
void action_enabler_free(struct action_enabler *enabler)
{
if (enabler->rulesave.comment != nullptr) {
free(enabler->rulesave.comment);
}
requirement_vector_free(&enabler->actor_reqs);
requirement_vector_free(&enabler->target_reqs);
common/actions.h
struct requirement_vector actor_reqs;
struct requirement_vector target_reqs;
/* Only relevant for ruledit and other rulesave users. Indicates that
* this action enabler is deleted and shouldn't be saved. */
bool ruledit_disabled;
struct {
/* Only relevant for ruledit and other rulesave users. Indicates that
* this action enabler is deleted and shouldn't be saved. */
bool ruledit_disabled;
char *comment;
} rulesave;
};
#define action_has_result(_act_, _res_) ((_act_)->result == (_res_))
......
#define action_enabler_list_re_iterate(action_enabler_list, aenabler) \
action_enabler_list_iterate(action_enabler_list, aenabler) { \
if (!aenabler->ruledit_disabled) {
if (!aenabler->rulesave.ruledit_disabled) {
#define action_enabler_list_re_iterate_end \
} \
data/alien/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/civ1/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/civ2/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/civ2civ3/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/classic/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/goldkeep/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/granularity/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/multiplayer/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/ruledit/comments-3.3.txt
; action = the action to enable.\n\
; actor_reqs = requirements that apply to the actor.\n\
; target_reqs = requirements that apply to the target.\n\
; comment = Comment for the benefit to someone examining the ruleset\n\
; Not used by freeciv any other way.\n\
;\n\
; README.actions lists the possible actions and their hard coded\n\
; requirements.\n\
data/sandbox/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/stub/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
data/webperimental/actions.ruleset
; action = the action to enable.
; actor_reqs = requirements that apply to the actor.
; target_reqs = requirements that apply to the target.
; comment = Comment for the benefit to someone examining the ruleset
; Not used by freeciv any other way.
;
; README.actions lists the possible actions and their hard coded
; requirements.
server/ruleset/rscompat.c
" Don't know how to fix it."
" Dropping it.",
action_rule_name(paction), problem->description);
ae->ruledit_disabled = TRUE;
ae->rulesave.ruledit_disabled = TRUE;
req_vec_problem_free(problem);
return TRUE;
......
" for %s: %s"
" Dropping it.",
action_rule_name(paction), problem->description);
ae->ruledit_disabled = TRUE;
ae->rulesave.ruledit_disabled = TRUE;
req_vec_problem_free(problem);
return TRUE;
}
......
req_vec_change_translation(
&problem->suggested_solutions[i],
action_enabler_vector_by_number_name));
new_enabler->ruledit_disabled = TRUE;
new_enabler->rulesave.ruledit_disabled = TRUE;
req_vec_problem_free(problem);
return TRUE;
}
......
if (problem->num_suggested_solutions - 1 == i) {
/* The last modification is to the original enabler. */
ae->action = new_enabler->action;
ae->ruledit_disabled = new_enabler->ruledit_disabled;
ae->rulesave.ruledit_disabled = new_enabler->rulesave.ruledit_disabled;
requirement_vector_copy(&ae->actor_reqs,
&new_enabler->actor_reqs);
requirement_vector_copy(&ae->target_reqs,
......
do {
restart_enablers_for_action = FALSE;
action_enabler_list_iterate(action_enablers_for_action(act_id), ae) {
if (ae->ruledit_disabled) {
if (ae->rulesave.ruledit_disabled) {
/* Ignore disabled enablers */
continue;
}
server/ruleset/ruleload.c
/* Make sure that all action enablers are disabled. */
action_enabler_list_iterate(action_enablers_for_action(paction->id),
ae) {
ae->ruledit_disabled = TRUE;
ae->rulesave.ruledit_disabled = TRUE;
purged++;
} action_enabler_list_iterate_end;
......
/* Impossible requirement vector requirement. */
action_enabler_list_iterate(action_enablers_for_action(paction->id),
ae) {
if (!ae->ruledit_disabled
if (!ae->rulesave.ruledit_disabled
&& (!action_enabler_possible_actor(ae)
|| req_vec_is_impossible_to_fulfill(&ae->target_reqs))) {
ae->ruledit_disabled = TRUE;
ae->rulesave.ruledit_disabled = TRUE;
purged++;
log_normal("Purged unused action enabler for %s",
action_rule_name(paction));
......
/* Do the purging. */
action_enabler_list_iterate(action_enablers_for_action(paction->id),
ae) {
while (!ae->ruledit_disabled
while (!ae->rulesave.ruledit_disabled
&& (purge_redundant_req_vec(&ae->actor_reqs, actor_reqs)
|| purge_redundant_req_vec(&ae->target_reqs,
target_reqs))) {
......
struct requirement_vector *actor_reqs;
struct requirement_vector *target_reqs;
const char *action_text;
const char *comment;
enabler = action_enabler_new();
......
requirement_vector_copy(&enabler->target_reqs, target_reqs);
comment = secfile_lookup_str(file, "%s.comment", sec_name);
if (comment != nullptr) {
enabler->rulesave.comment = fc_strdup(comment);
}
action_enabler_add(enabler);
} section_list_iterate_end;
tools/ruledit/tab_enablers.cpp
enabler_list->clear();
action_enablers_iterate(enabler) {
if (!enabler->ruledit_disabled) {
if (!enabler->rulesave.ruledit_disabled) {
char buffer[512];
QListWidgetItem *item;
......
void tab_enabler::delete_now()
{
if (selected != nullptr) {
selected->ruledit_disabled = true;
selected->rulesave.ruledit_disabled = true;
refresh();
update_enabler_info(nullptr);
......
// Try to reuse freed enabler slot
action_enablers_iterate(enabler) {
if (enabler->ruledit_disabled) {
if (enabler->rulesave.ruledit_disabled) {
if (initialize_new_enabler(enabler)) {
enabler->ruledit_disabled = false;
enabler->rulesave.ruledit_disabled = false;
update_enabler_info(enabler);
refresh();
}
tools/ruleutil/rulesave.c
action_enablers_iterate(pae) {
char path[512];
if (pae->ruledit_disabled) {
if (pae->rulesave.ruledit_disabled) {
continue;
}
......
save_reqs_vector(sfile, &(pae->actor_reqs), path, "actor_reqs");
save_reqs_vector(sfile, &(pae->target_reqs), path, "target_reqs");
if (pae->rulesave.comment != nullptr) {
secfile_insert_str(sfile, pae->rulesave.comment, "%s.comment", path);
}
} action_enablers_iterate_end;
return save_ruleset_file(sfile, filename);
    (1-1/1)