Skip to content

Commit 0d9634f

Browse files
Merge pull request #37 from openbase/feature/4-agents-should-see-the-energy-level-and-action-points-of-on-adversary-agent
Feature/4 agents should see some global states of the last seen adversary agent
2 parents 85eebdf + 6a234eb commit 0d9634f

File tree

8 files changed

+325
-241
lines changed

8 files changed

+325
-241
lines changed

src/main/kotlin/org/openbase/planetsudo/game/GameSound.kt

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ enum class GameSound(uri: String) {
7777
return
7878
}
7979

80+
println("Play sound: ${this.name}")
8081
AUDIO_SERVER.playAudio(audioData)
8182
soundHistory[this] = Instant.now()
8283
}

src/main/kotlin/org/openbase/planetsudo/game/strategy/AbstractStrategy.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import org.openbase.planetsudo.game.GameManager
88
import org.openbase.planetsudo.game.SwatTeam
99
import org.openbase.planetsudo.game.SwatTeam.*
1010
import org.openbase.planetsudo.level.AbstractLevel
11-
import org.openbase.planetsudo.level.levelobjects.Agent
12-
import org.openbase.planetsudo.level.levelobjects.AgentInterface
13-
import org.openbase.planetsudo.level.levelobjects.Mothership
14-
import org.openbase.planetsudo.level.levelobjects.MothershipInterface
11+
import org.openbase.planetsudo.level.levelobjects.*
1512
import org.slf4j.Logger
1613
import org.slf4j.LoggerFactory
1714
import java.beans.PropertyChangeEvent
@@ -26,6 +23,7 @@ abstract class AbstractStrategy(val agent: AgentInterface) : Runnable {
2623

2724
private val strategyOwner: Agent by lazy { agent as Agent }
2825
val mothership: MothershipInterface by lazy { strategyOwner.mothership }
26+
val adversaryAgent: GlobalAgentInterface get() = agent.adversaryAgent
2927
val mothershipInternal: Mothership by lazy { strategyOwner.mothership }
3028
private val rules: TreeMap<Int, Rule> = TreeMap()
3129
private val gameManager: GameManager = GameManager.gameManager

src/main/kotlin/org/openbase/planetsudo/game/strategy/DivineStrategy.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class DivineStrategy(agent: AgentInterface) : AbstractStrategy(agent) {
281281
createRule(
282282
object : Rule("Shift for Extra Resource") {
283283
override fun constraint(): Boolean {
284-
return agent.isCarryingResource(ResourceType.ExtremPoint) && agent.hasTonic() && !agent.isShifting && !agent.isAtMothership
284+
return agent.isCarryingResource(ResourceType.ExtremPoint) && agent.hasTonic && !agent.isShifting && !agent.isAtMothership
285285
}
286286

287287
override fun action() {

src/main/kotlin/org/openbase/planetsudo/level/levelobjects/Agent.kt

+22-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Agent(
5454
private var helpLevelObjectOld: AbstractLevelObject? = null
5555
private var adversaryObject: AbstractLevelObject? = null
5656
private var catchedfuel = 0
57+
private var lastAversaryAgent: Agent? = null
5758

5859
val mothership: Mothership
5960
val team: Team
@@ -179,7 +180,9 @@ class Agent(
179180
get() = level.getTouchableResource(this) != null
180181

181182
override val seeAdversaryAgent: Boolean
182-
get() = level.getAdversaryAgent(this) != null
183+
get() = level.getAdversaryAgent(this)
184+
.also { lastAversaryAgent = it }
185+
.let { it != null }
183186

184187
override val seeTeamAgent: Boolean
185188
get() = level.getTeamAgent(this) != null
@@ -482,6 +485,16 @@ class Agent(
482485
}
483486
}
484487

488+
override fun turnToAdversaryAgent(beta: Int) {
489+
ap.actionPoint
490+
if (useFuel()) {
491+
level.getAdversaryAgent(this)?.let { adversaryAgent ->
492+
direction.turnTo(position, adversaryAgent.position)
493+
direction.angle += beta
494+
}
495+
}
496+
}
497+
485498
override fun turnRandom() {
486499
turnRandom(360)
487500
}
@@ -773,21 +786,27 @@ class Agent(
773786

774787
override fun makeInvisible() {
775788
ap.getActionPoint(100)
776-
if (hasTonicForInvisibility()) {
789+
if (hasTonicForInvisibility) {
777790
tonic = 0
778791
invisible = true
779792
}
780793
}
781794

782795
override fun shift() {
783796
ap.actionPoint
784-
if (hasTonic()) {
797+
if (hasTonic) {
785798
tonic--
786799
shiftTonic++
787800
GameSound.Shift.play()
788801
}
789802
}
790803

804+
override val adversaryAgent: GlobalAgentInterface
805+
get() = GlobalAgentProxy(
806+
lastAversaryAgent
807+
?: error("No adversary agent seen!"),
808+
)
809+
791810
companion object {
792811
const val MAX_TONIC: Int = 3
793812
const val AGENT_SIZE: Int = 50

0 commit comments

Comments
 (0)