任务单 #41120

Counter requirement type

开放日期: 2021-01-08 06:24 最后更新: 2022-04-08 03:09

报告人:
属主:
类型:
状态:
关闭
组件:
里程碑:
优先:
5 - Medium
严重性:
5 - Medium
处理结果:
Fixed
文件:
13

Details

Add a new requirement type 'Counter'. Name of the requirement is name of the counter. Requirement works only at City range for now.

Add new 'checkpoint' int field to struct counter, and set it e.g. 5 for the City Owned counter. Requirement is fulfilled if the value of the requirement is at least checkpoint.

Test for example by introducing a ruleset rule that when city has been owned less than those 5 turns, it suffers extra unhappiness.

任务单历史 (3/47 Histories)

2021-01-08 06:24 Updated by: cazfi
  • New Ticket "Counter requirement type" created
2022-02-19 19:15 Updated by: lachu
评论

Hi. Maybe set default value of Owned counter to 5? When City is conquered or transfer in other way, the value is set to 5, so we had extra unhappiness. But we can avoid unhappy for newly created cities, by setting this value to 5 by default.

2022-02-21 02:30 Updated by: lachu
评论

H Reply To cazfi

Add a new requirement type 'Counter'. Name of the requirement is name of the counter. Requirement works only at City range for now. Add new 'checkpoint' int field to struct counter, and set it e.g. 5 for the City Owned counter. Requirement is fulfilled if the value of the requirement is at least checkpoint. Test for example by introducing a ruleset rule that when city has been owned less than those 5 turns, it suffers extra unhappiness.

I provided changes. It works. I tested in this way: 1. Ran game 2. Add empty enemy city (big city, with 7 population) 3. Add some my units (tanks) 4. Conquer city 5. Open conquered city's window 6. Keeping this window open (always on top), skip five turns 7. See people stop be unhappy

2022-02-22 17:32 Updated by: cazfi
评论

- You should not set checkpoint to 5 for ALL counters in counters_init(), but set for "Owned" counter only when initializing 'static struct counter counters'
- Document the new requirement type in README.effects ("Requirement types and supported ranges" section)
- Use uppercase boolean macro, instead of assuming actual boolean type, in C-code: false -> FALSE
- req_text_insert(): This should use translated name, not rule name. Same in universal_name_translation(). Unfortunately we don't have translated name yet -> I'll open a new ticket about that in a moment
- Add empty line between variable declarations and code, i.e., after "struct counter *count = req->source.value.counter;"
- No space after ! (not): "if (! target_city) {" -> "if (!target_city) {"
- Indentation wrong in worklist_item_post()

2022-02-22 21:32 Updated by: alienvalkyrie
评论

This patch is not up to date with more recent changes to master; in is_req_active(), you'll want to use context->city rather than target_city (since #43809). I only skimmed the patch and didn't test it, so there might be other things too; you'll likely want to rebase your local changes onto a current version of master. (If you don't know how to do that – stash or commit your local changes, then git pull --rebase; if there are any conflicts, you'll be prompted to resolve them on a patch-by-patch basis.)

2022-02-23 01:40 Updated by: lachu
评论

Reply To cazfi

- You should not set checkpoint to 5 for ALL counters in counters_init(), but set for "Owned" counter only when initializing 'static struct counter counters'

Done

- Document the new requirement type in README.effects ("Requirement types and supported ranges" section)

Will be done in separate patch

- Use uppercase boolean macro, instead of assuming actual boolean type, in C-code: false -> FALSE

Done

- req_text_insert(): This should use translated name, not rule name. Same in universal_name_translation(). Unfortunately we don't have translated name yet -> I'll open a new ticket about that in a moment

Not done at the moment. I use invocation of universal_untranslated_name instead of returning rulename directly from struct

- Add empty line between variable declarations and code, i.e., after "struct counter *count = req->source.value.counter;"

Done

- No space after ! (not): "if (! target_city) {" -> "if (!target_city) {"

Done

- Indentation wrong in worklist_item_post()

Done

2022-02-23 02:50 Updated by: lachu
评论

Sorry you must wait.

2022-02-24 01:38 Updated by: lachu
评论

Sorry you must wait. Reply To cazfi

- You should not set checkpoint to 5 for ALL counters in counters_init(), but set for "Owned" counter only when initializing 'static struct counter counters'
- Document the new requirement type in README.effects ("Requirement types and supported ranges" section)
- Use uppercase boolean macro, instead of assuming actual boolean type, in C-code: false -> FALSE
- req_text_insert(): This should use translated name, not rule name. Same in universal_name_translation(). Unfortunately we don't have translated name yet -> I'll open a new ticket about that in a moment
- Add empty line between variable declarations and code, i.e., after "struct counter *count = req->source.value.counter;"
- No space after ! (not): "if (! target_city) {" -> "if (!target_city) {"
- Indentation wrong in worklist_item_post()

Probably done.

2022-02-27 01:11 Updated by: lachu
评论

I think, why nobody response. I see I miss one problem: I use false statement instead of FALSE macrodefinition present in older version of C language.

2022-02-27 01:56 Updated by: alienvalkyrie
评论

Sorry for radio silence; happens sometimes.

counters.c: I believe cazfi meant to adjust the definition in the counters array at the very top of the file to set the checkpoint, rather than in counters_init(). In fact, because a new member is added to the counter struct, that definition needs to be adjusted anyway. It might also be sensible to use designated initialization a la { .rule_name = "Owned", .type = COUNTER_OWNED, /* etc */ }, since there are now two integer members that could cause confusion.

requirements.c, is_req_active(): Set eval variable rather than returning directly, and use tristate values, i.e. BOOL_TO_TRISTATE macro for the comparison and TRI_MAYBE when the city is null (to make sure negated requirements and different requirement problem types are handled correctly).

rssanity.c: Please mind the line length; try to keep lines below 77 characters (also see the doc/CodingStyle document).

README.effects is still missing info on Counter requirements (or rather, only exists in a separate patch – we'd like everything to be in one patch).

requirements.c, universal_name_translation() and reqtext.c, req_text_insert(): Since we are currently missing counter_name_translation() those can't be covered yet ~> #43989 must be resolved first.

(Edited, 2022-02-27 02:04 Updated by: alienvalkyrie)
2022-03-02 23:46 Updated by: lachu
评论

Reply To alienvalkyrie

I think everything is fine now.

(Edited, 2022-03-02 23:47 Updated by: lachu)
2022-03-03 03:02 Updated by: alienvalkyrie
评论

In common/requirements.c, req_from_str(), the first switch (to find a default range) is missing a VUT_COUNTER case. Tip: configure with --enable-debug to get compile errors for missing cases.

In ai/default/daieffects.c, dai_can_requirement_be_met_in_city(): The VUT_COUNTER case should probably be grouped together with the other cases without sensible handling at the bottom.

In common/reqtext.c, req_text_insert(): Use the translated name, and make sure there's a blank line before and after your case (in style with surrounding code). There also needs to be different text for present and negated requirements. I also think it might be sensible to have the word "counter" in there, since a counter name by itself might be ambiguous/hard to understand; smth like "Requires %s counter at %d or higher." and Requires %s counter below %d.", respectively.

In common/requirements.c, universal_number(): Should return the unique ID of the counter, so it can be retrieved via universal_by_number()/counter_by_id(). It would probably be sensible to add a function called counter_id or counter_number to counters.[ch] for this purpose.

In common/requirements.c, req_from_str(), in the second switch (valid ranges), the indentation is off.

In common/requirements.c, is_req_active(): Can you bring the VUT_COUNTER case in line with the surrounding code?

  • clean up blank lines / formatting
  • the count variable only is only needed inside the else branch
  • set eval rather than returning
  • wrap the result of the value comparison in BOOL_TO_TRISTATE()

Tip: You can look at the other cases (e.g. government or style) to see what the code should look like.

In common/requirements.c, universal_name_translation() should use the translated counter name, as well as return the buffer (like the other cases).

In server/cityturn.c, worklist_item_postpone_req_vec(), counter requirements aren't handled.

In server/rssanity.c, sanity_check_req_set(), don't delete the newline after the previous case.

doc/README.effects is STILL missing info on Counter requirements in this patch.

In general, commit messages should mention the relevant ticket (i.e. this one) as well as the person who reported a bug or requested a feature (when applicable).

For the future, please look at how similar things are done in other places (e.g. surrounding code), to make sure you're not missing anything.

2022-03-04 23:47 Updated by: lachu
  • File 0001-OSDN-41120-S-awomir-Lach.patch (File ID: 8683) is attached
2022-03-04 23:50 Updated by: lachu
  • File 0001-OSDN-41120-S-awomir-Lach.patch (File ID: 8683) is deleted
2022-03-04 23:52 Updated by: lachu
评论

Reply To alienvalkyrie

In ai/default/daieffects.c, dai_can_requirement_be_met_in_city(): The VUT_COUNTER case should probably be grouped together with the other cases without sensible handling at the bottom.

Thanks. It should and I made an mistake. Maybe if somebody else will change code in other part, it will causes error.

In common/requirements.c, universal_number(): Should return the unique ID of the counter, so it can be retrieved via universal_by_number()/counter_by_id(). It would probably be sensible to add a function called counter_id or counter_number to counters.[ch] for this purpose.

Thanks. Big my mistake. I decided to ask you, what do you mean, but while typing this ,message, I saw (I mean look inside the code - English is not my strong skill) to code and repair bug.

I will send patch in few seconds.

(Edited, 2022-03-05 23:22 Updated by: lachu)
2022-03-06 20:12 Updated by: lachu
评论

Reply To alienvalkyrie

Maybe I do not told clear. I think all problems were addressed by latest patch.

2022-03-12 23:48 Updated by: cazfi
评论

- is_req_active(): "} else {" should be one line
- is_req_active(): add empty line between "struct counter *count = ..." and "eval ="
- worklist_item_postpone_req_vec(): comment talking about "techs" when you are handling counters

2022-03-13 19:14 Updated by: lachu
评论

Reply To cazfi

- is_req_active(): "} else {" should be one line
- is_req_active(): add empty line between "struct counter *count = ..." and "eval ="
- worklist_item_postpone_req_vec(): comment talking about "techs" when you are handling counters

I done three changes you suggested.

2022-03-14 04:15 Updated by: cazfi
评论

Reply To lachu

Reply To cazfi

- is_req_active(): "} else {" should be one line

- There is another instance of multi-line "} else {" in req_text_insert()
More importantly, you need to rebase the patch against current git master HEAD. It doesn't apply in its current form.
2022-03-15 02:49 Updated by: lachu
评论

Reply To cazfi

Reply To lachu

Reply To cazfi

- is_req_active(): "} else {" should be one line

- There is another instance of multi-line "} else {" in req_text_insert()

Repaired

More importantly, you need to rebase the patch against current git master HEAD. It doesn't apply in its current form.

Rebased

2022-03-15 03:48 Updated by: cazfi
评论

Build fails (while building ruledit, do you have Qt >= 5.11 so you could enable it?)

CC univ_value.o

../../../../src/tools/ruledit/univ_value.c: In function ‘universal_value_initial’:
../../../../src/tools/ruledit/univ_value.c:42:3: error: enumeration value ‘VUT_COUNTER’ not handled in switch (-Werror=switch)

42 | switch (src->kind) {
| ~

../../../../src/tools/ruledit/univ_value.c: In function ‘universal_kind_values’:
../../../../src/tools/ruledit/univ_value.c:238:3: error: enumeration value ‘VUT_COUNTER’ not handled in switch (-Werror=switch)

238 | switch (univ->kind) {
| ~

cc1: all warnings being treated as errors

2022-03-16 01:14 Updated by: lachu
评论

On my system exist Qt 5.15.2 . I do not enable Qt, but when enabling ruleup, everything does compile.

2022-03-16 01:19 Updated by: cazfi
评论

Reply To lachu

On my system exist Qt 5.15.2 . I do not enable Qt, but when enabling ruleup, everything does compile.

It's ruledit failing, not ruleup. As you have Qt5 instead of Qt6, you need to use --with-qtver=qt5 to be able to build any of our Qt-based programs (Qt-client, Qt modpack installer, Ruledit)

2022-03-17 04:04 Updated by: lachu
2022-03-17 04:05 Updated by: lachu
  • File 0001-OSDN-41120-S-awomir-Lach-Introduce-checkpoint-value-.patch (File ID: 8773) is deleted
2022-03-17 04:06 Updated by: lachu
评论

I think it should work. But I had message patch do not apply, when I try to apply it.

EDIT:

After

git reset --hard HEAD~1

git am ./patch_name

apply

I previously test on other copy

(Edited, 2022-03-17 04:09 Updated by: lachu)
2022-03-20 11:55 Updated by: cazfi
评论

I'm going to do some testing on this in a moment, but one thing missed so far is that req_text_insert() has a bug, I think. For !present requirement it says "at maximum %d value", but if the counter value is exactly the checkpoint it's going to meet 'present' (like text for 'present' correctly indicates), not '!present' requirement. So should be "less than %d"

2022-03-30 18:17 Updated by: cazfi
评论

Reply To cazfi

For !present requirement it says "at maximum %d value", but if the counter value is exactly the checkpoint it's going to meet 'present' (like text for 'present' correctly indicates), not '!present' requirement. So should be "less than %d"

Is there a new patch version coming? (I know it's been only ten days - just confirming that you noticed this)

2022-03-31 03:46 Updated by: None
评论

Reply To cazfi

Reply To cazfi

For !present requirement it says "at maximum %d value", but if the counter value is exactly the checkpoint it's going to meet 'present' (like text for 'present' correctly indicates), not '!present' requirement. So should be "less than %d"

Is there a new patch version coming? (I know it's been only ten days - just confirming that you noticed this)

I do not even start. I wait when you do tests and return from holidays few days ago. I will introduce this little change tomorrow.

2022-04-01 00:20 Updated by: lachu
评论

Reply To cazfi

Reply To cazfi

For !present requirement it says "at maximum %d value", but if the counter value is exactly the checkpoint it's going to meet 'present' (like text for 'present' correctly indicates), not '!present' requirement. So should be "less than %d"

Is there a new patch version coming? (I know it's been only ten days - just confirming that you noticed this)

As I promised, you can check my patch: "Merge with upstream and repair wrong helptext message" .

2022-04-02 00:48 Updated by: cazfi
  • 属主 Update from (无) to cazfi
  • 处理结果 Update from to Accepted
评论

Reply To cazfi

For !present requirement it says "at maximum %d value", but if the counter value is exactly the checkpoint it's going to meet 'present' (like text for 'present' correctly indicates), not '!present' requirement. So should be "less than %d"

Is there a new patch version coming? (I know it's been only ten days - just confirming that you noticed this)

2022-04-02 09:29 Updated by: alienvalkyrie
  • 处理结果 Update from Accepted to
评论

is_req_active() has a return TRI_MAYBE; instead of eval = TRI_MAYBE;

2022-04-02 19:05 Updated by: cazfi
评论

Reply To alienvalkyrie

is_req_active() has a return TRI_MAYBE; instead of eval = TRI_MAYBE;

True. That's a bug. Also, when looking at it, noticed that indentation there is wrong (3 spaces instead of 2)

2022-04-03 20:39 Updated by: lachu
评论

Reply To cazfi

Reply To alienvalkyrie

is_req_active() has a return TRI_MAYBE; instead of eval = TRI_MAYBE;

True. That's a bug. Also, when looking at it, noticed that indentation there is wrong (3 spaces instead of 2)

Done.

2022-04-06 09:04 Updated by: cazfi
  • 处理结果 Update from to Accepted
评论

I've tested that the latest patch compiles in my "standard setup". Will try to test with some more exotic build configurations too while it's in my stack of patches awaiting pushing in (tests to the entire stack, that is)

2022-04-08 03:09 Updated by: cazfi
  • 状态 Update from 开启 to 关闭
  • 处理结果 Update from Accepted to Fixed

Attachment File List

编辑

Please login to add comment to this ticket » 登录名