use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class DC_ObjInitializer method initializePartyPositions.
public static void initializePartyPositions(String playerPartyData, Collection<? extends Obj> units) {
List<String> items = Arrays.asList(playerPartyData.split(OBJ_SEPARATOR));
for (String item : items) {
Coordinates c = getCoordinatesFromObjString(item);
String typeName = item.split(COORDINATES_OBJ_SEPARATOR)[1];
for (Obj unit : units) {
if (unit.getType().getName().equals(typeName)) {
if (!DC_Game.game.getRules().getStackingRule().canBeMovedOnto(unit, c)) {
// TODO tactics?
// direction
c = Positioner.adjustCoordinate(c, FacingMaster.getRandomFacing());
// preference?
}
unit.setCoordinates(c);
}
}
}
}
use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class ArenaBattleConstructor method constructWaveSequence.
public Map<Wave, Integer> constructWaveSequence(ENCOUNTER_TYPE[] encounter_sequence) {
Integer round = getRoundNumber();
if (SkirmishMaster.isSkirmish()) {
return SkirmishMaster.constructWaveSequences(round);
}
Map<Wave, Integer> map = new XLinkedMap<>();
if (alt != null) {
alt = !alt;
} else {
alt = checkAltEncounter();
}
List<ObjType> waves = getWaveTypes(getDungeon().getType(), alt);
List<ObjType> waveBuffer = new ArrayList<>(waves);
for (ENCOUNTER_TYPE type : encounter_sequence) {
if (waveBuffer.isEmpty()) {
waveBuffer = DataManager.getTypesGroup(DC_TYPE.ENCOUNTERS, StringMaster.getWellFormattedString(type.toString()));
}
waves = new ArrayList<>(waveBuffer);
Conditions conditions = new Conditions(getEncounterTypeCondition(type));
List<ObjType> filteredWaves = new Filter<ObjType>(game, conditions).filter(waves);
if (!filteredWaves.isEmpty()) {
waves = filteredWaves;
} else {
continue;
}
ObjType waveType = getWaveType(waves, type);
waveType = new ObjType(waveType);
FACING_DIRECTION side = null;
// getMaster().getDungeonMaster().getPositioner().nextSide();
waveType.setProperty(PROPS.SPAWNING_SIDE, side.getName());
Coordinates c = pickSpawnCoordinateForWave(type, round, waveType);
Wave wave = new Wave(c, waveType, game, new Ref(game), game.getPlayer(false));
wave.initUnitMap();
map.put(wave, round);
if (Eidolons.DEV_MODE) {
game.getLogManager().logInfo(wave.toString() + " on round #" + round);
}
LogMaster.log(1, wave.toString() + " on round #" + round);
// TODO subtract from
round += getRoundsToFight(waveType, type);
// total pool
}
setIndex(getIndex() + 1);
return map;
}
use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class ArenaBattleConstructor method pickSpawnCoordinateForWave.
private Coordinates pickSpawnCoordinateForWave(ENCOUNTER_TYPE type, Integer round, ObjType waveType, boolean recursion) {
if (sideSpawnTestMode) {
return null;
}
int minDistance = Integer.MAX_VALUE;
int maxDistance = 0;
Map<Coordinates, Point> map = new HashMap<>();
for (String substring : StringMaster.open(getDungeon().getProperty(PROPS.ENCOUNTER_SPAWN_POINTS))) {
Coordinates coordinates = new Coordinates(substring);
if (usedSpawnCoordinates.contains(coordinates)) {
continue;
}
for (Obj member : game.getPlayer(true).getControlledUnits()) {
// summoned?
int distance = PositionMaster.getDistance(member.getCoordinates(), coordinates);
if (distance > maxDistance) {
maxDistance = distance;
}
if (distance < minDistance) {
minDistance = distance;
}
}
map.put(coordinates, new Point(minDistance, maxDistance));
}
if (map.isEmpty()) {
if (recursion) {
return getDefaultSpawnCoordinate(type, round, waveType);
}
usedSpawnCoordinates.clear();
return pickSpawnCoordinateForWave(type, round, waveType, true);
}
Coordinates pick = null;
int minDistanceToOptimal = Integer.MAX_VALUE;
for (Coordinates coordinates : map.keySet()) {
minDistance = map.get(coordinates).x;
maxDistance = map.get(coordinates).y;
int distanceToOptimal = Math.max(0, getOptimalMinDistance() - minDistance);
distanceToOptimal += Math.max(0, maxDistance - getOptimalMaxDistance());
if (distanceToOptimal < minDistanceToOptimal) {
minDistanceToOptimal = distanceToOptimal;
pick = coordinates;
}
}
usedSpawnCoordinates.add(pick);
return pick;
}
use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class WaveAssembler method applyFill.
public boolean applyFill() {
// TODO for each group, add a (next) unit from filler pool
int i = 0;
for (List<ObjAtCoordinate> group : unitGroups) {
ObjType objType = getFillingType();
if (objType == null) {
return false;
}
FACING_DIRECTION side;
try {
side = positioner.getSides().get(i);
} catch (Exception e) {
// if (group.size() == 0)
return false;
// Coordinates c = (Coordinates) group.keySet().toArray()[0];
// if (c == null)
// return false;
// side = positioner.getFacingForEnemy(c);
}
i++;
Coordinates c = null;
try {
c = positioner.getCoordinatesForNewUnitInGroup(side, objType);
} catch (Exception e) {
main.system.ExceptionMaster.printStackTrace(e);
}
if (c == null) {
return false;
}
ObjAtCoordinate objAtCoordinate = new ObjAtCoordinate(objType, c);
group.add(objAtCoordinate);
typeMap.add(objAtCoordinate);
if (fillApplied >= getMaxFillNumber() || !checkPowerAdjustmentNeeded()) {
return false;
}
}
return true;
}
use of main.game.bf.Coordinates in project Eidolons by IDemiurge.
the class CombatScriptExecutor method doSpawn.
private boolean doSpawn(Ref ref, String[] args) {
int i = 0;
DC_Player player = getPlayerManager().getPlayer(args[i]);
if (player == null)
player = getPlayerManager().getPlayer(false);
else
i++;
List<String> units = new ArrayList<>();
// if (args[i].contains(ScriptSyntax.SPAWN_ARG_UNITS_WAVE))
String unitString = args[i];
int level = StringMaster.getInteger(VariableManager.getVars(unitString));
unitString = VariableManager.removeVarPart(unitString);
ObjType wave = DataManager.getType(unitString, DC_TYPE.ENCOUNTERS);
if (wave != null) {
for (String sub : StringMaster.open(wave.getProperty(PROPS.PRESET_GROUP))) {
if (level > 0)
units.add(UnitLevelManager.getLeveledTypeName(level, sub));
else
units.add(sub);
}
}
// TODO adjust wave? difficulty => level
boolean group = false;
if (units.isEmpty()) {
units.addAll(StringMaster.openContainer(UnitGroupMaster.getUnitGroupData(unitString, level)));
}
if (units.isEmpty()) {
// DataManager.gettypes
units.addAll(StringMaster.openContainer(unitString));
} else
group = true;
if (units.isEmpty())
return false;
i++;
// CoordinatesFactory.createCoordinates(unitString);
// if (origin==null )
// origin = ref.getObj(unitString).getCoordinates();
List<Coordinates> coordinates = null;
if (group) {
for (String sub : units) {
coordinates.add(DC_ObjInitializer.getCoordinatesFromObjString(sub));
}
} else
coordinates = getCoordinatesListForUnits(unitString, player, units, ref);
String data = "";
data += DataUnitFactory.getKeyValueString(UnitData.FORMAT, PARTY_VALUE.COORDINATES, StringMaster.joinList(coordinates, DataUnitFactory.getContainerSeparator(UnitData.FORMAT)));
data += DataUnitFactory.getKeyValueString(UnitData.FORMAT, PARTY_VALUE.MEMBERS, StringMaster.joinStringList(units, DataUnitFactory.getContainerSeparator(UnitData.FORMAT)));
UnitData unitData = new UnitData(data);
SPAWN_MODE mode = SPAWN_MODE.SCRIPT;
List<Unit> unitsList = getSpawner().spawn(unitData, player, mode);
getSpawner().getFacingAdjuster().adjustFacing(unitsList);
return true;
}
Aggregations