WIP unit tether component
This commit is contained in:
@@ -76,7 +76,7 @@ public class UnitTypes{
|
||||
//special block unit type
|
||||
public static @EntityDef({Unitc.class, BlockUnitc.class}) UnitType block;
|
||||
|
||||
//special tethered (has payload capability, because it's necessary sometimes)
|
||||
//special building tethered (has payload capability, because it's necessary sometimes)
|
||||
public static @EntityDef({Unitc.class, BuildingTetherc.class, Payloadc.class}) UnitType manifold, assemblyDrone;
|
||||
|
||||
//tank
|
||||
|
||||
39
core/src/mindustry/entities/comp/UnitTetherComp.java
Normal file
39
core/src/mindustry/entities/comp/UnitTetherComp.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package mindustry.entities.comp;
|
||||
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
|
||||
/** A unit that depends on a units's existence; if that unit is removed, it despawns. */
|
||||
@Component
|
||||
abstract class UnitTetherComp implements Unitc{
|
||||
@Import UnitType type;
|
||||
@Import Team team;
|
||||
|
||||
//spawner unit cannot be read directly for technical reasons.
|
||||
public transient @Nullable Unit spawner;
|
||||
public int spawnerUnitId = -1;
|
||||
|
||||
@Override
|
||||
public void afterRead(){
|
||||
if(spawnerUnitId != -1) spawner = Groups.unit.getByID(spawnerUnitId);
|
||||
spawnerUnitId = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSync(){
|
||||
if(spawnerUnitId != -1) spawner = Groups.unit.getByID(spawnerUnitId);
|
||||
spawnerUnitId = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(spawner == null || !spawner.isValid() || spawner.team != team){
|
||||
Call.unitDespawn(self());
|
||||
}else{
|
||||
spawnerUnitId = spawner.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user