Skip to content

Commit

Permalink
Update 14.11.2021 - ready to play
Browse files Browse the repository at this point in the history
  • Loading branch information
Ontheheavens committed Nov 14, 2021
1 parent 5679eb7 commit e9c07a0
Show file tree
Hide file tree
Showing 20 changed files with 263 additions and 205 deletions.
2 changes: 1 addition & 1 deletion data/campaign/abilities.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name,id,type,tags,activationDays,activationCooldown,durationDays,deactivationDays,deactivationCooldown,unlockedAtStart,defaultForAIFleet,musicSuppression,uiOn,uiOff,uiLoop,worldOn,worldOff,worldLoop,icon,plugin,ai,desc,sortOrder
"Forge Production",forge_production,TOGGLE,"burn-, stealth-",0.2,,,0.05,,TRUE,,,ui_neutrino_detector_on,ui_neutrino_detector_off,,system_temporalshell_off,,system_temporalshell_loop,graphics/icons/abilities/forge_production.png,data.forge.abilities.ForgeProduction,,"Control production of your Forge Modules.",868
"Forge Production",forge_production,TOGGLE,"burn-, stealth-,sensors+",0.5,,,0.25,1,TRUE,,,ui_neutrino_detector_on,ui_neutrino_detector_off,,system_temporalshell_off,,system_temporalshell_loop,graphics/icons/abilities/forge_production.png,data.forge.abilities.ForgeProduction,,"Control forge production of your fleet.",868
64 changes: 45 additions & 19 deletions data/forge/abilities/ForgeProduction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.Color;

import data.forge.abilities.conversion.*;
import data.forge.plugins.ForgeSettings;
import org.lwjgl.util.vector.Vector2f;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.util.Misc;
Expand All @@ -20,25 +21,31 @@

public class ForgeProduction extends BaseToggleAbility {

// Here: Declared constants

private static final Vector2f ZERO = new Vector2f();

private int notificationCounter = 0;

private final IntervalUtil productionInterval = new IntervalUtil(1f,1f);

// Here: Inherited methods

protected void activateImpl() { }

@Override
protected String getActivationText() {
return "Commencing forge production";
}

protected void applyEffect(float amount, float level) {

CampaignFleetAPI fleet = getFleet();

if (fleet == null) return;
if (!isActive()) return;

if (ENABLE_PENALTIES) {
fleet.getStats().getDetectedRangeMod().modifyPercent(getModId(), ForgeSettings.SENSOR_PROFILE_INCREASE, "Forge production");
fleet.goSlowOneFrame();
}

float days = Global.getSector().getClock().convertToDays(amount);

productionInterval.advance(days);
Expand All @@ -53,18 +60,18 @@ protected void applyEffect(float amount, float level) {

ForgeAssemblingLogic.startAssembling(fleet);

if (goodsWereForged ()) {
if (goodsWereForged()) {

fleet.addFloatingText("Forged goods", Misc.setAlpha(Misc.getTextColor(), 255), 0.5f);

if(PLAY_SOUND_NOTIFICATION) {
Global.getSoundPlayer().playSound("ui_cargo_raremetals", 1f, 1f, fleet.getLocation(), ZERO);
}

clearGoodsStatus ();
clearGoodsStatus();
}

if (SHOW_NOTIFICATION && goodsProducedReport ()) {
if (SHOW_NOTIFICATION && goodsProducedReport()) {
notificationCounter += 1;
}

Expand All @@ -82,7 +89,15 @@ protected void applyEffect(float amount, float level) {

protected void deactivateImpl() { cleanupImpl(); }

protected void cleanupImpl() { }
@Override
protected void cleanupImpl() {
CampaignFleetAPI fleet = getFleet();
if (fleet == null) return;

if (ENABLE_PENALTIES) {
fleet.getStats().getDetectedRangeMod().unmodify(getModId());
}
}

@Override
public boolean isUsable() {
Expand Down Expand Up @@ -110,8 +125,8 @@ public float getTooltipWidth() {
@Override
public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {

Color gray = Misc.getGrayColor();
Color highlight = Misc.getHighlightColor();
Color negativeHighlight = Misc.getNegativeHighlightColor();

String status = " (off)";
if (turnedOn) {
Expand All @@ -122,13 +137,17 @@ public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
title.highlightLast(status);
title.setHighlightColor(highlight);

tooltip.setLowGridRowHeight();

float pad = 6f;
tooltip.addPara("Control forge production of your fleet.", pad);
tooltip.addPara("Your fleet must have ships with active forge modules to produce goods. " +
"Ships that are mothballed or do not receive repairs are unable to use their forge modules. " +
"Production also uses heavy machinery, which must be present but is not consumed, and can break accidentally.", pad);
tooltip.addPara("Control forge production of your fleet and monitor fleet forging capacity.", pad);
if (!expanded) {
tooltip.addPara("Your fleet must have ships with active forge modules to produce goods. " +
"Ships that are mothballed or do not receive repairs are unable to use their forge modules. " +
"Production also uses heavy machinery, which must be present but is not consumed, and can break accidentally.", pad);
}

if (!hasActiveForgeShips() && expanded) {
ForgeProductionTooltip.addCannotForgeNote(tooltip);
}

if (hasActiveForgeShips() && expanded) {
ForgeProductionTooltip.addOperationalShipsBreakdown(tooltip);
Expand All @@ -138,14 +157,21 @@ public void createTooltip(TooltipMakerAPI tooltip, boolean expanded) {
ForgeProductionTooltip.addInactiveShipsBreakdown(tooltip);
}

if (!hasActiveForgeShips()) {
tooltip.addPara("Your fleet currently cannot conduct forging operations.", negativeHighlight, pad);
}

if (expanded) {
ForgeProductionTooltip.addExpandedInfo(tooltip);
}

if (ENABLE_PENALTIES && !expanded) {
tooltip.addPara("Causes the fleet to %s and increases the range at which the fleet can be detected by %s.",
pad, highlight, "move slowly", (int) ForgeSettings.SENSOR_PROFILE_INCREASE + "%");

tooltip.addPara("*A fleet is considered slow-moving at a burn level of half that of its slowest ship.", gray, pad);
}

if (!hasActiveForgeShips() && !expanded) {
ForgeProductionTooltip.addCannotForgeNote(tooltip);
}

addIncompatibleToTooltip(tooltip, expanded);
}

Expand Down
15 changes: 10 additions & 5 deletions data/forge/abilities/ForgeProductionTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@

public class ForgeProductionTooltip {

public static void addCannotForgeNote(TooltipMakerAPI tooltip) {
float pad = 6f;
Color negativeHighlight = Misc.getNegativeHighlightColor();
tooltip.addPara("Your fleet currently cannot conduct forging operations.", negativeHighlight, pad);
}

public static void addOperationalShipsBreakdown(TooltipMakerAPI tooltip) {

Color textColor = Misc.getTextColor();
Color highlightColor = Misc.getHighlightColor();
Color positiveHighlightColor = Misc.getPositiveHighlightColor();

String indent = " ";
float pad = 6f;
float pad = 10f;

tooltip.addSectionHeading("Operational ships", Alignment.MID, pad);
tooltip.addSpacer(6f);
Expand All @@ -57,7 +62,7 @@ public static void addOperationalShipsBreakdown(TooltipMakerAPI tooltip) {

String label = indent + shipNameShort + ", " + shipClass;

tooltip.addToGrid(0, rowNumber++, label, forgeModule, positiveHighlightColor);
tooltip.addToGrid(0, rowNumber++, label, forgeModule, highlightColor);

counter++;

Expand All @@ -81,7 +86,7 @@ public static void addInactiveShipsBreakdown(TooltipMakerAPI tooltip) {
Color highlightColor = Misc.getHighlightColor();

String indent = " ";
float pad = 6f;
float pad = 10f;

tooltip.addSectionHeading("Inactive ships", Alignment.MID, pad);
tooltip.addSpacer(6f);
Expand Down Expand Up @@ -131,7 +136,7 @@ public static void addExpandedInfo(TooltipMakerAPI tooltip) {
}

if (ForgeConditionChecker.hasAnySpecialItem()) {
addSpecialItemsBreakdown(tooltip);
ForgeProductionTooltip.addSpecialItemsBreakdown(tooltip);
}

}
Expand Down
12 changes: 6 additions & 6 deletions data/forge/abilities/conversion/ForgeAssemblingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ public static void assembleMachinery(CampaignFleetAPI fleet) {
float metalInAssembling = ForgeConditionChecker.getPlayerCargo(Commodities.METALS) / METAL_TO_ASSEMBLE;
float transplutonicsInAssembling = ForgeConditionChecker.getPlayerCargo(Commodities.RARE_METALS) / TRANSPLUTONICS_TO_ASSEMBLE;

int assemblingCycles = (int) (Math.min(assemblingCapacity,
int assemblingCycles = (int) Math.floor(Math.min(assemblingCapacity,
Math.min(machineryAvailableForAssembling, Math.min(metalInAssembling, transplutonicsInAssembling))));

boolean willHeavyMachineryBreakdown = ForgeConditionChecker.getMachineryBreakdownChance();
int MachineryInAssembling = (int) Math.ceil((assemblingCapacity * HEAVY_MACHINERY_ASSEMBLING_USAGE));
int machineryBroken = 0;

for (int machineryInCheck = 0; machineryInCheck < MachineryInAssembling; machineryInCheck++) {
if (Math.random() < ((float) BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality()))
if (Math.random() < (BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality()))
machineryBroken++;
}

float dailyMetalSpent = METAL_TO_ASSEMBLE * assemblingCycles;
float dailyTransplutonicsSpent = TRANSPLUTONICS_TO_ASSEMBLE * assemblingCycles;
float dailyHeavyMachineryProduced = (HEAVY_MACHINERY_PRODUCED + ForgeConditionChecker.getNanoforgeAssemblingBonus()) * assemblingCycles;
float dailyHeavyMachineryBroken = machineryBroken;
int dailyMetalSpent = (int) Math.ceil(METAL_TO_ASSEMBLE * assemblingCycles);
int dailyTransplutonicsSpent = (int) Math.ceil(TRANSPLUTONICS_TO_ASSEMBLE * assemblingCycles);
int dailyHeavyMachineryProduced = (int) Math.floor((HEAVY_MACHINERY_PRODUCED + ForgeConditionChecker.getNanoforgeAssemblingBonus()) * assemblingCycles);
int dailyHeavyMachineryBroken = machineryBroken;

fleet.getCargo().removeCommodity(Commodities.METALS, dailyMetalSpent);
fleet.getCargo().removeCommodity(Commodities.RARE_METALS, dailyTransplutonicsSpent);
Expand Down
10 changes: 5 additions & 5 deletions data/forge/abilities/conversion/ForgeCentrifugingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public static void centrifugeFuel(CampaignFleetAPI fleet) {

int initialCentrifugingCycles = (int) Math.min(centrifugingCapacity, Math.min(machineryAvailableForCentrifuging, volatilesInCentrifuging));

int centrifugingCycles = Math.min(initialCentrifugingCycles, getPossibleCentrifugingCycles(fleet));
int centrifugingCycles = (int) Math.floor(Math.min(initialCentrifugingCycles, getPossibleCentrifugingCycles(fleet)));

boolean willHeavyMachineryBreakdown = ForgeConditionChecker.getMachineryBreakdownChance();
int machineryInCentrifuging = (int) Math.ceil((centrifugingCycles * HEAVY_MACHINERY_CENTRIFUGING_USAGE));
int machineryBroken = 0;

for (int machineryInCheck = 0; machineryInCheck < machineryInCentrifuging; machineryInCheck++) {
if (Math.random()<((float) BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality())) machineryBroken++;
if (Math.random()<(BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality())) machineryBroken++;
}

float dailyVolatilesSpent = VOLATILES_TO_CENTRIFUGE * centrifugingCycles;
float dailyFuelProduced = (FUEL_PRODUCED + ForgeConditionChecker.getSynchrotronCoreBonus()) * centrifugingCycles;
float dailyHeavyMachineryBroken = machineryBroken;
int dailyVolatilesSpent = (int) Math.ceil(VOLATILES_TO_CENTRIFUGE * centrifugingCycles);
int dailyFuelProduced = (int) Math.floor((FUEL_PRODUCED + ForgeConditionChecker.getSynchrotronCoreBonus()) * centrifugingCycles);
int dailyHeavyMachineryBroken = machineryBroken;

fleet.getCargo().removeCommodity(Commodities.VOLATILES, dailyVolatilesSpent);
fleet.getCargo().addCommodity(Commodities.FUEL, dailyFuelProduced);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void applyForgingCRMalus(CampaignFleetAPI fleet, String forgeType)
if ((!ForgeConditionChecker.isOperational(member)))
continue;
if (member.getVariant().hasHullMod(forgeType))
member.getRepairTracker().applyCREvent(-(((float) CR_PRODUCTION_DECAY * ForgeConditionChecker.getForgingQuality()) *
member.getRepairTracker().applyCREvent(-((CR_PRODUCTION_DECAY * ForgeConditionChecker.getForgingQuality()) *
(member.getRepairTracker().getCR() / 0.7f)), "Forged goods");
}
}
Expand Down
12 changes: 6 additions & 6 deletions data/forge/abilities/conversion/ForgeManufacturingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ public static void manufactureSupplies(CampaignFleetAPI fleet) {
float metalInManufacturing = ForgeConditionChecker.getPlayerCargo(Commodities.METALS) / METAL_TO_MANUFACTURE;
float transplutonicsInManufacturing = ForgeConditionChecker.getPlayerCargo(Commodities.RARE_METALS) / TRANSPLUTONICS_TO_MANUFACTURE;

int manufacturingCycles = (int) (Math.min(manufacturingCapacity,
int manufacturingCycles = (int) Math.floor(Math.min(manufacturingCapacity,
Math.min(machineryAvailableForManufacturing, Math.min(metalInManufacturing, transplutonicsInManufacturing))));

boolean willHeavyMachineryBreakdown = ForgeConditionChecker.getMachineryBreakdownChance();
int MachineryInManufacturing = (int) Math.ceil((manufacturingCycles * HEAVY_MACHINERY_MANUFACTURING_USAGE));
int machineryBroken = 0;

for (int machineryInCheck = 0; machineryInCheck < MachineryInManufacturing; machineryInCheck++) {
if (Math.random() < ((float) BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality()))
if (Math.random() < (BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality()))
machineryBroken++;
}

float dailyMetalSpent = METAL_TO_MANUFACTURE * manufacturingCycles;
float dailyTransplutonicsSpent = TRANSPLUTONICS_TO_MANUFACTURE * manufacturingCycles;
float dailySuppliesProduced = (SUPPLIES_PRODUCED + ForgeConditionChecker.getNanoforgeManufacturingBonus()) * manufacturingCycles;
float dailyHeavyMachineryBroken = machineryBroken;
int dailyMetalSpent = (int) Math.ceil(METAL_TO_MANUFACTURE * manufacturingCycles);
int dailyTransplutonicsSpent = (int) Math.ceil(TRANSPLUTONICS_TO_MANUFACTURE * manufacturingCycles);
int dailySuppliesProduced = (int) Math.floor((SUPPLIES_PRODUCED + ForgeConditionChecker.getNanoforgeManufacturingBonus()) * manufacturingCycles);
int dailyHeavyMachineryBroken = machineryBroken;

fleet.getCargo().removeCommodity(Commodities.METALS, dailyMetalSpent);
fleet.getCargo().removeCommodity(Commodities.RARE_METALS, dailyTransplutonicsSpent);
Expand Down
20 changes: 10 additions & 10 deletions data/forge/abilities/conversion/ForgeRefiningLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public static void refineOre(CampaignFleetAPI fleet) {

float oreInRefining = ForgeConditionChecker.getPlayerCargo(Commodities.ORE)/ ORE_TO_REFINE;

int refiningCycles = (int) (Math.min(refiningCapacity, Math.min(machineryAvailableForRefining, oreInRefining)));
int refiningCycles = (int) Math.floor(Math.min(refiningCapacity, Math.min(machineryAvailableForRefining, oreInRefining)));

boolean willHeavyMachineryBreakdown = ForgeConditionChecker.getMachineryBreakdownChance();
int MachineryInRefining = (int) Math.ceil((refiningCycles * HEAVY_MACHINERY_REFINING_USAGE));
int machineryBroken = 0;

for (int machineryInCheck = 0; machineryInCheck < MachineryInRefining; machineryInCheck++) {
if (Math.random()<((float) BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality())) machineryBroken++;
if (Math.random()<(BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality())) machineryBroken++;
}

float dailyOreSpent = ORE_TO_REFINE * refiningCycles;
float dailyMetalProduced = (METAL_PRODUCED + ForgeConditionChecker.getCatalyticCoreBonus()) * refiningCycles;
float dailyHeavyMachineryBroken = machineryBroken;
int dailyOreSpent = (int) Math.ceil(ORE_TO_REFINE * refiningCycles);
int dailyMetalProduced = (int) Math.floor((METAL_PRODUCED + ForgeConditionChecker.getCatalyticCoreBonus()) * refiningCycles);
int dailyHeavyMachineryBroken = machineryBroken;

fleet.getCargo().removeCommodity(Commodities.ORE, dailyOreSpent);
fleet.getCargo().addCommodity(Commodities.METALS, dailyMetalProduced);
Expand Down Expand Up @@ -79,19 +79,19 @@ public static void refineTransplutonicOre(CampaignFleetAPI fleet) {

float transplutonicOreInRefining = ForgeConditionChecker.getPlayerCargo(Commodities.RARE_ORE) / TRANSPLUTONIC_ORE_TO_REFINE;

int refiningCycles = (int) (Math.min(refiningCapacity, Math.min(machineryAvailableForRefining, transplutonicOreInRefining)));
int refiningCycles = (int) Math.floor(Math.min(refiningCapacity, Math.min(machineryAvailableForRefining, transplutonicOreInRefining)));

boolean willHeavyMachineryBreakdown = ForgeConditionChecker.getMachineryBreakdownChance();
int machineryInRefining = (int) Math.ceil((refiningCycles * HEAVY_MACHINERY_REFINING_USAGE));
int machineryBroken = 0;

for (int machineryInCheck = 0; machineryInCheck < machineryInRefining; machineryInCheck++) {
if (Math.random()<((float) BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality())) machineryBroken++;
if (Math.random()<(BREAKDOWN_SEVERITY * ForgeConditionChecker.getForgingQuality())) machineryBroken++;
}

float dailyTransplutonicOreSpent = TRANSPLUTONIC_ORE_TO_REFINE * refiningCycles;
float dailyTransplutonicsProduced = (TRANSPLUTONICS_PRODUCED + ForgeConditionChecker.getCatalyticCoreBonus()) * refiningCycles;
float dailyHeavyMachineryBroken = machineryBroken;
int dailyTransplutonicOreSpent = (int) Math.ceil(TRANSPLUTONIC_ORE_TO_REFINE * refiningCycles);
int dailyTransplutonicsProduced = (int) Math.floor((TRANSPLUTONICS_PRODUCED + ForgeConditionChecker.getCatalyticCoreBonus()) * refiningCycles);
int dailyHeavyMachineryBroken = machineryBroken;

fleet.getCargo().removeCommodity(Commodities.RARE_ORE, dailyTransplutonicOreSpent);
fleet.getCargo().addCommodity(Commodities.RARE_METALS, dailyTransplutonicsProduced);
Expand Down
Loading

0 comments on commit e9c07a0

Please sign in to comment.