Added support for warp substs

This commit is contained in:
Collin Smith 2019-11-03 01:20:20 -07:00
parent ad0aa06a5d
commit 6fb76615ba
4 changed files with 70 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.PooledEngine;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.IntIntMap;
import com.riiablo.Riiablo;
import com.riiablo.codec.COF;
import com.riiablo.codec.excel.Levels;
@ -255,6 +256,23 @@ public class Engine extends PooledEngine {
warpComponent.index = index;
warpComponent.dstLevel = dstLevel;
warpComponent.warp = warp;
IntIntMap substs = warpComponent.substs;
if (warp.LitVersion) {
// FIXME: Below will cover overwhelming majority of cases -- need to solve act 5 ice cave case where 3 tiles are used
// I think this can be done by checking if there's a texture with the same id, else it's a floor warp
if (subIndex < 2) {
for (int i = 0; i < 2; i++) {
substs.put(DT1.Tile.Index.create(orientation, mainIndex, i), DT1.Tile.Index.create(orientation, mainIndex, i + warp.Tiles));
}
} else {
substs.put(DT1.Tile.Index.create(0, subIndex, 0), DT1.Tile.Index.create(0, subIndex, 4));
substs.put(DT1.Tile.Index.create(0, subIndex, 1), DT1.Tile.Index.create(0, subIndex, 5));
substs.put(DT1.Tile.Index.create(0, subIndex, 2), DT1.Tile.Index.create(0, subIndex, 6));
substs.put(DT1.Tile.Index.create(0, subIndex, 3), DT1.Tile.Index.create(0, subIndex, 7));
}
} else {
//substs = EMPTY_INT_INT_MAP;
}
BBoxComponent boxComponent = createComponent(BBoxComponent.class);
boxComponent.box = box;

View File

@ -1,6 +1,7 @@
package com.riiablo.engine.component;
import com.badlogic.ashley.core.Component;
import com.badlogic.gdx.utils.IntIntMap;
import com.badlogic.gdx.utils.Pool;
import com.riiablo.codec.excel.Levels;
import com.riiablo.codec.excel.LvlWarp;
@ -10,10 +11,13 @@ public class WarpComponent implements Component, Pool.Poolable {
public LvlWarp.Entry warp;
public Levels.Entry dstLevel;
public final IntIntMap substs = new IntIntMap();
@Override
public void reset() {
index = -1;
warp = null;
dstLevel = null;
substs.clear();
}
}

View File

@ -0,0 +1,44 @@
package com.riiablo.engine.system;
import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.riiablo.engine.Flags;
import com.riiablo.engine.component.MapComponent;
import com.riiablo.engine.component.WarpComponent;
import com.riiablo.map.Map;
public class WarpSystem extends IteratingSystem {
private final ComponentMapper<WarpComponent> warpComponent = ComponentMapper.getFor(WarpComponent.class);
private Map map;
public WarpSystem() {
super(Family.all(WarpComponent.class, MapComponent.class).get());
}
public Map getMap() {
return map;
}
public void setMap(Map map) {
if (this.map != map) {
this.map = map;
}
}
@Override
public void update(float delta) {
map.clearWarpSubsts();
super.update(delta);
}
@Override
protected void processEntity(Entity entity, float delta) {
WarpComponent warpComponent = this.warpComponent.get(entity);
if ((entity.flags & Flags.SELECTED) == Flags.SELECTED) {
map.addWarpSubsts(warpComponent.substs);
}
}
}

View File

@ -667,6 +667,10 @@ public class Map implements Disposable {
}
}
public void clearWarpSubsts() {
this.warpSubsts.clear();
}
private MapGraph mapGraph = new MapGraph(this);
private IndexedAStarPathFinder<MapGraph.Point2> pathFinder = new IndexedAStarPathFinder<>(mapGraph, true);