-
Notifications
You must be signed in to change notification settings - Fork 16
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
agent-q1
wants to merge
12
commits into
Terasology:develop
Choose a base branch
from
agent-q1:PopulationCounter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a407db1
First run
agent-q1 9b5c35a
Update src/main/java/org/terasology/metalrenegades/population/compone…
agent-q1 4259737
Update src/main/java/org/terasology/metalrenegades/population/compone…
agent-q1 e72ad6f
Update src/main/java/org/terasology/metalrenegades/population/system/…
agent-q1 34b281c
Update src/main/java/org/terasology/metalrenegades/population/system/…
agent-q1 2fa964d
Merge branch 'develop' of https://github.com/Terasology/MetalRenegade…
agent-q1 ff93203
fix: Use of unqualified names for enum
agent-q1 4fb384e
refactor: Clean up of unused imports and logs
agent-q1 76536eb
fix: Population comoponents now held by settlements
agent-q1 d954a7e
refactor: Changed name of PopulationComponent
agent-q1 c8f2bb6
refactor: Renamed PopulationComponent
agent-q1 fbe3777
feat: Addition of settlement property to event
agent-q1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...java/org/terasology/metalrenegades/population/component/FactionDistributionComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2020 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.terasology.metalrenegades.population.component; | ||
|
||
import org.terasology.entitySystem.Component; | ||
|
||
/** | ||
* Track total population information of good, bad, and neutral citizens. | ||
* | ||
* The entity this component belongs to defines the scope of the tracked population. | ||
* For instance, it may be attached to a world entity for the overall population or a settlement entity for the population of that settlement. | ||
* | ||
* The population is usually tracked by the {@link PopulationSystem}. | ||
*/ | ||
public class FactionDistributionComponent implements Component { | ||
public int goodCitizens; | ||
public int badCitizens; | ||
public int neutralCitizens; | ||
|
||
public FactionDistributionComponent(){ | ||
this.badCitizens = 0; | ||
this.goodCitizens = 0; | ||
this.neutralCitizens = 0; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/terasology/metalrenegades/population/system/PopulationSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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.dynamicCities.buildings.components.SettlementRefComponent; | ||
import org.terasology.dynamicCities.settlements.events.SettlementRegisterEvent; | ||
import org.terasology.entitySystem.entity.EntityRef; | ||
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.metalrenegades.ai.component.FactionAlignmentComponent; | ||
import org.terasology.metalrenegades.ai.component.HomeComponent; | ||
import org.terasology.metalrenegades.ai.event.CitizenSpawnedEvent; | ||
import org.terasology.metalrenegades.population.component.FactionDistributionComponent; | ||
|
||
@RegisterSystem(value = RegisterMode.AUTHORITY) | ||
public class PopulationSystem extends BaseComponentSystem { | ||
|
||
|
||
Logger logger = LoggerFactory.getLogger(PopulationSystem.class); | ||
|
||
@ReceiveEvent | ||
public void onSettlementRegisterEvent(SettlementRegisterEvent buildingEntitySpawnedEvent, EntityRef entityRef) { | ||
entityRef.addComponent(new FactionDistributionComponent()); | ||
} | ||
|
||
@ReceiveEvent | ||
public void citizenSpawned(CitizenSpawnedEvent event, EntityRef citizen, | ||
FactionAlignmentComponent factionAlignmentComponent) { | ||
|
||
EntityRef settlementEntity = event.getSettlement(); | ||
|
||
FactionDistributionComponent populationComponent = | ||
settlementEntity.getComponent(FactionDistributionComponent.class); | ||
|
||
|
||
switch (factionAlignmentComponent.alignment) { | ||
case NEUTRAL: | ||
populationComponent.neutralCitizens++; | ||
break; | ||
case GOOD: | ||
populationComponent.goodCitizens++; | ||
break; | ||
case BAD: | ||
populationComponent.badCitizens++; | ||
break; | ||
default: | ||
logger.error("Invalid Faction Alignment"); | ||
} | ||
|
||
settlementEntity.saveComponent(populationComponent); | ||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import