Feature #1677
closedallow terrain to have > 1 animal
0%
Description
In terrain.ruleset, animal="..." currently only supports 1 animal. I would like to use a comma separated list.
Files
Updated by Dean Brown 2 months ago
- File 1677.patch added
- File 1677Main.patch added
Causes a change to network packets, so expecting target 3.3.0.
I wanted to change the "animal = ..." to "animals = ..." in the terrain.ruleset files, but that breaks freeciv-ruleup. In file
server/ruleset/ruleload.c, routine load_ruleset_terrain() would have to try to lookup both "%s.animal" and "%s.animals" to make freeciv-ruleup work.
I can update the wiki page [[http://www.freeciv.org/wiki/How_to_update_a_ruleset_from_3.2_to_3.3]] when this is done.
Updated by Marko Lindqvist 2 months ago
- Category changed from Rulesets to General
- Target version set to 3.4.0-d3f
- Since this is not going to S3_2 or older, use nullptr instead of NULL
- As you said: "animal" needs to be changed to "animals"
- Style: Empty line between variable declarations and first line of code within the block
- Style: Some broken indentation
- It would be better to store num_animals in the terrain structure (just a few integers more memory taken) than to burn CPU to figure out the count every time it's needed
- In the client side terrain.animals must be initially initialized to nullptr, and in the server side it wouldn't hurt (so can be done in common code). Otherwise we may have non-nullptr animals, when in fact there's no animals
- 'FALSE' and 'TRUE', not 'false' and 'true' (Yeah, that's something we probably should change in coming versions, but I'd rather concentrate NULL > nullptr migration for now, instead of starting another migration already) Style: "if (! ok) {" -> "if (!ok) {" (no space after '!')
Updated by Dean Brown 2 months ago
- File 1677.patch added
- File 1677Main.patch added
Thanks for the feedback, here's updated better patches. I figured out how to use rscompat to avoid breaking freeciv-ruleup.
I originally made the terrain->animals to be null-terminated like the terrain->resources, but I agree it's better to also have
terrain->num_animals. It might also be better if terrain->resources were to be re-done similarly, but that's out of scope for this issue.
Updated by Marko Lindqvist about 2 months ago
- Target version changed from 3.4.0-d3f to 3.3.0-d3f
Updated by Marko Lindqvist about 2 months ago
- Blocks Tasks #1631: S3_3 datafileformat freeze (d3f) added
Updated by Marko Lindqvist about 1 month ago
I reviewed S3_3 patch (one with the rscompat part). Presumably most comments apply to main patch too
- Style: Empty line between variable declarations and first line of code within the block (still missing in some places)
- In case of "None" rscompat animal, the animals is set to nullptr without freeing the memory that it previously pointed to
- There is no need to support special value "None" for animals, as empty array gives the same result. (Old 'animal' needed it as 'animal' was a mandatory field to be always present)
- In rulesets, addition of 's' push rest of the line one character off. Remove one space to compensate.
- Several "} terrain_animals_iterate_end" with extra space (two spaces) between '}' and 'terrain_animals_iterate_end'
Updated by Dean Brown about 1 month ago
- File 1677.patch added
- File 1677Main.patch added
Yes both patches needed fixing.
Going forward, animals = "None" will generate a ruleset load error. Which is OK - that's how "Resources = ..." works.
Updated by Marko Lindqvist 26 days ago
- Status changed from New to In Review
- Assignee set to Marko Lindqvist
Updated by Marko Lindqvist 22 days ago
Starting tutorial scenario, I get
1: Trying to put 539309362 into 16 bits; it will result 13618 at receiving side.
Debugging that with the help of FIELD_RANGE_ASSERT of dataio_raw.c, I found out that it comes from the packets_gen.c line
e |= DIO_PUT(sint16, &dout, &field_addr, real_packet->animals[i]);
Updated by Marko Lindqvist 22 days ago
I guess the issue is in send_ruleset_terrain():
terrain_animals_iterate(pterrain, panimal) {
packet.animals[packet.num_animals] = utype_number(panimal);
} terrain_animals_iterate_end;
On every round of the iteration it places the animal to the same index (packet.num_animals), actually outside the whole legal range (0 ... num_animals-1). All the actually used indices are left with garbage values.
Updated by Marko Lindqvist 22 days ago
- Status changed from In Review to In Progress
- Assignee changed from Marko Lindqvist to Dean Brown
Updated by Dean Brown 21 days ago
- File 1677.patch 1677.patch added
- File 1677Main.patch 1677Main.patch added
Surprised my testing didn't catch that. Fixed patches.
Updated by Marko Lindqvist 19 days ago
- Status changed from In Progress to In Review
- Assignee changed from Dean Brown to Marko Lindqvist