Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: typesave sensor mappings #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/refuel_turret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import "github.com/Vilsol/go-mlog/m"

//Requires a unit to be flagged
func main() {
flag := 2
unitType := m.UMono
const turretName = "duo1"
ammoType := m.ITCopper
m.UnitBind(unitType)
if m.CurUnit.GetFlag() != flag {
return
}
item := m.CurUnit.GetFirstItem()
if item != ammoType { //go to core and pick up
coreX, coreY, _, core := m.UnitLocateBuilding(m.BCore, false)
m.UnitApproach(coreX, coreY, m.CurUnit.GetRange()-1)
unitCapacity := m.CurUnit.GetTotalItems()
m.UnitItemDrop(core, unitCapacity) //drop non-ammo item
m.UnitItemTake(core, ammoType, unitCapacity) //take ammo item
} else { // go to turret and refuel
turret := m.GetTurret(turretName)
m.UnitApproach(turret.GetX(), turret.GetY(), m.CurUnit.GetRange()-1)
m.UnitItemDrop(turret, m.CurUnit.GetTotalItems())
}
}
nbrugger-tgm marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3k
github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=
github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k=
github.com/MarvinJWendt/testza v0.2.12/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI=
github.com/MarvinJWendt/testza v0.2.14 h1:xSuCRRRlNNCHOONg0iUEb6hkx8fYNWPSbV2w1LIgvtA=
github.com/MarvinJWendt/testza v0.2.14/go.mod h1:JOIegYyV7rX+7VZ9r77L/eH6CfJHHzXjB69adAhzZkI=
github.com/MarvinJWendt/testza v0.2.15 h1:suR1fQ/folIjEJw4GTbIBahhmZ16zatr9JghbSU+LV0=
github.com/MarvinJWendt/testza v0.2.15/go.mod h1:eFcL4I0idjtIx8P9C6KkAuLgATNKpX4/2oUqKc6bF2c=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down Expand Up @@ -256,7 +254,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.10 h1:fv5GKR+e2UgD+gcxQECVT5rBwAmlFLl2mkKm7WK3ODY=
github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
Expand Down Expand Up @@ -336,7 +333,6 @@ github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eF
github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg=
github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE=
github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU=
github.com/pterm/pterm v0.12.33 h1:XiT50Pvdqn5O8FAiIqZMpXP6NkVEcmlUa+mkA1yWVCg=
github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE=
github.com/pterm/pterm v0.12.36 h1:Ui5zZj7xA8lXR0CxWXlKGCQMW1cZVUMOS8jEXs6ur/g=
github.com/pterm/pterm v0.12.36/go.mod h1:NjiL09hFhT/vWjQHSj1athJpx6H8cjpHXNAK5bUw8T8=
Expand Down
164 changes: 164 additions & 0 deletions m/archetypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
package m

type Turret interface {
Building
HasAmmo
HasInventory
HasRange
HasLiquid
HasPower
Controllable
// GetRotation the rotation at a scale of 0f..360f. 0 and 360 deg is when the turret looks at the very right side
GetRotation() int
// GetShootX the x cord of the targeted tile
GetShootX() int
// GetShootY the y cord of the targeted tile
GetShootY() int
// GetShootPosition the position of the targeted tile
GetShootPosition() HasPosition
}

type Building interface {
HasPosition
HasHealth
Teamed
GameElement
// GetType the type of the block (e.g. "cyclone" "microprocessor") not compatible with BlockFlag
GetType() string
IsEnabled() bool
}
type Unit interface {
HasPosition
HasHealth
HasRange
Controllable
Teamed
GameElement
HasInventory
GetType() UnitType
// IsDead true if unit is not alive or invalid. PS: Why anuken why "dead" and not alive?
IsDead() bool
IsBoosting() bool
GetFlag() int
}
type MiningUnit interface {
Unit
CanMine
}
type CarrierUnit interface {
HasPayload
Unit
}
type UnspecifiedBuilding interface {
Building
HasPower
HasAmmo
HasInventory
HasLiquid
HasConfig
}
type GameElement interface{}

type HasHealth interface {
// GetHealth Get the current health value of Unit or Building
GetHealth() int
GetMaxHealth() int
}
type HasInventory interface {
// GetTotalItems items in inventory
GetTotalItems() int
// GetFirstItem Type of the first item in the inventory
GetFirstItem() ItemType
// GetItemCapacity The maximum amount of items this unit/block can hold
GetItemCapacity() int
}
type HasLiquid interface {
// GetTotalLiquids liquids in internal storage
GetTotalLiquids() int
// GetLiquidCapacity The maximum amount of liquid this unit/block can hold
GetLiquidCapacity() int
}
type Shootable interface {
HasHealth
HasPosition
}
type HasPower interface {
// GetTotalPower In case of unbuffered consumers, this is the percentage (1.0f = 100%) of the demanded power which can be supplied.
// Blocks will work at a reduced efficiency if this is not equal to 1.0f.
// In case of buffered consumers, this is storage capacity.
GetTotalPower() int
// GetPowerCapacity The maximum amount of power this unit/block can hold
// In case of unbuffered consumers, this is the 0
GetPowerCapacity() int
// GetPowerNetStored power stored in the connected power network
GetPowerNetStored() int64
// GetPowerNetCapacity power the connected power network is able to store
GetPowerNetCapacity() int64
// GetPowerNetIn power the connected power network produces
GetPowerNetIn() int64
// GetPowerNetOut power the connected power network consumes
GetPowerNetOut() int64
}
type HasAmmo interface {
// GetAmmo The amount of ammo (in shots not units) this unit/turret holds
GetAmmo() int
// GetAmmoCapacity the amount of shots this turret/unit can store
GetAmmoCapacity() int
IsShooting() bool
}
type HasHeat interface {
// GetHeat The heat this building has accumulated (in nuclear reactor for example)
GetHeat()
}
type Productive interface {
// GetEfficiency The effi ciency at which this item produces/consumes, scale of 0..1 efficiencies
//above 100% (1) are not measurable. A Thermal generator with 300% efficiency
//and one with 100% will both return 1
//Note: Only seems to return the "electric efficiency"
GetEfficiency() float64
}

//TODO: sensor timescale -> no idea

type HasPosition interface {
GetX() int
GetY() int
// GetSize the side length of the block measured in tiles
GetSize() int
}

type Controllable interface {
GetControlled() Controller
// GetController name of the thing that commands this thing. "processor" <playerName> or the unit itself
//TODO: dont offer this method or find a more typesave way
GetController() string
}
type Teamed interface {
// GetTeam The team the thing belongs to
GetTeam() int
}
type HasRange interface {
// GetRange To shoot and or detect who knows (TODO: better docs)
GetRange() float64
}
type CanMine interface {
GetMineX() int
GetMineY() int
IsMining() bool
}
type HasName interface {
// GetName the exact name of the blockType or unit type. Use GetType preferably
GetName() string
}
type HasConfig interface {
// GetConfig The filtered item
GetConfig() string //mapped to "@configure" not "@config" nobody knows what latter one is
}

// HasPayload TODO needs closer clarification from MLOG side
type HasPayload interface {
// GetPayloadType block or unit type this unit is carrying
GetPayloadType() string
// GetPayloadCount How many things this unit is carrying (not items)
GetPayloadCount() int
}
12 changes: 7 additions & 5 deletions m/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ func PrintFlush(targetMessage string) {
}

// Get the linked tile at the specified address
func GetLink[A integer](address A) Link {
func GetLink[A integer](address A) UnspecifiedBuilding {
return nil
}

// Retrieve a list of units that match specified conditions
//
// Conditions are combined using an `and` operation
func Radar(from Ranged, target1 RadarTarget, target2 RadarTarget, target3 RadarTarget, sortOrder bool, sort RadarSort) Unit {
func Radar(from Building, target1 RadarTarget, target2 RadarTarget, target3 RadarTarget, sortOrder bool, sort RadarSort) Unit {
nbrugger-tgm marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

// Extract information indicated by sense from the provided block
func Sensor(block HealthC, sense string) float64 {
// Extract information indicated by sense from the provided block.
//Use this only if the needed information is not available using The getters of the building itself
//main purpose is to use generic "senses" or use things that are not mapped
func Sensor(block GameElement, sense string) float64 {
return 0
}

// String equivalent of Sensor
func SensorStr(block HealthC, sense string) string {
func SensorStr(block GameElement, sense string) string {
return ""
}
6 changes: 3 additions & 3 deletions m/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ func ControlEnabled(target Building, enabled bool) {
// Shoot with the provided turret at the target absolute position
//
// If shoot parameter is false, it will cease firing
func ControlShoot[A integer, B integer](turret Building, x A, y B, shoot bool) {
func ControlShoot[A integer, B integer](turret HasAmmo, x A, y B, shoot bool) {
}

// Smart version of ControlShoot
//
// Shoot with the provided turret at the predicted position of target unit
//
// If shoot parameter is false, it will cease firing
func ControlShootP(turret Building, target HealthC, shoot bool) {
func ControlShootP(turret HasAmmo, target Shootable, shoot bool) {
}

// Set the configuration of the target building
func ControlConfigure[A integer](target Building, configuration A) {
func ControlConfigure[A integer](target HasConfig, configuration A) {
}
10 changes: 8 additions & 2 deletions m/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package m

// Process provided string as a game constant
//
// Example m.Const("@copper")
// Example m.Const("@copper") (only use this if you cannot use the enums like ItemType or UnitType
// use this if you have dynamic values like m.Const("@"+"fl"+"are") (whyever you want to do this)
func Const(constant string) string {
return ""
}

// Return a building of the provided name
//
// Example m.B("message1")
func B(name string) Building {
func B(name string) UnspecifiedBuilding {
return nil
}

// GetTurret Get a block that is specificaly a turret alias for B with better typing
func GetTurret(name string) Turret {
return nil
}
Loading