Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Population Component (Specific to MR) #77

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.metalrenegades.population.component;

import org.terasology.entitySystem.Component;

public class PopulationComponent implements Component {
agent-q1 marked this conversation as resolved.
Show resolved Hide resolved
public int goodCitizens;
public int badCitizens;
public int neutralCitizens;

public PopulationComponent(){
this.badCitizens=0;
this.goodCitizens=0;
this.neutralCitizens = 0;
agent-q1 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.metalrenegades.population.system;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.entitySystem.entity.EntityRef;
import org.terasology.entitySystem.entity.lifecycleEvents.OnActivatedComponent;
import org.terasology.entitySystem.event.ReceiveEvent;
import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterMode;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.logic.players.LocalPlayer;
import org.terasology.metalrenegades.ai.component.FactionAlignmentComponent;
import org.terasology.metalrenegades.ai.event.CitizenSpawnedEvent;
import org.terasology.metalrenegades.ai.system.FactionAlignmentSystem;
import org.terasology.metalrenegades.population.component.PopulationComponent;
import org.terasology.network.ClientComponent;
import org.terasology.registry.In;

@RegisterSystem(value = RegisterMode.AUTHORITY)
public class PopulationSystem extends BaseComponentSystem {

@In
LocalPlayer player;
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when a authority system gets the LocalPlayer injected? I've never asked myself that question, now I'm curious 🤔 anybody knows?

I'm a bit concerned this may cause trouble in multi-player.


Logger logger = LoggerFactory.getLogger(PopulationSystem.class);

@ReceiveEvent
public void onPlayerSpawn(OnActivatedComponent event, EntityRef entity, ClientComponent component) {

entity.addComponent(new PopulationComponent());
logger.error("Component PopulationComponent added to player");
Copy link
Contributor

Choose a reason for hiding this comment

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

this is obviously not an error 😅 (I guess this just to see that it actually works).



}

@ReceiveEvent
public void citizenSpawned(CitizenSpawnedEvent event, EntityRef citizen) {
FactionAlignmentComponent factionAlignmentComponent = citizen.getComponent(FactionAlignmentComponent.class);
agent-q1 marked this conversation as resolved.
Show resolved Hide resolved
PopulationComponent populationComponent = player.getClientEntity().getComponent(PopulationComponent.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know whether there is already a settlement entity in MetalRenegades, but my gut feeling says it would be nice to get the affected settlement from the CitizenSpawnedEvent. This settlement entity (or component) would then have a reference to the population:

        PopulationComponent populationComponent = event.getSettlement().getPopulation();

(please don't take the exact syntax for granted)

if (factionAlignmentComponent.alignment == FactionAlignmentSystem.Alignment.NEUTRAL) {
populationComponent.neutralCitizens++;

} else if (factionAlignmentComponent.alignment == FactionAlignmentSystem.Alignment.GOOD) {
populationComponent.goodCitizens++;

} else if (factionAlignmentComponent.alignment == FactionAlignmentSystem.Alignment.BAD) {
populationComponent.badCitizens++;
} else {
logger.error("Invalid Faction Alignment");
}
agent-q1 marked this conversation as resolved.
Show resolved Hide resolved

player.getClientEntity().saveComponent(populationComponent);
logger.error("Population is {} {} {] ",populationComponent.badCitizens, populationComponent.goodCitizens, populationComponent.neutralCitizens);
}


}