Starsector API
Loading...
Searching...
No Matches
BaseBattleObjectiveEffect.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.combat;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.combat.BattleObjectiveAPI;
10import com.fs.starfarer.api.combat.BattleObjectiveEffect;
11import com.fs.starfarer.api.combat.CombatEngineAPI;
12import com.fs.starfarer.api.combat.CombatFleetManagerAPI;
13import com.fs.starfarer.api.combat.FogOfWarAPI;
14
15public abstract class BaseBattleObjectiveEffect implements BattleObjectiveEffect {
16
17 protected CombatEngineAPI engine;
18 protected List<ShipStatusItem> itemsNAFrigates = new ArrayList<ShipStatusItem>();
19 protected List<ShipStatusItem> itemsNAFighters= new ArrayList<ShipStatusItem>();
20
21 protected BattleObjectiveAPI objective;
22
23 private Map<BattleObjectiveAPI, Integer> prevOwners = new HashMap<BattleObjectiveAPI, Integer>();
24
25 public void init(CombatEngineAPI engine, BattleObjectiveAPI objective) {
26 this.engine = engine;
27 this.objective = objective;
28
29 ShipStatusItem item = new ShipStatusItem(objective.getDisplayName(), "n / a to fighters", false);
30 itemsNAFighters.add(item);
31 item = new ShipStatusItem(objective.getDisplayName(), "n / a to frigates", false);
32 itemsNAFrigates.add(item);
33 }
34
36 int bs = Global.getSettings().getBattleSize();
37 int bonus = (int)Math.round((float) bs * objective.getBattleSizeFractionBonus());
38 return bonus;
39 }
40
41 public void giveCommandPointsForCapturing(int points) {
42 int owner = objective.getOwner();
43 CombatFleetManagerAPI fleetManager = engine.getFleetManager(owner);
44 if (fleetManager != null) {
45 Integer prevOwner = (Integer) prevOwners.get(objective);
46 if (prevOwner != null && prevOwner.intValue() != owner) {
47 // objective just switched hands, give bonus
48 String bonusKey = objective.getDisplayName() + "_bonus_ " + "" + (float) Math.random();
49 fleetManager.getTaskManager(false).getCommandPointsStat().modifyFlat(bonusKey, points);
50 fleetManager.getTaskManager(true).getCommandPointsStat().modifyFlat(bonusKey, points);
51 }
52 }
53 prevOwners.put(objective, owner);
54 }
55
56
57 public void revealArea(float radius) {
58 FogOfWarAPI fog = engine.getFogOfWar(0);
59 if (objective.getOwner() == 0) {
60 fog.revealAroundPoint(objective, objective.getLocation().x, objective.getLocation().y, radius);
61 }
62
63 fog = engine.getFogOfWar(1);
64 if (objective.getOwner() == 1) {
65 fog.revealAroundPoint(objective, objective.getLocation().x, objective.getLocation().y, radius);
66 }
67 }
68
69}
static SettingsAPI getSettings()
Definition Global.java:51
void init(CombatEngineAPI engine, BattleObjectiveAPI objective)