001package com.fs.starfarer.api.impl.campaign; 002 003import com.fs.starfarer.api.campaign.AsteroidAPI; 004import com.fs.starfarer.api.campaign.CampaignEngineLayers; 005import com.fs.starfarer.api.campaign.SectorEntityToken; 006import com.fs.starfarer.api.combat.ViewportAPI; 007import com.fs.starfarer.api.util.Misc; 008 009public class HiddenCacheEntityPlugin extends BaseCustomEntityPlugin { 010 011 private AsteroidAPI asteroid; 012 013 public void init(SectorEntityToken entity, Object pluginParams) { 014 super.init(entity, pluginParams); 015 readResolve(); 016 } 017 018 Object readResolve() { 019 return this; 020 } 021 022 protected void createAsteroidIfNeeded() { 023 if (asteroid != null) return; 024 if (entity.getContainingLocation() == null) return; 025 026 asteroid = entity.getContainingLocation().addAsteroid(16f); 027 asteroid.setLocation(entity.getLocation().x, entity.getLocation().y); 028 asteroid.setFacing(Misc.random.nextFloat() * 360f); 029 entity.getContainingLocation().removeEntity(asteroid); 030// float orbitDays = 100f; 031// asteroid.setCircularOrbit(this.entity, 0f, 0f, orbitDays); 032// asteroid.addTag(Tags.NON_CLICKABLE); 033// asteroid.addTag(Tags.NO_ENTITY_TOOLTIP); 034 } 035 036 public void advance(float amount) { 037 if (entity.isInCurrentLocation()) { 038 createAsteroidIfNeeded(); 039 if (asteroid != null) { 040 asteroid.advance(amount); 041 } 042 } 043 } 044 045 public float getRenderRange() { 046 return entity.getRadius() + 100f; 047 } 048 049 public void render(CampaignEngineLayers layer, ViewportAPI viewport) { 050 if (asteroid != null) { 051 asteroid.setLocation(entity.getLocation().x, entity.getLocation().y); 052 asteroid.setLightSource(entity.getLightSource(), entity.getLightColor()); 053 asteroid.forceRender(); 054 } 055 } 056 057} 058 059 060 061 062