-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reduced ShipwreckDistanceFromIsland to 0.4 * Added position to effect * Added sail shipwreck and all ships queries * Added SailShip system * Fixed bug with no moving ship * Linter fixes
- Loading branch information
Showing
13 changed files
with
275 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package msg | ||
|
||
type SailShipwreckMsg struct { | ||
Player string `json:"player"` | ||
} | ||
|
||
type SailShipWreckResult struct { | ||
Success bool `json:"success"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package query | ||
|
||
import ( | ||
comp "oceanus-shard/component" | ||
"oceanus-shard/system" | ||
|
||
"pkg.world.dev/world-engine/cardinal" | ||
"pkg.world.dev/world-engine/cardinal/search/filter" | ||
) | ||
|
||
type AllShipsRequest struct{} | ||
|
||
// AllShips - | ||
func AllShips(world cardinal.WorldContext, _ *AllShipsRequest) (*map[string]comp.Effect, error) { | ||
_, effects, err := system.QueryAllComponents[comp.Effect]( | ||
world, | ||
filter.Component[comp.Player](), | ||
filter.Component[comp.Building](), | ||
filter.Component[comp.Effect](), | ||
) | ||
|
||
shipsMap := make(map[string]comp.Effect) | ||
for _, effect := range effects { | ||
if effect.Amount > 0 { | ||
shipsMap[effect.ID] = *effect | ||
} | ||
} | ||
|
||
return &shipsMap, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package system | ||
|
||
import ( | ||
"math" | ||
"time" | ||
|
||
"pkg.world.dev/world-engine/cardinal" | ||
"pkg.world.dev/world-engine/cardinal/search/filter" | ||
"pkg.world.dev/world-engine/cardinal/types" | ||
|
||
comp "oceanus-shard/component" | ||
"oceanus-shard/constants" | ||
) | ||
|
||
// SailShip - | ||
func SailShip(world cardinal.WorldContext) error { | ||
return cardinal.NewSearch().Entity( | ||
filter.Contains(filter.Component[comp.Building](), filter.Component[comp.Effect]())). | ||
Each(world, func(id types.EntityID) bool { | ||
effectComponent, _ := cardinal.GetComponent[comp.Effect](world, id) | ||
|
||
if effectComponent.Amount == 0 || effectComponent.TargetPosition == nil { | ||
return true | ||
} | ||
|
||
buildingComponent, _ := cardinal.GetComponent[comp.Building](world, id) | ||
raftTravelDistancePerTick := | ||
constants.RaftTravelSpeedPerMinute / time.Minute.Seconds() * constants.TickRate.Seconds() | ||
|
||
buildingComponent.Effect.Position = findPointAtDistance( | ||
buildingComponent.Effect.Position, | ||
*buildingComponent.Effect.TargetPosition, | ||
raftTravelDistancePerTick, | ||
) | ||
|
||
err := updateEffect(world, id, buildingComponent.Effect) | ||
if err != nil { | ||
return true | ||
} | ||
return true | ||
}) | ||
} | ||
|
||
func findPointAtDistance(start, end [2]float64, distance float64) [2]float64 { | ||
x1, y1 := start[0], start[1] | ||
x2, y2 := end[0], end[1] | ||
|
||
dx := x2 - x1 | ||
dy := y2 - y1 | ||
|
||
length := math.Sqrt(dx*dx + dy*dy) | ||
|
||
if distance > length { | ||
return end | ||
} | ||
|
||
unitDx := dx / length | ||
unitDy := dy / length | ||
|
||
newX := x1 + unitDx*distance | ||
newY := y1 + unitDy*distance | ||
|
||
return [2]float64{newX, newY} | ||
} |
Oops, something went wrong.