Skip to content

Commit 9849476

Browse files
committed
fix: damage reputation loss is now proportional rather than constant
1 parent 4c06073 commit 9849476

27 files changed

Lines changed: 111 additions & 58 deletions

engine/src/main/java/org/destinationsol/game/FactionManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ public FactionManager(FactionsConfigs factionsConfigs) {
6969
* @param event the event that occurred.
7070
* @param <T> the type of event.
7171
*/
72-
public <T extends Enum<T> & ReputationEvent> void reportEvent(Faction instigator, Faction target, T event) {
72+
public <T extends ReputationEvent> void reportEvent(Faction instigator, Faction target, T event) {
7373
// TODO: Add support for custom event handlers.
7474
// Some examples:
7575
// - A pacifist faction is offended by any attacks made by a faction, regardless of the target.
7676
// - A merchant faction may randomly give a free bonus when buying items.
7777
// - A protective faction may dispatch a fleet to intercept the attacker if one of their ships is attacked.
78-
Integer targetReputationImpact = target.getReputationImpact(event);
78+
Float targetReputationImpact = target.getReputationImpact(event);
7979
if (targetReputationImpact != null) {
8080
target.setRelation(instigator, target.getRelation(instigator) + targetReputationImpact);
8181
} else {

engine/src/main/java/org/destinationsol/game/Rubble.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void onRemove(SolGame game) {
101101
}
102102

103103
@Override
104-
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType) {
104+
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType, SolObject instigator) {
105105
}
106106

107107
@Override

engine/src/main/java/org/destinationsol/game/SolObject.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ public interface SolObject {
8080
* no health pool or should be otherwise indestructible, or invincible against some types of damage, this method can
8181
* be freely left blank.
8282
*
83-
* @param dmg Damage the object receives.
84-
* @param game Game this object belongs to.
85-
* @param position Position the object was hit at, if hit by point-based damage. Null if not applicable, such as fire.
86-
* @param dmgType Type of the damage object receives.
83+
* @param dmg Damage the object receives.
84+
* @param game Game this object belongs to.
85+
* @param position Position the object was hit at, if hit by point-based damage. Null if not applicable, such as fire.
86+
* @param dmgType Type of the damage object receives.
87+
* @param instigator Object that damaged this object.
8788
*/
88-
void receiveDmg(float dmg, SolGame game, @Nullable Vector2 position, DmgType dmgType);
89+
void receiveDmg(float dmg, SolGame game, @Nullable Vector2 position, DmgType dmgType, @Nullable SolObject instigator);
8990

9091
/**
9192
* Denotes whether this object is affected by gravity.

engine/src/main/java/org/destinationsol/game/SolObjectEntityWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void onRemove(SolGame game) {
6262
}
6363

6464
@Override
65-
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType) {
65+
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType, SolObject instigator) {
6666

6767
}
6868

engine/src/main/java/org/destinationsol/game/StarPort.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ public void onRemove(SolGame game) {
156156
}
157157

158158
@Override
159-
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType) {
159+
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType, SolObject instigator) {
160160
game.getContext().get(SpecialSounds.class).playHit(game, this, position, dmgType);
161+
// TODO: Reduce reputation with the origin planet's owning faction when planet ownership is implemented.
161162
}
162163

163164
@Override
@@ -436,7 +437,7 @@ public void onRemove(SolGame game) {
436437
}
437438

438439
@Override
439-
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType) {
440+
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType, SolObject instigator) {
440441
game.getContext().get(SpecialSounds.class).playHit(game, this, position, dmgType);
441442
}
442443

engine/src/main/java/org/destinationsol/game/asteroid/Asteroid.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void handleContact(SolObject other, float absImpulse, SolGame game, Vecto
112112
} else {
113113
dmg = absImpulse / mass / DUR;
114114
}
115-
receiveDmg(dmg, game, collPos, DmgType.CRASH);
115+
receiveDmg(dmg, game, collPos, DmgType.CRASH, null);
116116
}
117117

118118
@Override
@@ -149,7 +149,7 @@ private boolean updateInAtm(SolGame game) {
149149
}
150150

151151
float dmg = body.getLinearVelocity().len() * SPD_TO_ATM_DMG * game.getTimeStep();
152-
receiveDmg(dmg, game, null, DmgType.FIRE);
152+
receiveDmg(dmg, game, null, DmgType.FIRE, null);
153153
return true;
154154
}
155155

@@ -215,7 +215,7 @@ private void throwLoot(SolGame game, SolItem item) {
215215
}
216216

217217
@Override
218-
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType) {
218+
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType, SolObject instigator) {
219219
life -= dmg;
220220
game.getContext().get(SpecialSounds.class).playHit(game, this, position, dmgType);
221221
}

engine/src/main/java/org/destinationsol/game/console/commands/DieCommandHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public String die(@Game SolGame game) throws CommandExecutionException {
3838
if (!hero.isAlive()) {
3939
throw new CommandExecutionException("Hero is already dead!");
4040
}
41-
hero.getShip().receivePiercingDmg(hero.getHull().getHullConfig().getMaxLife() + 1f, game, hero.getPosition(), DmgType.CRASH);
41+
hero.getShip().receivePiercingDmg(hero.getHull().getHullConfig().getMaxLife() + 1f, game, hero.getPosition(), DmgType.CRASH, null);
4242
return "Hero killed!";
4343
}
4444
}

engine/src/main/java/org/destinationsol/game/drawables/DrawableObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void onRemove(SolGame game) {
116116
}
117117

118118
@Override
119-
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType) {
119+
public void receiveDmg(float dmg, SolGame game, Vector2 position, DmgType dmgType, SolObject instigator) {
120120
}
121121

122122
@Override
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2026 The Terasology Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.destinationsol.game.faction;
18+
19+
/**
20+
* A reputation-affecting event raised when a ship (or projectile fired by a ship) causes damage to another.
21+
*/
22+
public class DamageInflictedReputationEvent implements ReputationEvent {
23+
// This constant is calculated based on backwards compatibility with the old "1 hit = -1 reputation" logic,
24+
// assuming a normal bullet clip that deals 1.6 units of damage (same as the Heavy Machine Gun at the time).
25+
public static final float DAMAGE_REPUTATION_MODIFIER = 1.0f / 1.6f;
26+
private final float damageTaken;
27+
28+
public DamageInflictedReputationEvent(float damageTaken) {
29+
this.damageTaken = damageTaken;
30+
}
31+
32+
/**
33+
* Returns the quantity of damage caused by the instigator.
34+
* @return the quantity of damage caused by the instigator.
35+
*/
36+
public float getDamageTaken() {
37+
return damageTaken;
38+
}
39+
40+
/**
41+
* {@inheritDoc}
42+
*/
43+
@Override
44+
public float getDefaultReputationImpact() {
45+
return -(damageTaken * DAMAGE_REPUTATION_MODIFIER);
46+
}
47+
}

engine/src/main/java/org/destinationsol/game/faction/DefaultReputationEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public enum DefaultReputationEvent implements ReputationEvent {
4848
* @return the default impact on reputation this event will have in absence of a faction-specific value.
4949
*/
5050
@Override
51-
public int getDefaultReputationImpact() {
51+
public float getDefaultReputationImpact() {
5252
return defaultReputationImpact;
5353
}
5454
}

0 commit comments

Comments
 (0)