001package com.fs.starfarer.api.impl.combat; 002 003import java.util.ArrayList; 004import java.util.HashMap; 005import java.util.List; 006import java.util.Map; 007 008import com.fs.starfarer.api.Global; 009import com.fs.starfarer.api.combat.BattleObjectiveAPI; 010import com.fs.starfarer.api.combat.BattleObjectiveEffect; 011import com.fs.starfarer.api.combat.CombatEngineAPI; 012import com.fs.starfarer.api.combat.CombatFleetManagerAPI; 013import com.fs.starfarer.api.combat.FogOfWarAPI; 014 015public abstract class BaseBattleObjectiveEffect implements BattleObjectiveEffect { 016 017 protected CombatEngineAPI engine; 018 protected List<ShipStatusItem> itemsNAFrigates = new ArrayList<ShipStatusItem>(); 019 protected List<ShipStatusItem> itemsNAFighters= new ArrayList<ShipStatusItem>(); 020 021 protected BattleObjectiveAPI objective; 022 023 private Map<BattleObjectiveAPI, Integer> prevOwners = new HashMap<BattleObjectiveAPI, Integer>(); 024 025 public void init(CombatEngineAPI engine, BattleObjectiveAPI objective) { 026 this.engine = engine; 027 this.objective = objective; 028 029 ShipStatusItem item = new ShipStatusItem(objective.getDisplayName(), "n / a to fighters", false); 030 itemsNAFighters.add(item); 031 item = new ShipStatusItem(objective.getDisplayName(), "n / a to frigates", false); 032 itemsNAFrigates.add(item); 033 } 034 035 public int getBonusDeploymentPoints() { 036 int bs = Global.getSettings().getBattleSize(); 037 int bonus = (int)Math.round((float) bs * objective.getBattleSizeFractionBonus()); 038 return bonus; 039 } 040 041 public void giveCommandPointsForCapturing(int points) { 042 int owner = objective.getOwner(); 043 CombatFleetManagerAPI fleetManager = engine.getFleetManager(owner); 044 if (fleetManager != null) { 045 Integer prevOwner = (Integer) prevOwners.get(objective); 046 if (prevOwner != null && prevOwner.intValue() != owner) { 047 // objective just switched hands, give bonus 048 String bonusKey = objective.getDisplayName() + "_bonus_ " + "" + (float) Math.random(); 049 fleetManager.getTaskManager(false).getCommandPointsStat().modifyFlat(bonusKey, points); 050 fleetManager.getTaskManager(true).getCommandPointsStat().modifyFlat(bonusKey, points); 051 } 052 } 053 prevOwners.put(objective, owner); 054 } 055 056 057 public void revealArea(float radius) { 058 FogOfWarAPI fog = engine.getFogOfWar(0); 059 if (objective.getOwner() == 0) { 060 fog.revealAroundPoint(objective, objective.getLocation().x, objective.getLocation().y, radius); 061 } 062 063 fog = engine.getFogOfWar(1); 064 if (objective.getOwner() == 1) { 065 fog.revealAroundPoint(objective, objective.getLocation().x, objective.getLocation().y, radius); 066 } 067 } 068 069}