WIP unit tether component

This commit is contained in:
Anuken
2022-07-14 15:32:23 -04:00
parent 9dce4f36f7
commit f32e39fb86
2 changed files with 40 additions and 1 deletions

View File

@@ -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

View 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;
}
}
}