summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-06-12 09:57:13 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2019-06-12 09:57:13 +0200
commitdf54ba490259e1eb1e7c8133903417579ec4f400 (patch)
treeb282afb878facd3039185055274ef3f5d0b4b322 /src/shared/struct/map/shr_map_marker.erl
parentd693f287201f3178f9cc36eee15af29694f67263 (diff)
Adds more funs to handle map markers.
Using map markers to handle attacks of opportunity appears to be a bad idea: while it does make their detection very cheap, this leads to having frequent (and rather large) updates to the markers.
Diffstat (limited to 'src/shared/struct/map/shr_map_marker.erl')
-rw-r--r--src/shared/struct/map/shr_map_marker.erl93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/shared/struct/map/shr_map_marker.erl b/src/shared/struct/map/shr_map_marker.erl
index 84cad36..dac2f5e 100644
--- a/src/shared/struct/map/shr_map_marker.erl
+++ b/src/shared/struct/map/shr_map_marker.erl
@@ -82,6 +82,18 @@
-export
(
[
+ set_locations/2,
+ add_locations/2,
+ remove_locations/2,
+ ataxia_set_locations/2,
+ ataxia_add_locations/2,
+ ataxia_remove_locations/2
+ ]
+).
+
+-export
+(
+ [
decode/1,
encode/1
]
@@ -121,6 +133,9 @@ decode_data (Map) ->
#spawn_mrk{}
end.
+-spec get_locations_field () -> non_neg_integer().
+get_locations_field () -> #marker.locations.
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -190,3 +205,81 @@ get_character_index (Marker) ->
#matk_mrk{ character_ix = IX } -> IX;
_ -> -1
end.
+
+-spec set_locations (list(shr_location:type()), type()) -> type().
+set_locations (Locations, Marker) -> Marker#marker{ locations = Locations }.
+
+-spec ataxia_set_locations
+ (
+ list(shr_location:type()),
+ type()
+ )
+ -> {type(), ataxic:basic()}.
+ataxia_set_locations (Locations, Marker) ->
+ {
+ set_locations(Locations, Marker),
+ ataxic:update_field
+ (
+ get_locations_field(),
+ ataxic:constant([Locations])
+ )
+ }.
+
+-spec add_locations (list(shr_location:type()), type()) -> type().
+add_locations (Locations, Marker) ->
+ Marker#marker{ locations = (Locations ++ Marker#marker.locations) }.
+
+-spec ataxia_add_locations
+ (
+ list(shr_location:type()),
+ type()
+ )
+ -> {type(), ataxic:basic()}.
+ataxia_add_locations (Locations, Marker) ->
+ {
+ add_locations(Locations, Marker),
+ ataxic:update_field
+ (
+ get_locations_field(),
+ ataxic:apply_function
+ (
+ lists,
+ append,
+ [
+ ataxic:constant([Locations]),
+ ataxic:current_value()
+ ]
+ )
+ )
+ }.
+
+-spec remove_locations (list(shr_location:type()), type()) -> type().
+remove_locations (Locations, Marker) ->
+ Marker#marker
+ {
+ locations = lists:subtract(Marker#marker.locations, Locations)
+ }.
+
+-spec ataxia_remove_locations
+ (
+ list(shr_location:type()),
+ type()
+ )
+ -> {type(), ataxic:basic()}.
+ataxia_remove_locations (Locations, Marker) ->
+ {
+ remove_locations(Locations, Marker),
+ ataxic:update_field
+ (
+ get_locations_field(),
+ ataxic:apply_function
+ (
+ lists,
+ subtract,
+ [
+ ataxic:current_value(),
+ ataxic:constant([Locations])
+ ]
+ )
+ )
+ }.