Skip to content

Commit

Permalink
Renamed fraction to faction. No functionality changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonC4 committed Aug 5, 2015
1 parent 3db7630 commit cd0567b
Show file tree
Hide file tree
Showing 30 changed files with 292 additions and 292 deletions.
2 changes: 1 addition & 1 deletion main/src/com/miloshpetrov/sol2/game/BeaconHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public Action processMouse(SolGame g, Vector2 pos, boolean clicked, boolean onMa
Action action;
Pilot targetPilot = findPilotInPos(g, pos, onMap, clicked);
if (targetPilot != null) {
boolean enemies = g.getFractionMan().areEnemies(targetPilot.getFraction(), g.getHero().getPilot().getFraction());
boolean enemies = g.getFactionMan().areEnemies(targetPilot.getFaction(), g.getHero().getPilot().getFaction());
if (enemies) {
action = Action.ATTACK;
if (clicked) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.miloshpetrov.sol2.game;

public enum Fraction {
LAANI("laani"), EHAR("ehar");
private final String myName;

Fraction(String name) {
myName = name;
}

public String getName() {
return myName;
}
}
package com.miloshpetrov.sol2.game;

public enum Faction {
LAANI("laani"), EHAR("ehar");
private final String myName;

Faction(String name) {
myName = name;
}

public String getName() {
return myName;
}
}
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
package com.miloshpetrov.sol2.game;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.RayCastCallback;
import com.miloshpetrov.sol2.TextureManager;
import com.miloshpetrov.sol2.game.input.Pilot;
import com.miloshpetrov.sol2.game.projectile.Projectile;
import com.miloshpetrov.sol2.game.ship.SolShip;

import java.util.List;

public class FractionMan {

private final MyRayBack myRayBack;

public FractionMan(TextureManager textureManager) {
myRayBack = new MyRayBack();
}

public SolShip getNearestEnemy(SolGame game, SolShip ship) {
Pilot pilot = ship.getPilot();
float detectionDist = pilot.getDetectionDist();
if (detectionDist <= 0) return null;
detectionDist += ship.getHull().config.getApproxRadius();
Fraction f = pilot.getFraction();
return getNearestEnemy(game, detectionDist, f, ship.getPos());
}

public SolShip getNearestEnemy(SolGame game, Projectile proj) {
return getNearestEnemy(game, game.getCam().getViewDist(), proj.getFraction(), proj.getPos());
}

public SolShip getNearestEnemy(SolGame game, float detectionDist, Fraction f, Vector2 pos) {
SolShip res = null;
float minDst = detectionDist;
List<SolObject> objs = game.getObjMan().getObjs();
for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
SolObject o = objs.get(i);
if (!(o instanceof SolShip)) continue;
SolShip ship2 = (SolShip) o;
if (!areEnemies(f, ship2.getPilot().getFraction())) continue;
float dst = ship2.getPos().dst(pos) - ship2.getHull().config.getApproxRadius();
if (minDst < dst) continue;
minDst = dst;
res = ship2;
}
return res;
}

private boolean hasObstacles(SolGame game, SolShip shipFrom, SolShip shipTo) {
myRayBack.shipFrom = shipFrom;
myRayBack.shipTo = shipTo;
myRayBack.hasObstacle = false;
game.getObjMan().getWorld().rayCast(myRayBack, shipFrom.getPos(), shipTo.getPos());
return myRayBack.hasObstacle;
}

public boolean areEnemies(SolShip s1, SolShip s2) {
Fraction f1 = s1.getPilot().getFraction();
Fraction f2 = s2.getPilot().getFraction();
return areEnemies(f1, f2);
}

public boolean areEnemies(Fraction f1, Fraction f2) {
return f1 != null && f2 != null && f1 != f2;
}

private static class MyRayBack implements RayCastCallback {
public SolShip shipFrom;
public SolShip shipTo;
public boolean hasObstacle;

@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
SolObject o = (SolObject) fixture.getBody().getUserData();
if (o == shipFrom || o == shipTo) {
return -1;
}
hasObstacle = true;
return 0;
}
}
}
package com.miloshpetrov.sol2.game;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.RayCastCallback;
import com.miloshpetrov.sol2.TextureManager;
import com.miloshpetrov.sol2.game.input.Pilot;
import com.miloshpetrov.sol2.game.projectile.Projectile;
import com.miloshpetrov.sol2.game.ship.SolShip;

import java.util.List;

public class FactionMan {

private final MyRayBack myRayBack;

public FactionMan(TextureManager textureManager) {
myRayBack = new MyRayBack();
}

public SolShip getNearestEnemy(SolGame game, SolShip ship) {
Pilot pilot = ship.getPilot();
float detectionDist = pilot.getDetectionDist();
if (detectionDist <= 0) return null;
detectionDist += ship.getHull().config.getApproxRadius();
Faction f = pilot.getFaction();
return getNearestEnemy(game, detectionDist, f, ship.getPos());
}

public SolShip getNearestEnemy(SolGame game, Projectile proj) {
return getNearestEnemy(game, game.getCam().getViewDist(), proj.getFaction(), proj.getPos());
}

public SolShip getNearestEnemy(SolGame game, float detectionDist, Faction f, Vector2 pos) {
SolShip res = null;
float minDst = detectionDist;
List<SolObject> objs = game.getObjMan().getObjs();
for (int i = 0, objsSize = objs.size(); i < objsSize; i++) {
SolObject o = objs.get(i);
if (!(o instanceof SolShip)) continue;
SolShip ship2 = (SolShip) o;
if (!areEnemies(f, ship2.getPilot().getFaction())) continue;
float dst = ship2.getPos().dst(pos) - ship2.getHull().config.getApproxRadius();
if (minDst < dst) continue;
minDst = dst;
res = ship2;
}
return res;
}

private boolean hasObstacles(SolGame game, SolShip shipFrom, SolShip shipTo) {
myRayBack.shipFrom = shipFrom;
myRayBack.shipTo = shipTo;
myRayBack.hasObstacle = false;
game.getObjMan().getWorld().rayCast(myRayBack, shipFrom.getPos(), shipTo.getPos());
return myRayBack.hasObstacle;
}

public boolean areEnemies(SolShip s1, SolShip s2) {
Faction f1 = s1.getPilot().getFaction();
Faction f2 = s2.getPilot().getFaction();
return areEnemies(f1, f2);
}

public boolean areEnemies(Faction f1, Faction f2) {
return f1 != null && f2 != null && f1 != f2;
}

private static class MyRayBack implements RayCastCallback {
public SolShip shipFrom;
public SolShip shipTo;
public boolean hasObstacle;

@Override
public float reportRayFixture(Fixture fixture, Vector2 point, Vector2 normal, float fraction) {
SolObject o = (SolObject) fixture.getBody().getUserData();
if (o == shipFrom || o == shipTo) {
return -1;
}
hasObstacle = true;
return 0;
}
}
}
22 changes: 11 additions & 11 deletions main/src/com/miloshpetrov/sol2/game/GalaxyFiller.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private Vector2 getPosForStation(SolSystem sys, boolean mainStation, ConsumedAng
return stationPos;
}

private FarShip build(SolGame game, ShipConfig cfg, Fraction frac, boolean mainStation, SolSystem sys,
private FarShip build(SolGame game, ShipConfig cfg, Faction faction, boolean mainStation, SolSystem sys,
ConsumedAngles angles)
{
HullConfig hullConf = cfg.hull;
Expand All @@ -62,15 +62,15 @@ private FarShip build(SolGame game, ShipConfig cfg, Fraction frac, boolean mainS
boolean isBig = hullConf.getType() == HullConfig.Type.BIG;
dp = new ExplorerDestProvider(game, pos, !isBig, hullConf, sys);
if (isBig) {
if (frac == Fraction.LAANI) tradeConfig = sys.getConfig().tradeConfig;
if (faction == Faction.LAANI) tradeConfig = sys.getConfig().tradeConfig;
} else {
detectionDist *= 1.5;
}
}
Pilot pilot = new AiPilot(dp, true, frac, true, "something", detectionDist);
Pilot pilot = new AiPilot(dp, true, faction, true, "something", detectionDist);
float angle = mainStation ? 0 : SolMath.rnd(180);
boolean hasRepairer;
hasRepairer = frac == Fraction.LAANI;
hasRepairer = faction == Faction.LAANI;
int money = cfg.money;
FarShip s = game.getShipBuilder().buildNewFar(game, pos, null, angle, 0, pilot, cfg.items, hullConf, null, hasRepairer, money, tradeConfig, true);
game.getObjMan().addFarObjNow(s);
Expand All @@ -86,7 +86,7 @@ private FarShip build(SolGame game, ShipConfig cfg, Fraction frac, boolean mainS
break;
}
}
createGuard(game, s, guardConf, frac, guardianAngle);
createGuard(game, s, guardConf, faction, guardianAngle);
}
}
return s;
Expand All @@ -99,7 +99,7 @@ public void fill(SolGame game) {

ShipConfig mainStationCfg = game.getPlayerSpawnConfig().mainStation;
ConsumedAngles angles = new ConsumedAngles();
FarShip mainStation = build(game, mainStationCfg, Fraction.LAANI, true, systems.get(0), angles);
FarShip mainStation = build(game, mainStationCfg, Faction.LAANI, true, systems.get(0), angles);
myMainStationPos = new Vector2(mainStation.getPos());
myMainStationHc = mainStation.getHullConfig();

Expand All @@ -108,13 +108,13 @@ public void fill(SolGame game) {
for (ShipConfig shipConfig : sysConfig.constAllies) {
int count = (int)(shipConfig.density);
for (int i = 0; i < count; i++) {
build(game, shipConfig, Fraction.LAANI, false, sys, angles);
build(game, shipConfig, Faction.LAANI, false, sys, angles);
}
}
for (ShipConfig shipConfig : sysConfig.constEnemies) {
int count = (int)(shipConfig.density);
for (int i = 0; i < count; i++) {
build(game, shipConfig, Fraction.EHAR, false, sys, angles);
build(game, shipConfig, Faction.EHAR, false, sys, angles);
}
}
angles = new ConsumedAngles();
Expand Down Expand Up @@ -164,10 +164,10 @@ private void link(SolGame game, Planet a, Planet b) {
game.getObjMan().addFarObjNow(sp);
}

private void createGuard(SolGame game, FarShip target, ShipConfig guardConf, Fraction frac, float guardRelAngle) {
private void createGuard(SolGame game, FarShip target, ShipConfig guardConf, Faction faction, float guardRelAngle) {
Guardian dp = new Guardian(game, guardConf.hull, target.getPilot(), target.getPos(), target.getHullConfig(), guardRelAngle);
Pilot pilot = new AiPilot(dp, true, frac, false, null, Const.AI_DET_DIST);
boolean hasRepairer = frac == Fraction.LAANI;
Pilot pilot = new AiPilot(dp, true, faction, false, null, Const.AI_DET_DIST);
boolean hasRepairer = faction == Faction.LAANI;
int money = guardConf.money;
FarShip e = game.getShipBuilder().buildNewFar(game, dp.getDest(), null, guardRelAngle, 0, pilot, guardConf.items,
guardConf.hull, null, hasRepairer, money, null, true);
Expand Down
14 changes: 7 additions & 7 deletions main/src/com/miloshpetrov/sol2/game/MapDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void draw(GameDrawer drawer, SolGame game) {
float iconSz = getIconRadius(cam) * 2;
float starNodeW = cam.getViewHeight(myZoom) * STAR_NODE_SZ;
float viewDist = cam.getViewDist(myZoom);
FractionMan fractionMan = game.getFractionMan();
FactionMan factionMan = game.getFactionMan();
SolShip hero = game.getHero();
Planet np = game.getPlanetMan().getNearestPlanet();
Vector2 camPos = cam.getPos();
Expand All @@ -108,7 +108,7 @@ public void draw(GameDrawer drawer, SolGame game) {
drawStarNodes(drawer, game, viewDist, camPos, starNodeW);

// using ui textures
drawIcons(drawer, game, iconSz, viewDist, fractionMan, hero, camPos, heroDmgCap);
drawIcons(drawer, game, iconSz, viewDist, factionMan, hero, camPos, heroDmgCap);
}

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

private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float viewDist, FractionMan fractionMan,
private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float viewDist, FactionMan factionMan,
SolShip hero, Vector2 camPos, float heroDmgCap)
{

Expand All @@ -228,7 +228,7 @@ private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float view
SolShip ship = (SolShip) o;
String hint = ship.getPilot().getMapHint();
if (hint == null && !DebugOptions.DETAILED_MAP) continue;
drawObjIcon(iconSz, oPos, ship.getAngle(), fractionMan, hero, ship.getPilot().getFraction(), heroDmgCap, o, ship.getHull().config.getIcon(), drawer);
drawObjIcon(iconSz, oPos, ship.getAngle(), factionMan, hero, ship.getPilot().getFaction(), heroDmgCap, o, ship.getHull().config.getIcon(), drawer);
}
if ((o instanceof StarPort)) {
StarPort sp = (StarPort) o;
Expand All @@ -243,7 +243,7 @@ private void drawIcons(GameDrawer drawer, SolGame game, float iconSz, float view
if (viewDist < camPos.dst(oPos)) continue;
String hint = ship.getPilot().getMapHint();
if (hint == null && !DebugOptions.DETAILED_MAP) continue;
drawObjIcon(iconSz, oPos, ship.getAngle(), fractionMan, hero, ship.getPilot().getFraction(), heroDmgCap, ship, ship.getHullConfig().getIcon(), drawer);
drawObjIcon(iconSz, oPos, ship.getAngle(), factionMan, hero, ship.getPilot().getFaction(), heroDmgCap, ship, ship.getHullConfig().getIcon(), drawer);
}
List<StarPort.MyFar> farPorts = game.getObjMan().getFarPorts();
for (int i = 0, sz = farPorts.size(); i < sz; i++) {
Expand Down Expand Up @@ -327,10 +327,10 @@ private void drawNpGround(GameDrawer drawer, SolGame game, float viewDist, Plane
}

public void drawObjIcon(float iconSz, Vector2 pos, float objAngle,
FractionMan fractionMan, SolShip hero, Fraction objFrac, float heroDmgCap,
FactionMan factionMan, SolShip hero, Faction objFac, float heroDmgCap,
Object shipHack, TextureAtlas.AtlasRegion icon, Object drawerHack)
{
boolean enemy = hero != null && fractionMan.areEnemies(objFrac, hero.getPilot().getFraction());
boolean enemy = hero != null && factionMan.areEnemies(objFac, hero.getPilot().getFaction());
float angle = objAngle;
if (enemy && mySkullTime > 0 && HardnessCalc.isDangerous(heroDmgCap, shipHack)) {
icon = mySkullTex;
Expand Down
4 changes: 2 additions & 2 deletions main/src/com/miloshpetrov/sol2/game/ObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ObjectManager {
private float myFarBeginDist;
private float myRadiusRecalcAwait;

public ObjectManager(SolContactListener contactListener, FractionMan fractionMan) {
public ObjectManager(SolContactListener contactListener, FactionMan factionMan) {
myObjs = new ArrayList<SolObject>();
myToRemove = new ArrayList<SolObject>();
myToAdd = new ArrayList<SolObject>();
Expand All @@ -35,7 +35,7 @@ public ObjectManager(SolContactListener contactListener, FractionMan fractionMan
myFarPorts = new ArrayList<StarPort.MyFar>();
myWorld = new World(new Vector2(0, 0), true);
myWorld.setContactListener(contactListener);
myWorld.setContactFilter(new SolContactFilter(fractionMan));
myWorld.setContactFilter(new SolContactFilter(factionMan));
myDr = new Box2DDebugRenderer();
myRadii = new HashMap<SolObject, Float>();
}
Expand Down
8 changes: 4 additions & 4 deletions main/src/com/miloshpetrov/sol2/game/SolContactFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.miloshpetrov.sol2.game.projectile.Projectile;

public class SolContactFilter implements ContactFilter {
private final FractionMan myFractionMan;
private final FactionMan myFactionMan;

public SolContactFilter(FractionMan fractionMan) {
myFractionMan = fractionMan;
public SolContactFilter(FactionMan factionMan) {
myFactionMan = factionMan;
}

@Override
Expand All @@ -22,6 +22,6 @@ public boolean shouldCollide(Fixture fixtureA, Fixture fixtureB) {
Projectile proj = (Projectile)(aIsProj ? oA : oB);
SolObject o = aIsProj ? oB : oA;
Fixture f = aIsProj ? fixtureB : fixtureA;
return proj.shouldCollide(o, f, myFractionMan);
return proj.shouldCollide(o, f, myFactionMan);
}
}

0 comments on commit cd0567b

Please sign in to comment.