Skip to content

Commit cd0567b

Browse files
committed
Renamed fraction to faction. No functionality changes.
1 parent 3db7630 commit cd0567b

30 files changed

+292
-292
lines changed

main/src/com/miloshpetrov/sol2/game/BeaconHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public Action processMouse(SolGame g, Vector2 pos, boolean clicked, boolean onMa
160160
Action action;
161161
Pilot targetPilot = findPilotInPos(g, pos, onMap, clicked);
162162
if (targetPilot != null) {
163-
boolean enemies = g.getFractionMan().areEnemies(targetPilot.getFraction(), g.getHero().getPilot().getFraction());
163+
boolean enemies = g.getFactionMan().areEnemies(targetPilot.getFaction(), g.getHero().getPilot().getFaction());
164164
if (enemies) {
165165
action = Action.ATTACK;
166166
if (clicked) {
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package com.miloshpetrov.sol2.game;
2-
3-
public enum Fraction {
4-
LAANI("laani"), EHAR("ehar");
5-
private final String myName;
6-
7-
Fraction(String name) {
8-
myName = name;
9-
}
10-
11-
public String getName() {
12-
return myName;
13-
}
14-
}
1+
package com.miloshpetrov.sol2.game;
2+
3+
public enum Faction {
4+
LAANI("laani"), EHAR("ehar");
5+
private final String myName;
6+
7+
Faction(String name) {
8+
myName = name;
9+
}
10+
11+
public String getName() {
12+
return myName;
13+
}
14+
}
Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
1-
package com.miloshpetrov.sol2.game;
2-
3-
import com.badlogic.gdx.math.Vector2;
4-
import com.badlogic.gdx.physics.box2d.Fixture;
5-
import com.badlogic.gdx.physics.box2d.RayCastCallback;
6-
import com.miloshpetrov.sol2.TextureManager;
7-
import com.miloshpetrov.sol2.game.input.Pilot;
8-
import com.miloshpetrov.sol2.game.projectile.Projectile;
9-
import com.miloshpetrov.sol2.game.ship.SolShip;
10-
11-
import java.util.List;
12-
13-
public class FractionMan {
14-
15-
private final MyRayBack myRayBack;
16-
17-
public FractionMan(TextureManager textureManager) {
18-
myRayBack = new MyRayBack();
19-
}
20-
21-
public SolShip getNearestEnemy(SolGame game, SolShip ship) {
22-
Pilot pilot = ship.getPilot();
23-
float detectionDist = pilot.getDetectionDist();
24-
if (detectionDist <= 0) return null;
25-
detectionDist += ship.getHull().config.getApproxRadius();
26-
Fraction f = pilot.getFraction();
27-
return getNearestEnemy(game, detectionDist, f, ship.getPos());
28-
}
29-
30-
public SolShip getNearestEnemy(SolGame game, Projectile proj) {
31-
return getNearestEnemy(game, game.getCam().getViewDist(), proj.getFraction(), proj.getPos());
32-
}
33-
34-
public SolShip getNearestEnemy(SolGame game, float detectionDist, Fraction f, Vector2 pos) {
35-
SolShip res = null;
36-
float minDst = detectionDist;
37-
List<SolObject> objs = game.getObjMan().getObjs();
38-
for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
39-
SolObject o = objs.get(i);
40-
if (!(o instanceof SolShip)) continue;
41-
SolShip ship2 = (SolShip) o;
42-
if (!areEnemies(f, ship2.getPilot().getFraction())) continue;
43-
float dst = ship2.getPos().dst(pos) - ship2.getHull().config.getApproxRadius();
44-
if (minDst < dst) continue;
45-
minDst = dst;
46-
res = ship2;
47-
}
48-
return res;
49-
}
50-
51-
private boolean hasObstacles(SolGame game, SolShip shipFrom, SolShip shipTo) {
52-
myRayBack.shipFrom = shipFrom;
53-
myRayBack.shipTo = shipTo;
54-
myRayBack.hasObstacle = false;
55-
game.getObjMan().getWorld().rayCast(myRayBack, shipFrom.getPos(), shipTo.getPos());
56-
return myRayBack.hasObstacle;
57-
}
58-
59-
public boolean areEnemies(SolShip s1, SolShip s2) {
60-
Fraction f1 = s1.getPilot().getFraction();
61-
Fraction f2 = s2.getPilot().getFraction();
62-
return areEnemies(f1, f2);
63-
}
64-
65-
public boolean areEnemies(Fraction f1, Fraction f2) {
66-
return f1 != null && f2 != null && f1 != f2;
67-
}
68-
69-
private static class MyRayBack implements RayCastCallback {
70-
public SolShip shipFrom;
71-
public SolShip shipTo;
72-
public boolean hasObstacle;
73-
74-
@Override
75-
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
76-
SolObject o = (SolObject) fixture.getBody().getUserData();
77-
if (o == shipFrom || o == shipTo) {
78-
return -1;
79-
}
80-
hasObstacle = true;
81-
return 0;
82-
}
83-
}
84-
}
1+
package com.miloshpetrov.sol2.game;
2+
3+
import com.badlogic.gdx.math.Vector2;
4+
import com.badlogic.gdx.physics.box2d.Fixture;
5+
import com.badlogic.gdx.physics.box2d.RayCastCallback;
6+
import com.miloshpetrov.sol2.TextureManager;
7+
import com.miloshpetrov.sol2.game.input.Pilot;
8+
import com.miloshpetrov.sol2.game.projectile.Projectile;
9+
import com.miloshpetrov.sol2.game.ship.SolShip;
10+
11+
import java.util.List;
12+
13+
public class FactionMan {
14+
15+
private final MyRayBack myRayBack;
16+
17+
public FactionMan(TextureManager textureManager) {
18+
myRayBack = new MyRayBack();
19+
}
20+
21+
public SolShip getNearestEnemy(SolGame game, SolShip ship) {
22+
Pilot pilot = ship.getPilot();
23+
float detectionDist = pilot.getDetectionDist();
24+
if (detectionDist <= 0) return null;
25+
detectionDist += ship.getHull().config.getApproxRadius();
26+
Faction f = pilot.getFaction();
27+
return getNearestEnemy(game, detectionDist, f, ship.getPos());
28+
}
29+
30+
public SolShip getNearestEnemy(SolGame game, Projectile proj) {
31+
return getNearestEnemy(game, game.getCam().getViewDist(), proj.getFaction(), proj.getPos());
32+
}
33+
34+
public SolShip getNearestEnemy(SolGame game, float detectionDist, Faction f, Vector2 pos) {
35+
SolShip res = null;
36+
float minDst = detectionDist;
37+
List<SolObject> objs = game.getObjMan().getObjs();
38+
for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
39+
SolObject o = objs.get(i);
40+
if (!(o instanceof SolShip)) continue;
41+
SolShip ship2 = (SolShip) o;
42+
if (!areEnemies(f, ship2.getPilot().getFaction())) continue;
43+
float dst = ship2.getPos().dst(pos) - ship2.getHull().config.getApproxRadius();
44+
if (minDst < dst) continue;
45+
minDst = dst;
46+
res = ship2;
47+
}
48+
return res;
49+
}
50+
51+
private boolean hasObstacles(SolGame game, SolShip shipFrom, SolShip shipTo) {
52+
myRayBack.shipFrom = shipFrom;
53+
myRayBack.shipTo = shipTo;
54+
myRayBack.hasObstacle = false;
55+
game.getObjMan().getWorld().rayCast(myRayBack, shipFrom.getPos(), shipTo.getPos());
56+
return myRayBack.hasObstacle;
57+
}
58+
59+
public boolean areEnemies(SolShip s1, SolShip s2) {
60+
Faction f1 = s1.getPilot().getFaction();
61+
Faction f2 = s2.getPilot().getFaction();
62+
return areEnemies(f1, f2);
63+
}
64+
65+
public boolean areEnemies(Faction f1, Faction f2) {
66+
return f1 != null && f2 != null && f1 != f2;
67+
}
68+
69+
private static class MyRayBack implements RayCastCallback {
70+
public SolShip shipFrom;
71+
public SolShip shipTo;
72+
public boolean hasObstacle;
73+
74+
@Override
75+
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
76+
SolObject o = (SolObject) fixture.getBody().getUserData();
77+
if (o == shipFrom || o == shipTo) {
78+
return -1;
79+
}
80+
hasObstacle = true;
81+
return 0;
82+
}
83+
}
84+
}

main/src/com/miloshpetrov/sol2/game/GalaxyFiller.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private Vector2 getPosForStation(SolSystem sys, boolean mainStation, ConsumedAng
4444
return stationPos;
4545
}
4646

47-
private FarShip build(SolGame game, ShipConfig cfg, Fraction frac, boolean mainStation, SolSystem sys,
47+
private FarShip build(SolGame game, ShipConfig cfg, Faction faction, boolean mainStation, SolSystem sys,
4848
ConsumedAngles angles)
4949
{
5050
HullConfig hullConf = cfg.hull;
@@ -62,15 +62,15 @@ private FarShip build(SolGame game, ShipConfig cfg, Fraction frac, boolean mainS
6262
boolean isBig = hullConf.getType() == HullConfig.Type.BIG;
6363
dp = new ExplorerDestProvider(game, pos, !isBig, hullConf, sys);
6464
if (isBig) {
65-
if (frac == Fraction.LAANI) tradeConfig = sys.getConfig().tradeConfig;
65+
if (faction == Faction.LAANI) tradeConfig = sys.getConfig().tradeConfig;
6666
} else {
6767
detectionDist *= 1.5;
6868
}
6969
}
70-
Pilot pilot = new AiPilot(dp, true, frac, true, "something", detectionDist);
70+
Pilot pilot = new AiPilot(dp, true, faction, true, "something", detectionDist);
7171
float angle = mainStation ? 0 : SolMath.rnd(180);
7272
boolean hasRepairer;
73-
hasRepairer = frac == Fraction.LAANI;
73+
hasRepairer = faction == Faction.LAANI;
7474
int money = cfg.money;
7575
FarShip s = game.getShipBuilder().buildNewFar(game, pos, null, angle, 0, pilot, cfg.items, hullConf, null, hasRepairer, money, tradeConfig, true);
7676
game.getObjMan().addFarObjNow(s);
@@ -86,7 +86,7 @@ private FarShip build(SolGame game, ShipConfig cfg, Fraction frac, boolean mainS
8686
break;
8787
}
8888
}
89-
createGuard(game, s, guardConf, frac, guardianAngle);
89+
createGuard(game, s, guardConf, faction, guardianAngle);
9090
}
9191
}
9292
return s;
@@ -99,7 +99,7 @@ public void fill(SolGame game) {
9999

100100
ShipConfig mainStationCfg = game.getPlayerSpawnConfig().mainStation;
101101
ConsumedAngles angles = new ConsumedAngles();
102-
FarShip mainStation = build(game, mainStationCfg, Fraction.LAANI, true, systems.get(0), angles);
102+
FarShip mainStation = build(game, mainStationCfg, Faction.LAANI, true, systems.get(0), angles);
103103
myMainStationPos = new Vector2(mainStation.getPos());
104104
myMainStationHc = mainStation.getHullConfig();
105105

@@ -108,13 +108,13 @@ public void fill(SolGame game) {
108108
for (ShipConfig shipConfig : sysConfig.constAllies) {
109109
int count = (int)(shipConfig.density);
110110
for (int i = 0; i < count; i++) {
111-
build(game, shipConfig, Fraction.LAANI, false, sys, angles);
111+
build(game, shipConfig, Faction.LAANI, false, sys, angles);
112112
}
113113
}
114114
for (ShipConfig shipConfig : sysConfig.constEnemies) {
115115
int count = (int)(shipConfig.density);
116116
for (int i = 0; i < count; i++) {
117-
build(game, shipConfig, Fraction.EHAR, false, sys, angles);
117+
build(game, shipConfig, Faction.EHAR, false, sys, angles);
118118
}
119119
}
120120
angles = new ConsumedAngles();
@@ -164,10 +164,10 @@ private void link(SolGame game, Planet a, Planet b) {
164164
game.getObjMan().addFarObjNow(sp);
165165
}
166166

167-
private void createGuard(SolGame game, FarShip target, ShipConfig guardConf, Fraction frac, float guardRelAngle) {
167+
private void createGuard(SolGame game, FarShip target, ShipConfig guardConf, Faction faction, float guardRelAngle) {
168168
Guardian dp = new Guardian(game, guardConf.hull, target.getPilot(), target.getPos(), target.getHullConfig(), guardRelAngle);
169-
Pilot pilot = new AiPilot(dp, true, frac, false, null, Const.AI_DET_DIST);
170-
boolean hasRepairer = frac == Fraction.LAANI;
169+
Pilot pilot = new AiPilot(dp, true, faction, false, null, Const.AI_DET_DIST);
170+
boolean hasRepairer = faction == Faction.LAANI;
171171
int money = guardConf.money;
172172
FarShip e = game.getShipBuilder().buildNewFar(game, dp.getDest(), null, guardRelAngle, 0, pilot, guardConf.items,
173173
guardConf.hull, null, hasRepairer, money, null, true);

main/src/com/miloshpetrov/sol2/game/MapDrawer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void draw(GameDrawer drawer, SolGame game) {
9494
float iconSz = getIconRadius(cam) * 2;
9595
float starNodeW = cam.getViewHeight(myZoom) * STAR_NODE_SZ;
9696
float viewDist = cam.getViewDist(myZoom);
97-
FractionMan fractionMan = game.getFractionMan();
97+
FactionMan factionMan = game.getFactionMan();
9898
SolShip hero = game.getHero();
9999
Planet np = game.getPlanetMan().getNearestPlanet();
100100
Vector2 camPos = cam.getPos();
@@ -108,7 +108,7 @@ public void draw(GameDrawer drawer, SolGame game) {
108108
drawStarNodes(drawer, game, viewDist, camPos, starNodeW);
109109

110110
// using ui textures
111-
drawIcons(drawer, game, iconSz, viewDist, fractionMan, hero, camPos, heroDmgCap);
111+
drawIcons(drawer, game, iconSz, viewDist, factionMan, hero, camPos, heroDmgCap);
112112
}
113113

114114
public float getIconRadius(SolCam cam) {
@@ -215,7 +215,7 @@ private void drawAreaDanger(GameDrawer drawer, float rad, Vector2 pos, float tra
215215
drawer.draw(mySkullBigTex, rad *2, rad *2, rad, rad, pos.x, pos.y, angle, myAreaWarnCol);
216216
}
217217

218-
private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float viewDist, FractionMan fractionMan,
218+
private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float viewDist, FactionMan factionMan,
219219
SolShip hero, Vector2 camPos, float heroDmgCap)
220220
{
221221

@@ -228,7 +228,7 @@ private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float view
228228
SolShip ship = (SolShip) o;
229229
String hint = ship.getPilot().getMapHint();
230230
if (hint == null && !DebugOptions.DETAILED_MAP) continue;
231-
drawObjIcon(iconSz, oPos, ship.getAngle(), fractionMan, hero, ship.getPilot().getFraction(), heroDmgCap, o, ship.getHull().config.getIcon(), drawer);
231+
drawObjIcon(iconSz, oPos, ship.getAngle(), factionMan, hero, ship.getPilot().getFaction(), heroDmgCap, o, ship.getHull().config.getIcon(), drawer);
232232
}
233233
if ((o instanceof StarPort)) {
234234
StarPort sp = (StarPort) o;
@@ -243,7 +243,7 @@ private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float view
243243
if (viewDist < camPos.dst(oPos)) continue;
244244
String hint = ship.getPilot().getMapHint();
245245
if (hint == null && !DebugOptions.DETAILED_MAP) continue;
246-
drawObjIcon(iconSz, oPos, ship.getAngle(), fractionMan, hero, ship.getPilot().getFraction(), heroDmgCap, ship, ship.getHullConfig().getIcon(), drawer);
246+
drawObjIcon(iconSz, oPos, ship.getAngle(), factionMan, hero, ship.getPilot().getFaction(), heroDmgCap, ship, ship.getHullConfig().getIcon(), drawer);
247247
}
248248
List<StarPort.MyFar> farPorts = game.getObjMan().getFarPorts();
249249
for (int i = 0, sz = farPorts.size(); i < sz; i++) {
@@ -327,10 +327,10 @@ private void drawNpGround(GameDrawer drawer, SolGame game, float viewDist, Plane
327327
}
328328

329329
public void drawObjIcon(float iconSz, Vector2 pos, float objAngle,
330-
FractionMan fractionMan, SolShip hero, Fraction objFrac, float heroDmgCap,
330+
FactionMan factionMan, SolShip hero, Faction objFac, float heroDmgCap,
331331
Object shipHack, TextureAtlas.AtlasRegion icon, Object drawerHack)
332332
{
333-
boolean enemy = hero != null && fractionMan.areEnemies(objFrac, hero.getPilot().getFraction());
333+
boolean enemy = hero != null && factionMan.areEnemies(objFac, hero.getPilot().getFaction());
334334
float angle = objAngle;
335335
if (enemy && mySkullTime > 0 && HardnessCalc.isDangerous(heroDmgCap, shipHack)) {
336336
icon = mySkullTex;

main/src/com/miloshpetrov/sol2/game/ObjectManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ObjectManager {
2626
private float myFarBeginDist;
2727
private float myRadiusRecalcAwait;
2828

29-
public ObjectManager(SolContactListener contactListener, FractionMan fractionMan) {
29+
public ObjectManager(SolContactListener contactListener, FactionMan factionMan) {
3030
myObjs = new ArrayList<SolObject>();
3131
myToRemove = new ArrayList<SolObject>();
3232
myToAdd = new ArrayList<SolObject>();
@@ -35,7 +35,7 @@ public ObjectManager(SolContactListener contactListener, FractionMan fractionMan
3535
myFarPorts = new ArrayList<StarPort.MyFar>();
3636
myWorld = new World(new Vector2(0, 0), true);
3737
myWorld.setContactListener(contactListener);
38-
myWorld.setContactFilter(new SolContactFilter(fractionMan));
38+
myWorld.setContactFilter(new SolContactFilter(factionMan));
3939
myDr = new Box2DDebugRenderer();
4040
myRadii = new HashMap<SolObject, Float>();
4141
}

main/src/com/miloshpetrov/sol2/game/SolContactFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import com.miloshpetrov.sol2.game.projectile.Projectile;
66

77
public class SolContactFilter implements ContactFilter {
8-
private final FractionMan myFractionMan;
8+
private final FactionMan myFactionMan;
99

10-
public SolContactFilter(FractionMan fractionMan) {
11-
myFractionMan = fractionMan;
10+
public SolContactFilter(FactionMan factionMan) {
11+
myFactionMan = factionMan;
1212
}
1313

1414
@Override
@@ -22,6 +22,6 @@ public boolean shouldCollide(Fixture fixtureA, Fixture fixtureB) {
2222
Projectile proj = (Projectile)(aIsProj ? oA : oB);
2323
SolObject o = aIsProj ? oB : oA;
2424
Fixture f = aIsProj ? fixtureB : fixtureA;
25-
return proj.shouldCollide(o, f, myFractionMan);
25+
return proj.shouldCollide(o, f, myFactionMan);
2626
}
2727
}

0 commit comments

Comments
 (0)