autoworkers improvement - how to get some data

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
Post Reply
sandwave
Posts: 6
Joined: Wed May 14, 2025 2:48 am

autoworkers improvement - how to get some data

Post by sandwave »

I've been working on a new autoworker algorithm that mimics more my play style. I had to relearn C and wrote an algorithm with some unit tests that are independent of freeciv. (I didn't think I could make an algorithm that integrated with the freeciv codebase and unit test it efficiently.)

I'm trying to integrate my algorithm with freeciv now. My algorithm uses a relatively simple data structure that reflects what is in the UI. So I have to translate some of the freeciv data structures to mine.

At the moment I'm really stumped on how to determine what infrastructure is already developed on a tile. I guess it's in this struct variable extras?
struct tile {
...
bv_extras extras;

But I see no identifiers to figure out which bits are for irrigation, farmland, or mines. I saw the extras in terrain.ruleset (classic) but it's not clear how that gets into the tile data structure. I'd appreciate any information on this!

Also perhaps you can verify if these expressions are correct?

tile_has_road(ptile, road_by_number(1)) // true if railroad
tile_has_road(ptile, road_by_number(0)) // true if road

The 0 and 1 are my guesses of the road type indexes based on their order in the terrain.ruleset file. I'd prefer to have the correct identifier though.

Thanks for any suggestions.
cazfi
Elite
Posts: 3335
Joined: Tue Jan 29, 2013 6:54 pm

Re: autoworkers improvement - how to get some data

Post by cazfi »

First you have to decide what property makes a road type a "railroad" for your purposes.

Then e.g.

Code: Select all

extra_type_list_iterate(extra_type_list_by_cause(EC_ROAD), pextra) {
  if (pextra->wanted_property
      || extra_road_get(pextra)->wanted_property) {
      // pextra is an interesting road type extra
  }
} extra_type_list_iterate_end;
sandwave
Posts: 6
Joined: Wed May 14, 2025 2:48 am

Re: autoworkers improvement - how to get some data

Post by sandwave »

Thanks, this helped me solve nearly all the conversion problems.

I decided to go with the graphics_str property. Even though it's ruleset-specific, it's easy to see and debug the conversion between the UI, the terrain.ruleset, and my algorithm.
Post Reply