Skip to content

Commit

Permalink
Support turning citizens into specialists and changing their type
Browse files Browse the repository at this point in the history
This doesn't yet implement the benefits of specialists, but it does allow us to force certain tiles to not be worked. This is important when passing tiles between cities, for example.

#541
  • Loading branch information
TomWerner committed Feb 12, 2025
1 parent 41098ba commit c9baef9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public override void _Ready() {
// are visible and map UI locations back to map locations.
cityScreen.tileAssignmentLayer = mapView.tileAssignmentLayer;
cityScreen.mapView = mapView;
cityScreen.citizenTypes = gameDataAccess.gameData.citizenTypes;
}

//TODO: What was this supposed to do? It throws errors and occasinally causes crashes now, because _OnViewportSizeChanged doesn't exist
Expand Down
35 changes: 28 additions & 7 deletions C7/UIElements/CityScreen/CityScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public partial class CityScreen : CenterContainer {
private ILogger log = LogManager.ForContext<CityScreen>();
public TileAssignmentLayer tileAssignmentLayer;
public MapView mapView;
public List<CitizenType> citizenTypes;
private TextureRect background;
private List<TextureButton> popHeads = new();

Expand Down Expand Up @@ -50,7 +51,7 @@ public override void _UnhandledInput(InputEvent @event) {
using (UIGameDataAccess gameDataAccess = new()) {
Tile tile = mapView.tileOnScreenAt(gameDataAccess.gameData.map, eventMouseButton.Position);
if (tile != null) {
HandleReassignment(tile, gameDataAccess.gameData.citizenTypes);
HandleReassignment(tile);
RenderPopHeads(tileAssignmentLayer.city);
}
}
Expand All @@ -59,7 +60,14 @@ public override void _UnhandledInput(InputEvent @event) {
}
}

private void HandleReassignment(Tile tile, List<CitizenType> citizenTypes) {
// Returns a list of specialists that this player can use.
private List<CitizenType> GetKnownSpecialists(Player player) {
return citizenTypes.FindAll(x => {
return !x.IsDefaultCitizen && (x.PrerequisiteTech == null || player.knownTechs.Contains(x.PrerequisiteTech));
});
}

private void HandleReassignment(Tile tile) {
City city = tileAssignmentLayer.city;

// We can't assign citizens to other cities.
Expand All @@ -73,9 +81,15 @@ private void HandleReassignment(Tile tile, List<CitizenType> citizenTypes) {
}

// If we're already working a tile and click on it, turn the citizen
// into an entertainer.
// into a specialist.
if (tile.personWorkingTile != null && tile.personWorkingTile.city == city) {
// TODO: implement entertainers.
foreach (CitizenType citizenType in GetKnownSpecialists(city.owner)) {
CityResident resident = tile.personWorkingTile;
tile.personWorkingTile = null;
resident.tileWorked = Tile.NONE;
resident.citizenType = citizenType;
return;
}
return;
}

Expand Down Expand Up @@ -202,9 +216,6 @@ private void RenderPopHeads(City city) {

// Add each of the specialists.
//
// TODO: When clicking a specialist, have it iterate through the types
// of specialists known to the player.
//
// TODO: Render the specialist effect (like a smiley for entertainers)
// in the corner of the head.
foreach (CityResident cr in specialists) {
Expand All @@ -215,6 +226,16 @@ private void RenderPopHeads(City city) {
tb.TextureNormal = Util.LoadTextureFromPCX("Art/SmallHeads/popHeads.pcx",
textX + 1, textY + 1, 48, 48);
tb.SetPosition(new Vector2(xPos, 440));

List<CitizenType> specialistTypes = GetKnownSpecialists(city.owner);
int index = specialistTypes.FindIndex(x => x.Id == cr.citizenType.Id);
tb.Pressed += () => {
cr.citizenType = specialistTypes[(index + 1) % specialistTypes.Count];
++index;
RenderPopHeads(city);
};


background.AddChild(tb);
popHeads.Add(tb);
xPos += 48;
Expand Down

0 comments on commit c9baef9

Please sign in to comment.