From d93424a312cb8d6dbb0a40fe50d14e0997694142 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 28 Nov 2022 05:32:41 +0200 Subject: [PATCH 37/37] Add effects' comment support See osdn #46131 Signed-off-by: Marko Lindqvist --- common/effects.c | 27 +++++++++++++++++----- common/effects.h | 13 ++++++++--- data/alien/effects.ruleset | 2 ++ data/civ1/effects.ruleset | 2 ++ data/civ2/effects.ruleset | 2 ++ data/civ2civ3/effects.ruleset | 2 ++ data/classic/effects.ruleset | 2 ++ data/goldkeep/effects.ruleset | 2 ++ data/granularity/effects.ruleset | 2 ++ data/multiplayer/effects.ruleset | 2 ++ data/ruledit/comments-3.2.txt | 4 +++- data/sandbox/effects.ruleset | 2 ++ data/stub/effects.ruleset | 2 ++ data/webperimental/effects.ruleset | 2 ++ server/ruleset.c | 9 +++++++- tools/ruledit/effect_edit.cpp | 36 +++++++++++++++++++++++++----- tools/ruledit/effect_edit.h | 3 +++ tools/ruleutil/rulesave.c | 7 +++++- 18 files changed, 104 insertions(+), 17 deletions(-) diff --git a/common/effects.c b/common/effects.c index 32472ac4ca..eb1248d158 100644 --- a/common/effects.c +++ b/common/effects.c @@ -193,13 +193,31 @@ struct effect *effect_new(enum effect_type type, int value, effect_list_append(get_effects(type), peffect); /* Only relevant for ruledit and other rulesave users. */ - peffect->ruledit_do_not_save = FALSE; + peffect->rulesave.do_not_save = FALSE; + peffect->rulesave.comment = NULL; return peffect; } +/**********************************************************************//** + Free resources reserved for the effect. + + This does not remove effect from the cache lists. + See effect_remove() for that. +**************************************************************************/ +void effect_free(struct effect *peffect) +{ + requirement_vector_free(&peffect->reqs); + if (peffect->rulesave.comment != NULL) { + free(peffect->rulesave.comment); + } + free(peffect); +} + /**********************************************************************//** Remove effect from the caches. + + This does not free effect itself. See effect_free() for that. **************************************************************************/ void effect_remove(struct effect *peffect) { @@ -270,8 +288,8 @@ void ruleset_cache_init(void) } /**********************************************************************//** - Free the ruleset cache. This should be called at the end of the game or - when the client disconnects from the server. See ruleset_cache_init. + Free the ruleset cache. This should be called at the end of the game or + when the client disconnects from the server. See ruleset_cache_init(). **************************************************************************/ void ruleset_cache_free(void) { @@ -280,8 +298,7 @@ void ruleset_cache_free(void) if (tracker_list) { effect_list_iterate(tracker_list, peffect) { - requirement_vector_free(&peffect->reqs); - free(peffect); + effect_free(peffect); } effect_list_iterate_end; effect_list_destroy(tracker_list); ruleset_cache.tracker = NULL; diff --git a/common/effects.h b/common/effects.h index 3372826cf7..92d4589866 100644 --- a/common/effects.h +++ b/common/effects.h @@ -366,9 +366,15 @@ struct effect { * active if all of these requirement are met. */ struct requirement_vector reqs; - /* Only relevant for ruledit and other rulesave users. Indicates that - * this effect is deleted and shouldn't be saved. */ - bool ruledit_do_not_save; + /* Only relevant for ruledit and other rulesave users. */ + struct { + /* Indicates that this effect is deleted and shouldn't be saved. */ + bool do_not_save; + + /* Comment field to save. While an entry in the ini-file, not + * used by freeciv. */ + char *comment; + } rulesave; }; /* An effect_list is a list of effects. */ @@ -382,6 +388,7 @@ struct effect { struct effect *effect_new(enum effect_type type, int value, struct multiplier *pmul); struct effect *effect_copy(struct effect *old); +void effect_free(struct effect *peffect); void effect_remove(struct effect *peffect); void effect_req_append(struct effect *peffect, struct requirement req); diff --git a/data/alien/effects.ruleset b/data/alien/effects.ruleset index 164c7fe7dd..8e3a9eb581 100644 --- a/data/alien/effects.ruleset +++ b/data/alien/effects.ruleset @@ -41,6 +41,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/civ1/effects.ruleset b/data/civ1/effects.ruleset index 5b23a07ad4..294579d33f 100644 --- a/data/civ1/effects.ruleset +++ b/data/civ1/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/civ2/effects.ruleset b/data/civ2/effects.ruleset index 0f7f5fa5be..c0cdc5caa8 100644 --- a/data/civ2/effects.ruleset +++ b/data/civ2/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/civ2civ3/effects.ruleset b/data/civ2civ3/effects.ruleset index ed47779617..8833990421 100644 --- a/data/civ2civ3/effects.ruleset +++ b/data/civ2civ3/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/classic/effects.ruleset b/data/classic/effects.ruleset index 2a52060bc3..c384776b6c 100644 --- a/data/classic/effects.ruleset +++ b/data/classic/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/goldkeep/effects.ruleset b/data/goldkeep/effects.ruleset index 0e782b4651..4b2c23b456 100644 --- a/data/goldkeep/effects.ruleset +++ b/data/goldkeep/effects.ruleset @@ -42,6 +42,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/granularity/effects.ruleset b/data/granularity/effects.ruleset index 9dc57b1e19..dbb761c3ce 100644 --- a/data/granularity/effects.ruleset +++ b/data/granularity/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/multiplayer/effects.ruleset b/data/multiplayer/effects.ruleset index cf1c485415..523efd3c78 100644 --- a/data/multiplayer/effects.ruleset +++ b/data/multiplayer/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/ruledit/comments-3.2.txt b/data/ruledit/comments-3.2.txt index 36e9d2919e..50f5b2c960 100644 --- a/data/ruledit/comments-3.2.txt +++ b/data/ruledit/comments-3.2.txt @@ -1000,9 +1000,11 @@ effects = "\ ; See README.effects for list of possible types\n\ ; value = Value added for the effect type when this effect is active,\n\ ; i.e., all requirements are fulfilled\n\ -; multiplier = Name of the policy that gives a multiplier for effect's value\n\ +; multiplier = Name of the policy that gives a multiplier for effect\'s value\n\ ; reqs = Requirements for the effect to be active.\n\ ; See README.effects for help on requirements\n\ +; comment = Comment for the benefit to someone examining the ruleset\n\ +; Not used by freeciv any other way.\n\ ;\n\ ; */ <-- avoid gettext warnings\n\ " diff --git a/data/sandbox/effects.ruleset b/data/sandbox/effects.ruleset index 93b9a2d26c..3013eba5b4 100644 --- a/data/sandbox/effects.ruleset +++ b/data/sandbox/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/stub/effects.ruleset b/data/stub/effects.ruleset index 043e6d3e9f..fb9b31b72c 100644 --- a/data/stub/effects.ruleset +++ b/data/stub/effects.ruleset @@ -31,6 +31,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/data/webperimental/effects.ruleset b/data/webperimental/effects.ruleset index 4123465f5d..57af055eed 100644 --- a/data/webperimental/effects.ruleset +++ b/data/webperimental/effects.ruleset @@ -39,6 +39,8 @@ format_version = 30 ; multiplier = Name of the policy that gives a multiplier for effect's value ; reqs = Requirements for the effect to be active. ; See README.effects for help on requirements +; comment = Comment for the benefit to someone examining the ruleset +; Not used by freeciv any other way. ; ; */ <-- avoid gettext warnings diff --git a/server/ruleset.c b/server/ruleset.c index 697d24535b..58ba67fd6c 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -293,7 +293,7 @@ static int ruleset_purge_unused_effects(void) type = effect_type_next(type)) { effect_list_iterate(get_effects(type), eft) { if (req_vec_is_impossible_to_fulfill(&eft->reqs)) { - eft->ruledit_do_not_save = TRUE; + eft->rulesave.do_not_save = TRUE; purged++; log_normal("Purged unused effect for %s", effect_type_name(eft->type)); @@ -6173,6 +6173,7 @@ static bool load_ruleset_effects(struct section_file *file, const char *sec_name = section_name(psection); struct requirement_vector *reqs; const char *type; + const char *comment; type = secfile_lookup_str(file, "%s.type", sec_name); @@ -6225,6 +6226,12 @@ static bool load_ruleset_effects(struct section_file *file, effect_req_append(peffect, *preq); } requirement_vector_iterate_end; + comment = secfile_lookup_str_default(file, NULL, "%s.comment", sec_name); + + if (comment != NULL) { + peffect->rulesave.comment = fc_strdup(comment); + } + } section_list_iterate_end; section_list_destroy(sec); diff --git a/tools/ruledit/effect_edit.cpp b/tools/ruledit/effect_edit.cpp index 30222fa109..287c360953 100644 --- a/tools/ruledit/effect_edit.cpp +++ b/tools/ruledit/effect_edit.cpp @@ -99,7 +99,6 @@ effect_edit::effect_edit(ruledit_gui *ui_in, QString target, main_layout->addLayout(active_layout); row = 0; - mp_button = new QToolButton(); mp_button->setParent(this); mp_button->setToolButtonStyle(Qt::ToolButtonTextOnly); @@ -111,23 +110,29 @@ effect_edit::effect_edit(ruledit_gui *ui_in, QString target, multipliers_re_active_iterate(pmul) { menu->addAction(multiplier_rule_name(pmul)); } multipliers_re_active_iterate_end; - effect_edit_layout->addWidget(mp_button, row++, 0); + effect_edit_layout->addWidget(mp_button, row++, 0, 1, 2); + + lbl = new QLabel(QString::fromUtf8(R__("Comment"))); + effect_edit_layout->addWidget(lbl, row, 0); + comment = new QLineEdit(this); + connect(comment, SIGNAL(returnPressed()), this, SLOT(comment_given())); + effect_edit_layout->addWidget(comment, row++, 1); button = new QPushButton(QString::fromUtf8(R__("Requirements")), this); connect(button, SIGNAL(pressed()), this, SLOT(edit_reqs())); - effect_edit_layout->addWidget(button, row++, 0); + effect_edit_layout->addWidget(button, row++, 0, 1, 2); button = new QPushButton(QString::fromUtf8(R__("Add Effect")), this); connect(button, SIGNAL(pressed()), this, SLOT(add_now())); - effect_edit_layout->addWidget(button, row++, 0); + effect_edit_layout->addWidget(button, row++, 0, 1, 2); button = new QPushButton(QString::fromUtf8(R__("Delete Effect")), this); connect(button, SIGNAL(pressed()), this, SLOT(delete_now())); - effect_edit_layout->addWidget(button, row++, 0); + effect_edit_layout->addWidget(button, row++, 0, 1, 2); close_button = new QPushButton(QString::fromUtf8(R__("Close")), this); connect(close_button, SIGNAL(pressed()), this, SLOT(close_now())); - effect_edit_layout->addWidget(close_button, row++, 0); + effect_edit_layout->addWidget(close_button, row++, 0, 1, 2); refresh(); @@ -258,6 +263,7 @@ void effect_edit::fill_active() } else { mp_button->setText(NO_MULTIPLIER_NAME); } + comment->setText(selected->rulesave.comment); } else { mp_button->setText(NO_MULTIPLIER_NAME); } @@ -368,3 +374,21 @@ void effect_edit::multiplier_menu(QAction *action) refresh(); } + +/**********************************************************************//** + User entered comment for the building +**************************************************************************/ +void effect_edit::comment_given() +{ + if (selected != nullptr) { + if (selected->rulesave.comment != NULL) { + free(selected->rulesave.comment); + } + + if (!comment->text().isEmpty()) { + selected->rulesave.comment = fc_strdup(comment->text().toUtf8()); + } + + fill_active(); + } +} diff --git a/tools/ruledit/effect_edit.h b/tools/ruledit/effect_edit.h index ab3d6ed73d..7726a62d4c 100644 --- a/tools/ruledit/effect_edit.h +++ b/tools/ruledit/effect_edit.h @@ -26,6 +26,7 @@ // common #include "requirements.h" +class QLineEdit; class QSpinBox; class ruledit_gui; @@ -75,6 +76,7 @@ class effect_edit : public QDialog QSpinBox *value_box; QToolButton *mp_button; + QLineEdit *comment; private slots: void select_effect(); @@ -87,6 +89,7 @@ class effect_edit : public QDialog void effect_type_menu(QAction *action); void set_value(int value); void multiplier_menu(QAction *action); + void comment_given(); protected: void closeEvent(QCloseEvent *event); diff --git a/tools/ruleutil/rulesave.c b/tools/ruleutil/rulesave.c index 74df11ae92..7a7b221e0d 100644 --- a/tools/ruleutil/rulesave.c +++ b/tools/ruleutil/rulesave.c @@ -767,7 +767,7 @@ static bool effect_save(struct effect *peffect, void *data) effect_cb_data *cbdata = (effect_cb_data *)data; char path[512]; - if (peffect->ruledit_do_not_save) { + if (peffect->rulesave.do_not_save) { /* Is supposed to be skipped. */ return TRUE; } @@ -781,6 +781,11 @@ static bool effect_save(struct effect *peffect, void *data) save_reqs_vector(cbdata->sfile, &peffect->reqs, path, "reqs"); + if (peffect->rulesave.comment != NULL) { + secfile_insert_str(cbdata->sfile, peffect->rulesave.comment, + "%s.comment", path); + } + return TRUE; } -- 2.35.1