Search in sources :

Example 91 with Coordinates

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);
            }
        }
    }
}
Also used : Obj(main.entity.obj.Obj) MicroObj(main.entity.obj.MicroObj) ZCoordinates(main.game.bf.ZCoordinates) Coordinates(main.game.bf.Coordinates)

Example 92 with Coordinates

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;
}
Also used : XLinkedMap(main.data.XLinkedMap) ENCOUNTER_TYPE(main.content.enums.EncounterEnums.ENCOUNTER_TYPE) Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList) Conditions(main.elements.conditions.Conditions) FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) Ref(main.entity.Ref) ObjType(main.entity.type.ObjType)

Example 93 with Coordinates

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;
}
Also used : HashMap(java.util.HashMap) Obj(main.entity.obj.Obj) Coordinates(main.game.bf.Coordinates)

Example 94 with Coordinates

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;
}
Also used : FACING_DIRECTION(main.game.bf.Coordinates.FACING_DIRECTION) ObjAtCoordinate(main.entity.type.ObjAtCoordinate) ObjType(main.entity.type.ObjType) Coordinates(main.game.bf.Coordinates)

Example 95 with Coordinates

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;
}
Also used : Coordinates(main.game.bf.Coordinates) ArrayList(java.util.ArrayList) Unit(eidolons.entity.obj.unit.Unit) DC_Player(eidolons.game.battlecraft.logic.battle.universal.DC_Player) UnitData(eidolons.game.battlecraft.logic.dungeon.universal.UnitData) SPAWN_MODE(eidolons.game.battlecraft.logic.dungeon.universal.Spawner.SPAWN_MODE) ObjType(main.entity.type.ObjType)

Aggregations

Coordinates (main.game.bf.Coordinates)226 Unit (eidolons.entity.obj.unit.Unit)49 ObjType (main.entity.type.ObjType)30 ArrayList (java.util.ArrayList)29 Obj (main.entity.obj.Obj)28 DC_Obj (eidolons.entity.obj.DC_Obj)22 BattleFieldObject (eidolons.entity.obj.BattleFieldObject)21 FACING_DIRECTION (main.game.bf.Coordinates.FACING_DIRECTION)21 DIRECTION (main.game.bf.Coordinates.DIRECTION)20 Ref (main.entity.Ref)15 MapBlock (eidolons.game.battlecraft.logic.dungeon.location.building.MapBlock)13 DC_Cell (eidolons.entity.obj.DC_Cell)12 Action (eidolons.game.battlecraft.ai.elements.actions.Action)11 DC_ActiveObj (eidolons.entity.active.DC_ActiveObj)9 BufferedImage (java.awt.image.BufferedImage)8 DequeImpl (main.system.datatypes.DequeImpl)8 Vector2 (com.badlogic.gdx.math.Vector2)7 DC_UnitAction (eidolons.entity.active.DC_UnitAction)7 ZCoordinates (main.game.bf.ZCoordinates)6 ObjAtCoordinate (main.entity.type.ObjAtCoordinate)5