Skip to content

Add barbarian activity levels#903

Open
ajhalme wants to merge 7 commits intoC7-Game:Developmentfrom
ajhalme:barbarians-ui
Open

Add barbarian activity levels#903
ajhalme wants to merge 7 commits intoC7-Game:Developmentfrom
ajhalme:barbarians-ui

Conversation

@ajhalme
Copy link
Contributor

@ajhalme ajhalme commented Mar 1, 2026

This patch adds barbarian activity levels, in a few closely related pieces:

  • New UI controls for setting barbarian activity level in New Game, based on Civ3
  • Wire barbarian activity level to game state, save games, loading
  • Extend barbarian unit spawn engine logic to allow activity level parameterisation
  • Extend existing barbarian AI logic with an overarching strategy based on activity level
  • Revise barbarian AI to more cleanly separate observation and decision logic, to potentially enable more nuanced tactics

If the thinking was to make barbarian behaviour more customisable, I feel extending this framework with a "Custom" activity level or strategy should be doable. I haven't included the standard activity levels as game options in the same as world sizes, though this could be doable. Making it all fully dynamic so that one could have complete control over barbarian activity level options in a mod/scenario is probably doable, but quite involved.

Longer term, it would be interesting to expose the game state / the observation and decision points as hooks somehow so that one could wire-in a completely separate external AI process.

I haven't playtested this anger, the parameterisation is just a first stab: Sedentary seems to work as intended, and with the proposed double digit spawn rate and reduced exploration, Raging can be really something even with simple unit-based barbarian tactics. I've seen Raging camps hold their own well over 200 turns against AI players until AI players crash their economy and the game!


From the Civ3 manual

Barbarian

You can also set the level of barbarian activity in the game.
No Barbarians: Players who really hate barbarians can choose to play in this ideal barbarian-free world.
Sedentary: Barbarians are restricted to their encampments. The surrounding terrain is free of their mischief.
Roaming: Barbarian settlements occasionally appear, but less frequently and in smaller numbers than at higher levels. This is the standard level of barbarian activity.
Restless: Barbarians appear in moderate up to significant numbers, at shorter intervals than at lower levels.
Raging: You asked for it! The world is full of barbarians,and they appear in large numbers.
Random: This option randomly selects a Barbarian setting.

--

Civ3 UI:
og_new_game_slice

OpenCiv3:
openciv3_newgame_barbs

@ajhalme
Copy link
Contributor Author

ajhalme commented Mar 1, 2026

Loosely connected to #396 for #139. Implementing the tribe idea, having units attack together, will be key to making the different barb activity levels feel right.

It seems #218 is not an issue any more.

Copy link
Contributor

@TomWerner TomWerner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have time to play test this (or really look in that much detail, sorry) but it looks very cool!

Copy link
Contributor

@stavrosfa stavrosfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another comment here, because I couldn't find an appropriate place for it.

Shouldn't we disable barb camp spawning if the option is None?

AddBarbarianCamps(wc, gameMap);

private static void AddBarbarianCamps(WorldCharacteristics wc, GameMap m) {

Another TODO might be to have more/less camps based on the difficulty and/or barbarian level.

All in all, good stuff!

/// <summary>
///
/// </summary>
private static float DetermineSpawnRate(BarbarianActivity activity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question, just because I am curious. Where are these values coming from? Do you see any value in extracting them to the json so they can be parameterized?

Also same question for the strategies, where we do for example
GameData.rng.Next(100) < 50

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current activity level parameters aren't based on anything except casual play testing.

I left some comments/TODOs to highlight that more work is needed if we want to make the barbs behave the way they do in Civ3.

For this, my target was simply to have some kind of a gradient of barbarian behaviour so that there's a reason to include the missing UI elements. Making things configurable would probably be the preferred option over trying tease out the perfect parameters. The AI in the original system might of course have worked in a completely different way, so there aren't really "true" parameters for any of this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, I was just curious whether you pulled this info out of some source I haven't seen.

I think it's ok for now as a base, behaviour can be tweaked and refined as we go.

I don't think that will ever capture the true original AI mechanics 100%, and that's good in my opinion

@ajhalme
Copy link
Contributor Author

ajhalme commented Mar 4, 2026

Shouldn't we disable barb camp spawning if the option is None?
[Might we have] more/less camps based on the difficulty and/or barbarian level.

Added this in, there was actually a TODO for this.

I was remembering that barbarian camps double as "goody huts", but that can't be right.

It might even be that scaling the number of camps is the primary element of the activity level. The description does suggest behaviour changes as well, but hard to say.

@stavrosfa
Copy link
Contributor

Sorry, I saw the TODO, but in my mind it didn't include the "no camps" part, I thought it was a TODO for "calculate how many" when it would have been implemented

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.

3 participants