Skip to content

Prevent bridge destruction & Improved fleeing enemies#1840

Open
Johannes-callidus wants to merge 7 commits into
Keriew:masterfrom
Johannes-callidus:invasion-bridges
Open

Prevent bridge destruction & Improved fleeing enemies#1840
Johannes-callidus wants to merge 7 commits into
Keriew:masterfrom
Johannes-callidus:invasion-bridges

Conversation

@Johannes-callidus

Copy link
Copy Markdown
Collaborator

This PR prevents players from destroying bridges while an invasion is ongoing and makes several changes to retreating enemies.
Retreating enemies now have double the speed so a fought off invasion no longer takes forever.
And they now always retreat to the nearest invasion point and not to their source for the same reason as above.

@eugenikus8

Copy link
Copy Markdown
  1. I'm curious what would happen if an invasion consisted of two groups attacking from different entry points.
  2. Where would each group head?
  3. Would both groups run toward the same exit point, shared by all invading forces?
  4. If the shortest route to the nearest exit point went through a town, would the enemies ignore the buildings, or would they destroy everything in their path?

@Johannes-callidus

Copy link
Copy Markdown
Collaborator Author

The shortest route is calculated by each soldier every 300 ticks.
So how many groups there are shouldn't matter.
They'll destroy everything in their way when fleeing. They always did.
Luckily it's a pretty rare case that there's a city in between.

@eugenikus8

eugenikus8 commented Jul 21, 2026

Copy link
Copy Markdown

Update: The fleeing little guys in blue pants have become more dangerous than Caesar's troops. There are also significantly more destroyed buildings now. After testing this change, I'd prefer to keep the previous behavior.
Please add an option that allows us to restore the old retreat behavior.

P.S. I haven't checked yet, but it's possible that the bridges can be removed along with the animals as well.

@Johannes-callidus

Copy link
Copy Markdown
Collaborator Author

Now that you're mentioning that it seems kinda obvious, since I tested fighting off some big invasions. I thought I just got bad at military due to not playing a lot recently but they really destroyed that much because they were going double the speed straight through parts of my city.
Question: Should the option only change the routing behavior of the natives or also restore their speed to normal?

In terms of the bridges do you mean that you can remove wolves easily?

@eugenikus8

Copy link
Copy Markdown

I'm testing it. I just noticed that animals (I've only tested wolves so far) can't get onto the bridge.

@Johannes-callidus Johannes-callidus changed the title Prevent birdge destruction & Improved fleeing enemies Prevent bridge destruction & Improved fleeing enemies Jul 21, 2026
@Johannes-callidus

Johannes-callidus commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator Author

Grr roadblock bridges. (Since bridges are roadblocks they have TERRAIN_BUILDING and that probably prevents wolves from going there). But I should have thought about that when implementing the wolf rerouting feature.
Other animals shouldn't be effected.

@Johannes-callidus

Copy link
Copy Markdown
Collaborator Author

Now they should be able to go on bridges. At least on master.

@eugenikus8

Copy link
Copy Markdown

In terms of the bridges do you mean that you can remove wolves easily?

Yes. Now, if you pause the game at the right moment, you can remove a single bridge and wipe out the entire pack of wolves.
It might also make sense to prevent a bridge from being removed while wolves are standing on it.

@eugenikus8

Copy link
Copy Markdown

Question: Should the option only change the routing behavior of the natives or also restore their speed to normal?

This option should restore the enemies' retreat behavior to its fully vanilla state (they retreat back to their invasion points). As for the retreat speed, I'm not sure. It could be increased, but keeping the vanilla value is also perfectly fine. I'll leave that decision up to you.

@Johannes-callidus

Copy link
Copy Markdown
Collaborator Author

The option is actually untested so it would be very kind if someone could test it.

@eugenikus8

Copy link
Copy Markdown

I tested it with the option disabled. At first, everything seems to work fine, but at some point, after the enemies have taken heavy losses, they suddenly get a speed boost. However, they keep advancing instead of retreating to the invasion point.

I also noticed that some enemies seem to disappear without a trace.

P.S. The speed-boosted elephants charging in to destroy the city are quite a sight.

P.P.S. It looks like you can no longer destroy bridges using wolves.

test-fleeing-enemy.zip

@eugenikus8

Copy link
Copy Markdown

I think trying to find the nearest retreat point is a bad idea. It creates more problems than it solves. It would be better to simply speed up retreating enemies through an option instead.

Something like that.

        case FIGURE_ACTION_148_FLEEING:
        {
            f->destination_x = f->source_x;
            f->destination_y = f->source_y;
            int speed = 1;
            if (config_get(CONFIG_GP_CH_ENEMIES_RETREAT_FAST)) {
                speed += f->wait_ticks / 50; // +1 every 50 tick (1 day)
                if (speed > 3) {
                    speed = 3;
                }
            }
            figure_movement_move_ticks(f, f->speed_multiplier * speed);
            f->wait_ticks++;
            if (f->direction == DIR_FIGURE_AT_DESTINATION ||
                f->direction == DIR_FIGURE_REROUTE ||
                f->direction == DIR_FIGURE_LOST) {
                f->state = FIGURE_STATE_DEAD;
            }
            break;
        }

@Johannes-callidus

Copy link
Copy Markdown
Collaborator Author

Yeah I also realised that. There are so many more problems then you'd expect. Especially the huge lag due to the routing and if you only do it once you can end up with stuck troops.

@Johannes-callidus

Copy link
Copy Markdown
Collaborator Author

But at least I now understand routing and formations.

@eugenikus8

eugenikus8 commented Jul 21, 2026

Copy link
Copy Markdown

You can probably remove the unnecessary #includes as well. (src/figuretype/enemy.c)

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.

2 participants