-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
392f84a
commit 876912a
Showing
8 changed files
with
155 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,118 @@ | ||
package fos.type.units.comp; | ||
|
||
public class FOSCrawlComp { | ||
import arc.math.*; | ||
import arc.math.geom.Vec2; | ||
import arc.util.Time; | ||
import mindustry.Vars; | ||
import mindustry.ai.Pathfinder; | ||
import mindustry.annotations.Annotations.*; | ||
import mindustry.content.*; | ||
import mindustry.game.Team; | ||
import mindustry.gen.*; | ||
import mindustry.type.UnitType; | ||
import mindustry.world.Tile; | ||
import mindustry.world.blocks.environment.Floor; | ||
|
||
import static mindustry.Vars.*; | ||
|
||
/** | ||
* A stripped-down version of CrawlComp without solidity() method | ||
* to avoid conflicts with other components. | ||
* This is VERY cursed. | ||
*/ | ||
@Component | ||
public abstract class FOSCrawlComp implements Posc, Rotc, Hitboxc, Unitc { | ||
@Import | ||
float x, y, speedMultiplier, rotation, hitSize; | ||
@Import | ||
UnitType type; | ||
@Import | ||
Team team; | ||
@Import | ||
Vec2 vel; | ||
|
||
transient Floor lastDeepFloor; | ||
transient float lastCrawlSlowdown = 1f; | ||
transient float segmentRot, crawlTime = Mathf.random(100f); | ||
|
||
// there goes the solidity(). | ||
|
||
@Override | ||
@Replace | ||
public int pathType(){ | ||
return Pathfinder.costLegs; | ||
} | ||
|
||
@Override | ||
@Replace | ||
public float floorSpeedMultiplier(){ | ||
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn(); | ||
//TODO take into account extra blocks | ||
return (on.isDeep() ? 0.45f : on.speedMultiplier) * speedMultiplier * lastCrawlSlowdown; | ||
} | ||
|
||
@Override | ||
public void add(){ | ||
//reset segment rotation on add | ||
segmentRot = rotation; | ||
} | ||
|
||
@Override | ||
@Replace | ||
public Floor drownFloor(){ | ||
return lastDeepFloor; | ||
} | ||
|
||
@Override | ||
public void update(){ | ||
if(moving()){ | ||
segmentRot = Angles.moveToward(segmentRot, rotation, type.segmentRotSpeed * Time.delta); | ||
|
||
int radius = (int)Math.max(0, hitSize / tilesize * 2f); | ||
int count = 0, solids = 0, deeps = 0; | ||
lastDeepFloor = null; | ||
|
||
//calculate tiles under this unit, and apply slowdown + particle effects | ||
for(int cx = -radius; cx <= radius; cx++){ | ||
for(int cy = -radius; cy <= radius; cy++){ | ||
if(cx*cx + cy*cy <= radius){ | ||
count ++; | ||
Tile t = Vars.world.tileWorld(x + cx*tilesize, y + cy*tilesize); | ||
if(t != null){ | ||
|
||
if(t.solid()){ | ||
solids ++; | ||
} | ||
|
||
if(t.floor().isDeep()){ | ||
deeps ++; | ||
lastDeepFloor = t.floor(); | ||
} | ||
|
||
//TODO area damage to units | ||
if(t.build != null && t.build.team != team){ | ||
t.build.damage(team, type.crushDamage * Time.delta * state.rules.unitDamage(team)); | ||
} | ||
|
||
if(Mathf.chanceDelta(0.025)){ | ||
Fx.crawlDust.at(t.worldx(), t.worldy(), t.floor().mapColor); | ||
} | ||
}else{ | ||
solids ++; | ||
} | ||
} | ||
} | ||
} | ||
|
||
//when most blocks under this unit cannot be drowned in, do not drown | ||
if((float)deeps / count < 0.75f){ | ||
lastDeepFloor = null; | ||
} | ||
|
||
lastCrawlSlowdown = Mathf.lerpDelta(1f, type.crawlSlowdown, Mathf.clamp((float)solids / count / type.crawlSlowdownFrac)); | ||
} | ||
segmentRot = Angles.clampRange(segmentRot, rotation, type.segmentMaxRot); | ||
|
||
crawlTime += vel.len() * Time.delta; | ||
} | ||
} |
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