-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathFaction.java
More file actions
179 lines (165 loc) · 6.01 KB
/
Faction.java
File metadata and controls
179 lines (165 loc) · 6.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright 2025 The Terasology Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.destinationsol.game.faction;
import org.joml.Math;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.nui.Color;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A faction is an abstraction used to establish common diplomatic relations between aligned entities.
* Factions hold an overall disposition towards other factions, which determines their approach towards entities
* belonging to those factions. Factions holding a negative disposition towards others will be openly hostile.
*/
public class Faction {
/**
* The minimum possible reputation a faction can have with another.
*/
public static final int MIN_REPUTATION = -100;
/**
* The maximum possible reputation a faction can have with another.
*/
public static final int MAX_REPUTATION = 100;
/**
* The identifier used to uniquely identify this faction (e.g. "my-faction")
*/
private final ResourceUrn id;
/**
* The name of this faction.
*/
private final String name;
/**
* The faction's description.
*/
private final String description;
/**
* The faction's primary colour.
*/
private final Color colour;
/**
* Ship designs that can be produced by this faction.
*/
private final List<ResourceUrn> shipDesigns;
/**
* The default standing that this faction has towards unknown factions.
*/
private final float defaultDisposition;
/**
* The relations held between this faction and other factions.
*/
private final Map<Faction, Float> relations;
/**
* The impact that certain events will have on relations with another faction if they instigate a given event.
* (For example, hitting the ship with a projectile loses reputation, having a negative impact.)
* @see DefaultReputationEvent
*/
private final Map<String, Float> reputationImpacts;
/**
* Instantiates a new faction instance.
* @param id the faction's id (this should be the urn corresponding to the faction's JSON definition file)
* @param name the name of the faction
* @param description a description for the faction
* @param colour the faction's primary colour
* @param defaultDisposition the faction's default disposition towards unknown factions
* @param shipDesigns ship designs that can be built by this faction
* @param reputationImpacts the impact certain events should have on relationships between this faction and others.
*/
public Faction(ResourceUrn id, String name, String description, Color colour, int defaultDisposition,
List<ResourceUrn> shipDesigns, Map<String, Float> reputationImpacts) {
this.id = id;
this.name = name;
this.description = description;
this.colour = colour;
this.defaultDisposition = Math.clamp(MIN_REPUTATION, MAX_REPUTATION, defaultDisposition);
this.shipDesigns = shipDesigns;
this.relations = new HashMap<>();
this.reputationImpacts = reputationImpacts;
}
/**
* Returns the faction's id.
* @return the faction's id.
*/
public ResourceUrn getId() {
return id;
}
/**
* Returns the faction's name.
* @return the faction's name.
*/
public String getName() {
return name;
}
/**
* Returns the faction's description.
* @return the faction's description.
*/
public String getDescription() {
return description;
}
/**
* Returns the faction's primary colour.
* @return the faction's primary colour.
*/
public Color getColour() {
return colour;
}
/**
* Returns a list of ship designs that can be manufactured by the faction.
* @return a list of ship designs that this faction can make.
*/
public List<ResourceUrn> getShipDesigns() {
return shipDesigns;
}
/**
* Gets the impact of an event on this faction's relationships with others.
* @param event the event to query.
* @return the change in reputation, if known, otherwise null.
* @param <T> the type of event.
*/
public <T extends ReputationEvent> Float getReputationImpact(T event) {
return reputationImpacts.get(event.toString());
}
/**
* Specifies whether a faction has formal relations with another (meaning they have an explicit reputation built-up).
* @param faction the faction to check.
* @return true, if the faction is known to this faction, otherwise false.
*/
public boolean isAwareOf(Faction faction) {
return relations.containsKey(faction);
}
/**
* Returns the reputation held by another faction with this faction.
* @param faction the faction to check.
* @return the reputation value held with this faction.
*/
public float getRelation(Faction faction) {
if (faction == this) {
return MAX_REPUTATION;
}
return relations.getOrDefault(faction, defaultDisposition);
}
/**
* Sets the reputation held by this faction for another.
* @param faction the faction to assign reputation with.
* @param disposition the overall disposition of this faction towards the other.
*/
public void setRelation(Faction faction, float disposition) {
if (faction != this) {
relations.put(faction, Math.clamp(MIN_REPUTATION, MAX_REPUTATION, disposition));
}
}
}