Skip to content

Commit

Permalink
Add support for jumping to Boggled's gates
Browse files Browse the repository at this point in the history
  • Loading branch information
wispborne committed Jan 4, 2020
1 parent 841860e commit 9e175e8
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 28 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
@@ -1,8 +1,9 @@
# Changelog

## 2.0.3
## 2.0.3 (2020-1-3)

- If no Remnant systems exist, second quest uses a non-Remnant system
- Added support for jumping to Boggled's player constructed gates
- If no Remnant systems exist, second quest uses a non-Remnant system instead
- Fixed third quest intel showing planet type instead of name (thanks to @Avanitia#5323)
- Possibly fixed quest intel icon showing incorrectly (unconfirmed)
- Fixed bug where declining a quest, then trying to start it again would crash
Expand Down
Binary file modified jars/Gates_Awakened.jar
Binary file not shown.
32 changes: 28 additions & 4 deletions src/main/kotlin/org/wisp/gatesawakened/Common.kt
Expand Up @@ -38,9 +38,19 @@ internal object Common {
/**
* List of non-blacklisted gates (filterable), sorted by shortest distance from player first
*/
fun getGates(filter: GateFilter, excludeCurrentGate: Boolean): List<GateInfo> {
fun getGates(
filter: GateFilter,
excludeCurrentGate: Boolean,
includeGatesFromOtherMods: Boolean = false
): List<GateInfo> {
return getSystems()
.flatMap { system -> system.getEntitiesWithTag(Tags.TAG_GATE) }
.flatMap { system ->
system.getEntitiesWithTag(Tags.TAG_GATE) +
if (includeGatesFromOtherMods)
system.getEntitiesWithTag(Tags.TAG_BOGGLED_GATE)
else
emptyList()
}
.asSequence()
.filter { gate ->
when (filter) {
Expand All @@ -55,7 +65,13 @@ internal object Common {
GateInfo(
gate = it,
systemId = it.starSystem.id,
systemName = it.starSystem.baseName
systemName = it.starSystem.baseName,
sourceMod = when {
it.tags.contains(Tags.TAG_ACTIVE_GATES_GATE) -> GateMod.ActiveGates
it.tags.contains(Tags.TAG_BOGGLED_GATE) -> GateMod.BoggledPlayerGateConstruction
it.tags.contains(Tags.TAG_GATE_ACTIVATED) -> GateMod.GatesAwakened
else -> GateMod.Unknown
}
)
}
.filter {
Expand Down Expand Up @@ -127,7 +143,8 @@ internal object Common {
internal data class GateInfo(
val gate: Gate,
val systemId: String,
val systemName: String
val systemName: String,
val sourceMod: GateMod
)

internal enum class GateFilter {
Expand All @@ -138,6 +155,13 @@ internal enum class GateFilter {
IntroFringe
}

enum class GateMod {
GatesAwakened,
ActiveGates,
BoggledPlayerGateConstruction,
Unknown
}

val Any?.exhaustiveWhen: Unit?
get() = this?.run { }

Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/org/wisp/gatesawakened/Extensions.kt
Expand Up @@ -18,7 +18,11 @@ internal val SectorEntityToken.isGate: Boolean
get() = com.fs.starfarer.api.impl.campaign.ids.Tags.GATE in this.tags

internal val Gate.isActive: Boolean
get() = Tags.TAG_GATE_ACTIVATED in this.tags || Tags.TAG_ACTIVE_GATES_GATE_ACTIVATED in this.tags
get() = this.tags.any { tag ->
tag == Tags.TAG_GATE_ACTIVATED
|| tag == Tags.TAG_ACTIVE_GATES_GATE
|| tag == Tags.TAG_BOGGLED_GATE
}

/**
* Gates that are active from other mods (Active Gates) cannot be deactivated by Gates Awakened.
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/org/wisp/gatesawakened/constants/Tags.kt
Expand Up @@ -12,7 +12,10 @@ internal object Tags {
const val TAG_GATE_ACTIVATED = "${MOD_PREFIX}_gate_activated"

/** The tag used by the Active Gates mod, added so those gates may be used as well **/
const val TAG_ACTIVE_GATES_GATE_ACTIVATED = "gate_activated"
const val TAG_ACTIVE_GATES_GATE = "gate_activated"

/** The tag used by Boggled's Player Constructed Gates mod, added so those gates may be used as well **/
const val TAG_BOGGLED_GATE = "boggled_astral_gate"

/** Displays as a tag in the Intel Manager screen */
const val INTEL_ACTIVE_GATE = "Gates"
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/org/wisp/gatesawakened/jumping/Jump.kt
Expand Up @@ -11,7 +11,11 @@ internal object Jump {
/**
* @return whether jump was successful
*/
fun jumpPlayer(sourceLocation: SectorEntityToken?, destinationGate: Gate, isFuelRequired: Boolean = true): JumpResult {
fun jumpPlayer(
sourceLocation: SectorEntityToken?,
destinationGate: Gate,
isFuelRequired: Boolean = true
): JumpResult {
val playerFleet = di.sector.playerFleet

// Pay fuel cost (or show error if player lacks fuel)
Expand All @@ -32,7 +36,11 @@ internal object Jump {
}

// Jump player fleet to new system
di.sector.doHyperspaceTransition(di.sector.playerFleet, sourceLocation, JumpPointAPI.JumpDestination(destinationGate, null))
di.sector.doHyperspaceTransition(
di.sector.playerFleet,
sourceLocation,
JumpPointAPI.JumpDestination(destinationGate, null)
)
return JumpResult.Success
}

Expand Down
55 changes: 37 additions & 18 deletions src/main/kotlin/org/wisp/gatesawakened/jumping/JumpDialog.kt
@@ -1,4 +1,6 @@
package com.fs.starfarer.api.impl.campaign.rulecmd // Must use this package because this plugin is called by rules.csv
package com.fs.starfarer.api.impl.campaign.rulecmd

// Must use this package because this plugin is called by rules.csv


import ch.tutteli.kbox.joinToString
Expand All @@ -9,13 +11,11 @@ import com.fs.starfarer.api.campaign.TextPanelAPI
import com.fs.starfarer.api.impl.campaign.abilities.TransponderAbility
import com.fs.starfarer.api.impl.campaign.ids.Abilities
import com.fs.starfarer.api.impl.campaign.ids.Factions
import com.fs.starfarer.api.impl.campaign.rulecmd.PaginatedOptions
import com.fs.starfarer.api.loading.Description
import com.fs.starfarer.api.util.Misc
import org.lwjgl.input.Keyboard
import org.wisp.gatesawakened.*
import org.wisp.gatesawakened.constants.MOD_PREFIX
import org.wisp.gatesawakened.constants.Tags
import org.wisp.gatesawakened.jumping.Jump
import org.wisp.gatesawakened.midgame.Midgame
import org.wisp.gatesawakened.wispLib.addPara
Expand Down Expand Up @@ -56,7 +56,8 @@ class JumpDialog : PaginatedOptions() {
}

override fun optionSelected(optionText: String?, optionData: Any?) {
val activatedGates = Common.getGates(GateFilter.Active, excludeCurrentGate = true)
val activatedGates =
Common.getGates(GateFilter.Active, excludeCurrentGate = true, includeGatesFromOtherMods = true)

if (optionData in Option.values().map { it.id }) {
// If player chose a normal dialog option (not jump)
Expand Down Expand Up @@ -109,8 +110,14 @@ class JumpDialog : PaginatedOptions() {
activatedGates.forEach { activatedGate ->
val jumpCostInFuel = Common.jumpCostInFuel(activatedGate.gate.distanceFromPlayerInHyperspace)
val fuelRemainingAfterJump = di.sector.playerFleet.cargo.fuel - jumpCostInFuel

val gateModText = when (activatedGate.sourceMod) {
GateMod.BoggledPlayerGateConstruction -> " (warning: unrecognized Gate protocol)"
else -> String.empty
}

var jumpText =
"Jump to ${activatedGate.systemName} ($jumpCostInFuel fuel)"
"Jump to ${activatedGate.systemName} ($jumpCostInFuel fuel)$gateModText"

if (fuelRemainingAfterJump < 0) {
jumpText += " (${fuelRemainingAfterJump.absoluteValue} more required)"
Expand Down Expand Up @@ -317,20 +324,32 @@ class JumpDialog : PaginatedOptions() {
}

// Jump player fleet to new system
val gates = newSystem.getEntitiesWithTag(Tags.TAG_GATE_ACTIVATED)

return when (val result = Jump.jumpPlayer(
sourceLocation = dialog.interactionTarget,
destinationGate = gates.first()
)) {
is Jump.JumpResult.Success -> {
text.addPara { "Your fleet passes through the gate..." }
true
}
is Jump.JumpResult.FuelRequired -> {
text.addPara { "You lack the " + mark(result.fuelCost) + " fuel necessary to use the gate." }
false
val gates = Common.getGates(
filter = GateFilter.Active,
excludeCurrentGate = false,
includeGatesFromOtherMods = true
)
.filter { it.systemId == newSystem.id }
.map { it.gate }

try {
return when (val result = Jump.jumpPlayer(
sourceLocation = dialog.interactionTarget,
destinationGate = gates.first()
)) {
is Jump.JumpResult.Success -> {
text.addPara { "Your fleet passes through the gate..." }
true
}
is Jump.JumpResult.FuelRequired -> {
text.addPara { "You lack the " + mark(result.fuelCost) + " fuel necessary to use the gate." }
false
}
}
} catch (e: Exception) {
// Can happen if can't find a valid gate in the system to jump to
di.errorReporter.reportCrash(e)
return false
}
}

Expand Down

0 comments on commit 9e175e8

Please sign in to comment.