Incidencia #41118

Increase city owned counter as needed

Abrir Fecha: 2021-01-08 06:04 Última actualización: 2022-02-21 02:37

Informador:
Propietario:
Tipo:
Estado:
Cerrado
Componente:
Hito:
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Fixed
Fichero:
12

Details

Increase city owned counters (type COUNTER_OWNED) by one every turn. Reset it to zero when city changes owner.

It's best to introduce counter iterator macros already, and use them to find counters to update. This makes it to work when number and order of counters is no longer hardcoded in the future.

Test this by checking from a savegame that counter information saved is what it should.

Ticket History (3/35 Histories)

2021-01-08 06:04 Updated by: cazfi
  • New Ticket "Increase city owned counter as needed" created
2021-01-08 06:52 Updated by: cazfi
  • Details Updated
2021-02-01 01:21 Updated by: lachu
Comentario

Sorry, but in this patch:

https://www.hostedredmine.com/attachments/393326

I don't see any new counter_by_index definition/declaration.

2021-02-01 01:45 Updated by: cazfi
Comentario

See Ticket #41115 description. I guess you meant this comment to that ticket in the first place.

2022-02-07 23:11 Updated by: cazfi
  • Details Updated
2022-02-08 18:46 Updated by: lachu
Comentario

Hi. Can anybody test?

I see problem, which must be introduced with my earlier patch. One city do not have increased counter value (with id 125?). I think it was not saved, but only zero is saved as this counter value.

2022-02-09 18:20 Updated by: cazfi
Comentario

- You should iterate over counters_city (so you would get only city targeted counters), and increase all with the type COUNTER_OWNED, not just one
- Find the counters to update by the type COUNTER_OWNED, not by the name that will be ruleset defined in the future and will be different for each counter even if they have the same type
- Style: 'a++' instead of '++a' when it makes no difference

2022-02-09 18:56 Updated by: lachu
Comentario

Hi. Can anybody test?

I see problem, which must be introduced with my earlier patch. One city do not have increased counter value (with id 125?). I think it was not saved, but only zero is saved as this counter value. Reply To cazfi

- You should iterate over counters_city (so you would get only city targeted counters), and increase all with the type COUNTER_OWNED, not just one

Ok. But the index in city counter's array is the same for each city, so I will iterate once. Right?

PS: Take in mind, array of "counters" in city contains only value of counter. Other information are stored in global array and it was common for each counter stored in structure, which representing city.

- Find the counters to update by the type COUNTER_OWNED, not by the name that will be ruleset defined in the future and will be different for each counter even if they have the same type
- Style: 'a++' instead of '++a' when it makes no difference

Ok.

(Edited, 2022-02-09 18:58 Updated by: lachu)
2022-02-10 02:11 Updated by: lachu
Comentario

No test machinery is done for these macros.

2022-02-11 01:04 Updated by: lachu
  • File 0001-Added-iteration-macro-for-city-counters.patch (File ID: 8497) is attached
2022-02-11 01:08 Updated by: lachu
  • File 0001-Added-iteration-macro-for-city-counters.patch (File ID: 8497) is deleted
2022-02-11 01:14 Updated by: lachu
Comentario

Reply To cazfi

- You should iterate over counters_city (so you would get only city targeted counters), and increase all with the type COUNTER_OWNED, not just one
- Find the counters to update by the type COUNTER_OWNED, not by the name that will be ruleset defined in the future and will be different for each counter even if they have the same type
- Style: 'a++' instead of '++a' when it makes no difference

I only forgot to repair coding-style. And there is still error causes first city on list has save-game (or load-game) problems

2022-02-11 20:57 Updated by: lachu
Comentario

Reply To cazfi

- You should iterate over counters_city (so you would get only city targeted counters), and increase all with the type COUNTER_OWNED, not just one
- Find the counters to update by the type COUNTER_OWNED, not by the name that will be ruleset defined in the future and will be different for each counter even if they have the same type
- Style: 'a++' instead of '++a' when it makes no difference

Now it works. Problem was inside srv_main.c after I mess it there. I put code responsible for increase city counters' value inside loop, which had continue instruction for living players. Tested, but not well. I only play few turns and do save game.

2022-02-13 20:53 Updated by: lachu
Comentario

It was tested in few short games. It worked!

2022-02-13 21:01 Updated by: cazfi
Comentario

- That won't work if there is more than one COUNTER_OWNED type counters.
- You are missing the part setting those counters to zero when the city changes owner
- The city_counters_iterate() macros are missing (I assume this patch should add them). Should also be named like that (just one 'r')

(Edited, 2022-02-13 21:04 Updated by: cazfi)
2022-02-14 23:26 Updated by: lachu
Comentario

0001-Introduce-city-s-counter-iterration.patch (File ID: 8537) is the last patch (I assemble it with previous changes).

Sorry for my previous patch (I forgot about resetting counter's value). I still do not understood why there should be many counter_owned counters? I known, there is type, but I thought it was temporary solution.;

I hope now it will work.

2022-02-14 23:26 Updated by: lachu
Comentario

Reply To cazfi

- That won't work if there is more than one COUNTER_OWNED type counters.
- You are missing the part setting those counters to zero when the city changes owner
- The city_counters_iterate() macros are missing (I assume this patch should add them). Should also be named like that (just one 'r')

Thanks for help, Can you read my last post?

2022-02-15 01:30 Updated by: cazfi
Comentario

Reading (not yet actually testing) the patch, functionality looks good now.

The city_counters_iterate() macro could be improved a bit
- Style: "struct counter * pcount;" - you are not multiplying by 'pcount' but making it a pointer, so no space -> "struct counter *pcount;"
- You should not make a separate call to counters_get_city_counters_count() on every iteration. Call it once before the loop, assign value to variable, and compare against that variable on each iteration. Note next point about naming the variable
- Having static variable name '_i' means that within one city_counters_iterate() there cannot be another city_counters_iterate() (that would cause '_i' of the inner one to shadow one of the outer one). You could make name of the variable derived from pcounts name instead; '_i_##pcount'

2022-02-16 00:33 Updated by: lachu
Comentario

Reply To cazfi

Reading (not yet actually testing) the patch, functionality looks good now. The city_counters_iterate() macro could be improved a bit
- Style: "struct counter * pcount;" - you are not multiplying by 'pcount' but making it a pointer, so no space -> "struct counter *pcount;"
- You should not make a separate call to counters_get_city_counters_count() on every iteration. Call it once before the loop, assign value to variable, and compare against that variable on each iteration. Note next point about naming the variable
- Having static variable name '_i' means that within one city_counters_iterate() there cannot be another city_counters_iterate() (that would cause '_i' of the inner one to shadow one of the outer one). You could make name of the variable derived from pcounts name instead; '_i_##pcount'

Done. Should I wrote some automatic tests? I test it by comparing counter section of two savegames made on the same turn. First before conquering two cities and second after conquering it.

2022-02-17 05:58 Updated by: cazfi
Comentario

The new '_ccounter_count' variable has the same shadowing issue that '_i' had earlier -> make it '_ccounter_count_##pcount'

2022-02-18 00:32 Updated by: lachu
Comentario

Reply To cazfi

The new '_ccounter_count' variable has the same shadowing issue that '_i' had earlier -> make it '_ccounter_count_##pcount'

Done. Sorry. It was my bad,

2022-02-19 05:24 Updated by: cazfi
  • Propietario Update from (Ninguno) to cazfi
  • Resolución Update from Ninguno to Accepted
2022-02-21 02:37 Updated by: cazfi
  • Estado Update from Open to Cerrado
  • Resolución Update from Accepted to Fixed

Attachment File List

Editar

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Entrar