-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed fraction to faction. No functionality changes.
- Loading branch information
Showing
30 changed files
with
292 additions
and
292 deletions.
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
28 changes: 14 additions & 14 deletions
28
.../com/miloshpetrov/sol2/game/Fraction.java → ...c/com/miloshpetrov/sol2/game/Faction.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 |
---|---|---|
@@ -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; | ||
} | ||
} |
168 changes: 84 additions & 84 deletions
168
...m/miloshpetrov/sol2/game/FractionMan.java → ...om/miloshpetrov/sol2/game/FactionMan.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 |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.