Skip to content

R28 animations#36

Open
instafluff0 wants to merge 87 commits into
maxpetul:masterfrom
instafluff0:r28-animations
Open

R28 animations#36
instafluff0 wants to merge 87 commits into
maxpetul:masterfrom
instafluff0:r28-animations

Conversation

@instafluff0
Copy link
Copy Markdown
Contributor

@instafluff0 instafluff0 commented May 8, 2026

PR three of three for R28. This PR is less dramatic in terms of changes than it seems, as most of the 7.8k line additions are INI, config, and Python files for processing animations outside of the game. About 2.5k lines are in injected_code.c (and much of that is config parsing).

The general approach is to piggyback on Civ3’s existing tile-effect machinery instead of creating a new animation workflow from scratch. When a tile matches a configured ambient animation rule, we use Tile_spawn_animated_effect to spawn a normal built-in tile effect (AE_Disorder) as a carrier. So we use a vanilla animated effect path that already knows how to allocate, position, update, and draw an effect. While AE_Disorder is being loaded, I set a temporary override so Units_Image_Data_load_animated_effect ignores the AE_Disorder’s normal art and instead loads the configured custom Art\Animations...*.INI. After vanilla finishes constructing the effect, we rewrite the effect id back to the custom id and apply per-animation direction and pixel offsets. So just as with smolder & disorder, the native animation system still owns lifetime, frame advancement, AMB/FLC handling, and rendering; we just swap in an INI and decide which tiles should spawn or clear those effects.

Here are the main features:

  1. Allows custom FLC tile animations to be configured for terrain, resources, PCX sprite indices, and coastal waves, using:
enable_custom_animations = true

  1. Adds a new tile animation config file with #Animation entries, for example:
#Animation
name = Fish
ini_path = Resources\Fish\Fish.INI
type = resource
resource_type = Fish

  1. Allows animations to be filtered by day/night hour and season:
show_in_day_night_hours = 7-17
show_in_seasons = winter

  1. Supports animation placement controls, including direction, x/y offsets, and playback speed:
direction = southeast
x_offset = -15
y_offset = -20
frame_time_seconds = 0.13

  1. Adds animation support for natural wonders through their config entries:
animation = ini=NaturalWonders\AngelFalls.INI; hours=7-17; seasons=spring,summer,fall,winter; offsets=0,-10

Note that natural wonders can have multiple animation entries.


  1. Adds tie-breaking logic (pick_tile_animation_winner_for_tile and get_tile_animation_type_priority) for tiles with multiple matching candidate animations, using this priority order:
Resource > Natural Wonder > PCX > Terrain > Coastal Wave

If still tied, animations with day/night or season filters take precedence, then the later config entry wins.

instafluff0 added 30 commits May 7, 2026 09:11
…invalidation bug when loading save or starting new game
instafluff0 added 27 commits May 7, 2026 09:57
…ort for multiple terrains in single #Animation entry
# Conflicts:
#	C3X.h
#	default.districts_natural_wonders_config.txt
#	injected_code.c
@instafluff0
Copy link
Copy Markdown
Contributor Author

instafluff0 commented Jun 3, 2026

Update: after more testing I've found I'm getting an inconsistent infinite loop at the start of some games with the current branch, typically after a turn or two but sometimes not at all.

I checked the RET values in Ghidra for the 5 functions added to civ_prog_objects.csv:

inlead,    0x4DE5C0,    0x0,        0x0,        "on_timer_0x9F6500",			        "void (__stdcall *) (void)"
define,    0x4062A0,    0x0,        0x0,        "Units_Image_Data_load_animation",		"void (__fastcall *) (Units_Image_Data * this, int edx, char * asset_string, FLC_Animation * anim, int civ_id, int param_4, int param_5, bool param_6)"
inlead,    0x4069E0,    0x0,        0x0,        "Units_Image_Data_load_animated_effect",	"void (__fastcall *) (Units_Image_Data * this, int edx, FLC_Animation * anim, int effect_id)"
inlead,    0x5DA5E0,    0x0,        0x0,        "Tile_spawn_animated_effect",			"void (__fastcall *) (Tile * this, int edx, enum AnimatedEffect effect, int tile_x, int tile_y, bool randomize_start_frame, enum direction dummy_dir)"
define,    0x5DA7A0,    0x0,        0x0,        "Tile_clear_animated_effect",			"void (__fastcall *) (Tile * this)"

...And the signatures/args all look correct to me. As best I can tell from the debugger I think I am seeing uti_next and get_unit_ptr, but still digging.

After adding some more logging, I see:

[C3X] get_unit_ptr: Looking up unit with ID 1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
[C3X] get_unit_ptr: Looking up unit with ID -1
...

On and on, still trying to figure out what is calling it. I'd say this happens 10-20% of the time on the 2nd turn of the game.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant