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

Seeking AI behaviour #18

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3d72012
Skeleton
EtienneDesticourt Aug 8, 2016
e9913c3
Seek logic rework, removed channel callback
EtienneDesticourt Aug 9, 2016
59fa130
Fixed seek logic and added tests, fixed movement update, added ref to…
EtienneDesticourt Aug 10, 2016
3792cbd
Minor rename for clarity
EtienneDesticourt Aug 10, 2016
1fd1a23
Modified Seek to listen for :entity_change on Position
EtienneDesticourt Aug 10, 2016
239f2cc
:pos -> :coord
EtienneDesticourt Aug 10, 2016
165397c
Modified way AI behaviours are chosen for an npc
EtienneDesticourt Aug 10, 2016
f382506
Removed added whitespace
EtienneDesticourt Aug 10, 2016
e9c9693
Merge remote-tracking branch 'refs/remotes/origin/master' into AI_Pro…
EtienneDesticourt Aug 10, 2016
6fdee5b
:pos -> :coord
EtienneDesticourt Aug 10, 2016
f15a24f
Whitespace removal
EtienneDesticourt Aug 11, 2016
b2a2252
Added auto pos update skeleton
EtienneDesticourt Aug 11, 2016
12af7b6
Cleaned up seeking handler, fixed movement update handler
EtienneDesticourt Aug 15, 2016
260666f
Removed excess linebreak
EtienneDesticourt Aug 15, 2016
f718ddf
Naming changes
EtienneDesticourt Aug 16, 2016
38b65ca
Updated deps
EtienneDesticourt Oct 10, 2016
f819c1d
Put better default aggro/escape dist
EtienneDesticourt Oct 10, 2016
f7ab019
Set seeking as default npc behaviour, started auto updates at behavio…
EtienneDesticourt Oct 10, 2016
0c18581
Fixed tests
EtienneDesticourt Oct 10, 2016
d93eeb8
Changed event from map to atom, fixed seeks option
EtienneDesticourt Oct 11, 2016
e6dc0a6
Added geom deps, replaced Coord with Vector2D, added NavMesh to maps
EtienneDesticourt Oct 14, 2016
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
Prev Previous commit
Next Next commit
Set seeking as default npc behaviour, started auto updates at behavio…
…ur initialization
  • Loading branch information
EtienneDesticourt committed Oct 10, 2016
commit f7ab01942514720b45b11bd3fb7f0ddbb9bb513f
2 changes: 1 addition & 1 deletion lib/entice/logic/map_instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Entice.Logic.MapInstance do
def handle_event(
{:map_instance_npc_add, %{name: name, model: model, position: position}},
%Entity{attributes: %{MapInstance => %MapInstance{map: map}}} = entity) do
{:ok, eid, _pid} = Npc.spawn(name, model, position)
{:ok, eid, _pid} = Npc.spawn(name, model, position, [:seeks])
Coordination.register(eid, map) # TODO change map to something else if we have multiple instances
{:ok, entity}
end
Expand Down
9 changes: 8 additions & 1 deletion lib/entice/logic/movement.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Entice.Logic.Movement do
def register(entity),
do: Entity.put_behaviour(entity, Movement.Behaviour, [])

def register(entity, %{auto_updating?: auto_updating?}),
do: Entity.put_behaviour(entity, Movement.Behaviour, %{auto_updating?: auto_updating?})

def unregister(entity),
do: Entity.remove_behaviour(entity, Movement.Behaviour)
Expand All @@ -42,6 +44,11 @@ defmodule Entice.Logic.Movement do
def init(%Entity{attributes: %{Movement => _}} = entity, _args),
do: {:ok, entity}

def init(%Entity{attributes: %{Position => %Position{coord: coord, plane: plane}}} = entity, %{auto_updating?: true}) do
self |> Process.send_after({:movement_calculate_next}, 1)
{:ok, entity |> put_attribute(%Movement{goal: coord, plane: plane, auto_updating?: true})}
end

def init(%Entity{attributes: %{Position => %Position{coord: coord, plane: plane}}} = entity, _args),
do: {:ok, entity |> put_attribute(%Movement{goal: coord, plane: plane})}

Expand All @@ -51,7 +58,7 @@ defmodule Entice.Logic.Movement do
def handle_event({:movement_calculate_next},
%Entity{attributes: %{Movement => %Movement{auto_updating?: auto_updating?}}} = entity) do
#TODO: implement once the whole collision business is handled
if auto_updating?, do: self |> Process.send_after(:movement_calculate_next, Movement.update_interval)
if auto_updating?, do: self |> Process.send_after({:movement_calculate_next}, Movement.update_interval)
{:ok, entity}
end

Expand Down
8 changes: 6 additions & 2 deletions lib/entice/logic/npc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ defmodule Entice.Logic.Npc do
{:ok, id, pid} = Entity.start()
Npc.register(id, name, model, position)
Vitals.register(id)
Movement.register(id)
if opts[:seeks] || true, do: Seek.register(id)
if opts[:seeks] || true do
Seek.register(id)
Movement.register(id, %{auto_updating?: true})
else
Movement.register(id)
end
{:ok, id, pid}
end

Expand Down