Tíquete #47292

Unit counters framework

: 2023-02-03 03:25 Última Atualização: 2023-06-10 07:16

Relator:
Dono:
(Nenhum)
Tipo:
Estado:
Aberto
Componente:
Marcos:
Prioridade:
5 - Medium
Gravidade:
5 - Medium
Resolução:
Nenhum
Arquivo:
10

Details

Add initial support for unit counters. No need to implement any counter behavior in this ticket - current counters code should be flexible enough to work (iterate over) zero counter behaviors and counter instances.

---

- Add counter_target type "Unit"
- Add counters_get_unit_counters_count()
- Implement unit_counters_iterate(pcount) macro (mostly by copying ciyt_counters_iterate() and modifying a bit)
- Add "counter_values" to unit structure

Savegame part likely isn't as trivial "copy from city counters implementation" -> let's leave that to another ticket.

Ticket History (3/32 Histories)

2023-02-03 03:25 Updated by: cazfi
  • New Ticket "Unit counters framework" created
2023-02-15 00:33 Updated by: lachu
Comentário

I doubt it was good idea to copy counters mechanism from cities. Some counters may be not be related to some unit type/classes/etc. For example priest convert action should be related only to priest. But counters for cities implementation is quite simple, so it could be copied 1:1.

2023-02-23 04:36 Updated by: lachu
Comentário

Reply To cazfi

Add initial support for unit counters. No need to implement any counter behavior in this ticket - current counters code should be flexible enough to work (iterate over) zero counter behaviors and counter instances. --- - Add counter_target type "Unit"
- Add counters_get_unit_counters_count()
- Implement unit_counters_iterate(pcount) macro (mostly by copying ciyt_counters_iterate() and modifying a bit)
- Add "counter_values" to unit structure
Savegame part likely isn't as trivial "copy from city counters implementation" -> let's leave that to another ticket.

Sorry I do not reply, but create new post. Read above post, please.

2023-03-11 19:43 Updated by: cazfi
Comentário

Reply To lachu

I doubt it was good idea to copy counters mechanism from cities.

Not to copy, but to use existing generic code.

2023-03-22 23:17 Updated by: lachu
Comentário

I think, we should:

1. Define new range for counter - unit

  1. [counter_spread_religion]
  2. name = "Belief_spread"
  3. def = 5
  4. type = "User"
  5. range = "Unit"

2. Allow to assign unit counter to unit type

  1. [unit_warriors]
  2. name = _("Warriors")
  3. class = "Land"
  4. ;reqs
  5. obsolete_by = "Musketeers"
  6. graphic = "u.warriors"
  7. graphic_alt = "-"
  8. sound_move = "m_warriors"
  9. sound_move_alt = "m_generic"
  10. sound_fight = "f_warriors"
  11. sound_fight_alt = "f_generic"
  12. build_cost = 10
  13. pop_cost = 0
  14. attack = 1
  15. defense = 1
  16. hitpoints = 10
  17. firepower = 1
  18. move_rate = 1
  19. vision_radius_sq = 2
  20. transport_cap = 0
  21. fuel = 0
  22. uk_happy = 1
  23. uk_shield = 1
  24. uk_food = 1
  25. uk_gold = 1
  26. tp_defense = "Alight"
  27. flags = "Capturer", "Fortress", "FleshBased"
  28. roles = "DefendOk", "DefendOkStartUnit", "FirstBuild"
  29. helptext = _("\
  30. This unit may be built from the start of the game. It is the\
  31. weakest offensive unit.\
  32. ")
  33. counters = "Belief_spread"

3. On ruleset loading routine, load each counter name, load each unit and do sanity checks (test if each unit counter is assigned to at least one unit type - warriors have Belief_spread for example). If there exist dangling unit counter, stop loading ruleset and display error.

4. Unit type struct will contain pointers to counters definitions

5. Unit struct will contain counters' values

6. There could still exist global counters array for units type (entire set of unit types), for example for provide help text - maybe it would be necessary, but I am not sure, so 6 point maybe will be removed in future

2023-03-22 23:23 Updated by: cazfi
Comentário

Reply To cazfi

Add initial support for unit counters. No need to implement any counter behavior in this ticket - current counters code should be flexible enough to work (iterate over) zero counter behaviors and counter instances.

If you want to start with really minimal patch, I think you can do just

- Add counter_target type "Unit"

...and to make sure it does not break existing city counter usage.

2023-03-23 02:57 Updated by: lachu
Comentário

Reply To cazfi

Reply To cazfi

Add initial support for unit counters. No need to implement any counter behavior in this ticket - current counters code should be flexible enough to work (iterate over) zero counter behaviors and counter instances.

If you want to start with really minimal patch, I think you can do just

- Add counter_target type "Unit"

...and to make sure it does not break existing city counter usage.

Ok. I see implementing in my way could cause problems, but I am not sure. I see we use index/number and one is kept in counter structure, pointing position of counter in counter-type-related-array. When implementing as I suggested, we have separate array for each unit type, so my suggestion should be well-tested/though again.

2023-03-26 20:14 Updated by: cazfi
Comentário

I would take this in one step at a time. I'm not convinced that we could do radical restructuring of the parts of the counters code we already implemented in 3.2 and then build complex new unit counters on top of that would finish in time for 3.3. Let's try to get the basic use-case of the same counters applying to all units done first. Besides, ruleset would need to use a lot of different unit counters for the benefits of not storing them all for all units would outweigh the overhead of figuring out which counters each unit has and where (same counter could be in different index for different units, depending what other counters they have)

2023-04-01 21:15 Updated by: lachu
Comentário

Reply To cazfi

I would take this in one step at a time. I'm not convinced that we could do radical restructuring of the parts of the counters code we already implemented in 3.2 and then build complex new unit counters on top of that would finish in time for 3.3. Let's try to get the basic use-case of the same counters applying to all units done first. Besides, ruleset would need to use a lot of different unit counters for the benefits of not storing them all for all units would outweigh the overhead of figuring out which counters each unit has and where (same counter could be in different index for different units, depending what other counters they have)

0002-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(11KB)
Introduce counters unit framework

Sorry it takes too long. I had stupid typo (closing parenthesis placement bug, so some values was filled only if there was no counter name).

2023-04-06 01:51 Updated by: lachu
Comentário

Reply To cazfi

I would take this in one step at a time. I'm not convinced that we could do radical restructuring of the parts of the counters code we already implemented in 3.2 and then build complex new unit counters on top of that would finish in time for 3.3. Let's try to get the basic use-case of the same counters applying to all units done first. Besides, ruleset would need to use a lot of different unit counters for the benefits of not storing them all for all units would outweigh the overhead of figuring out which counters each unit has and where (same counter could be in different index for different units, depending what other counters they have)

0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(4KB)
Unit counters basics should now be implemented. It requires previous patch to be applied prior.
2023-04-08 19:03 Updated by: cazfi
Comentário

Looking the source code (files 12039 + 12082. Is that what you mean as the change to the repo?) it looks very good already. Only now that 'target' is read from the rulesets:

- Documentation comments in rulesets & ruledit/comments-3.3.txt need updating
- Rulesave needs to save it
- I think rulecompat needs to add "City" target to all counters loaded from 3.2 rulesets

2023-04-10 19:39 Updated by: lachu
Comentário

Reply To cazfi

Looking the source code (files 12039 + 12082. Is that what you mean as the change to the repo?) it looks very good already.

Yes, but in reverse order.

2023-04-14 00:38 Updated by: lachu
Comentário

Reply To cazfi

Looking the source code (files 12039 + 12082. Is that what you mean as the change to the repo?) it looks very good already. Only now that 'target' is read from the rulesets: - Documentation comments in rulesets & ruledit/comments-3.3.txt need updating
- Rulesave needs to save it
- I think rulecompat needs to add "City" target to all counters loaded from 3.2 rulesets

0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(7KB)
It requires file Introduce counters unit framework
(Edited, 2023-04-14 16:00 Updated by: lachu)
2023-04-14 00:40 Updated by: lachu
Comentário

Reply To cazfi

Looking the source code (files 12039 + 12082. Is that what you mean as the change to the repo?) it looks very good already. Only now that 'target' is read from the rulesets: - Documentation comments in rulesets & ruledit/comments-3.3.txt need updating
- Rulesave needs to save it
- I think rulecompat needs to add "City" target to all counters loaded from 3.2 rulesets

0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(8KB)
Documentation part
2023-04-14 21:37 Updated by: lachu
Comentário

There still many things missing, like network protocol support for unit's counters, etc.

2023-04-22 12:32 Updated by: cazfi
Comentário

"if (info->version > RSFORMAT_3_2) {"

Use ">= RSFORMAT_3_3)" instead. Old RSFORMAT_3_2 macro might get removed soon, and when we clean compat code of the previous version away, we will be searching for RSFORMAT_3_3.

---

- I don't think ruledit_disabled is in any way relevant in rulecompat.

+    if (pcount->ruledit_disabled) {
+      continue;
+    }
+    pcount->target = CTGT_CITY;

2023-04-23 22:31 Updated by: lachu
Comentário

Reply To cazfi

"if (info->version > RSFORMAT_3_2) {" Use ">= RSFORMAT_3_3)" instead. Old RSFORMAT_3_2 macro might get removed soon, and when we clean compat code of the previous version away, we will be searching for RSFORMAT_3_3. --- - I don't think ruledit_disabled is in any way relevant in rulecompat. {{{ + if (pcount->ruledit_disabled) { + continue; + } + pcount->target = CTGT_CITY; }}}

0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(7KB)
Minor changes
2023-05-09 12:10 Updated by: cazfi
Comentário

- Patch does not apply (any more?)
- Missing ruleset documentation about "target" field

- Following check is not strict enough. What if target was given as "blabla"? Even in compat mode, we should only accept the case where the "target" is completely missing:

if (!counter_target_is_valid(ct)) {
...
+          if (compat->version > RSFORMAT_3_2) {
+            ruleset_error(NULL, LOG_ERROR,
+                         "\"%s\" unknown counter target \"%s\".",
+                         filename, counter_type);
+            ok = FALSE;
+            break;
+          }
+          ct = CTGT_CITY;
         }

2023-05-23 02:56 Updated by: lachu
Comentário

2023-05-23 02:55 Updated by: lachu

File 0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch (File ID: 12452) is attached

I send to check if problems were fixed. It still has one problem: when we load ruleset from previous games and set counter_type to unit, it will load it without panic. I must check if ruleset version is older and check if counter_type is different than city.

2023-05-26 22:10 Updated by: lachu
Comentário

Reply To cazfi

- Patch does not apply (any more?)
- Missing ruleset documentation about "target" field
- Following check is not strict enough. What if target was given as "blabla"? Even in compat mode, we should only accept the case where the "target" is completely missing: {{{ if (!counter_target_is_valid(ct)) { ... + if (compat->version > RSFORMAT_3_2) { + ruleset_error(NULL, LOG_ERROR, + "\"%s\" unknown counter target \"%s\".", + filename, counter_type); + ok = FALSE; + break; + } + ct = CTGT_CITY; }

>

0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(8KB)
It should now working. Documentation changes will be placed in next patch.

0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch(8KB)

Documentation
2023-05-27 01:39 Updated by: lachu
Comentário

Reply To cazfi

- Patch does not apply (any more?)
- Missing ruleset documentation about "target" field
- Following check is not strict enough. What if target was given as "blabla"? Even in compat mode, we should only accept the case where the "target" is completely missing: {{{ if (!counter_target_is_valid(ct)) { ... + if (compat->version > RSFORMAT_3_2) { + ruleset_error(NULL, LOG_ERROR, + "\"%s\" unknown counter target \"%s\".", + filename, counter_type); + ok = FALSE; + break; + } + ct = CTGT_CITY; } }}}

2023-05-27 01:35 Updated by: lachu

File 0001-OSDN-47292-S-awomir-Lach-slawek-lach.art.pl.patch (File ID: 12477) is attached

I noticed small problem. When modder set invalid, but not blank target for newer ruleset, one condition check to not bypass, but should and else statement-related-instruction was executed.

Still, during trying to handle this issue, unconditionally I badly noticed some other error (it shown error that counter type is null), so I though It wrote that counter target is null and try to solve that, so (maybe?) code is ugly. Tell me if I should clean-up-it. It uses entry struct instead of testing if string is null from secfile_lookup_str_default function.

2023-06-10 07:16 Updated by: cazfi
Comentário

Sorry the review took so long. (But maybe you too should concentrate primarily to those patches that are targeted to 3.2 already, S3_2 d3f is in a year)

---

- There's one use of "malloc()" that should be "fc_malloc()"
- In load_ruleset_game() reading the counter target entry twice (once with direct secfile_entry_lookup() and once through secfile_lookup_str_default() ) doesn't serve any function, I think. At least we don't do that for anything else. I would drop counter_type_entry
- It would be better to set target correctly for 3.2 counters as soon as they are loaded, and not to all of them after ruleset has been loaded completely. It would make fixing bugs easier in this patch already, and likely becomes only more important during freeciv-3.3 development. Implement something like:

ct = counter_target_by_name(counter_target_3_3(compat, counter_type), fc_strcasecmp);
where counter_target_3_3() will return either counter_type back, or possibly "City" in case of compatibility mode 3.2 ruleset loading.
- Should be on the same line:
+          }
+          else if (CTGT_CITY != ct) {
- "ruleset in format 30" - Use freeciv version numbers instead of format number

---

Didn't look at the documentation yet. If you provide multiple patches to apply, could you at least have different names for them (not overwriting each other when downloaded). Likely the simplest way is to use 'git format-patch' over the entire branch to get "0001-....patch" and "0002-....patch"

Attachment File List

Editar

Please login to add comment to this ticket » Login