egs_zones: Iterate through the set file to later create objects.
This commit is contained in:
parent
11a03f3a96
commit
bf7fa44897
@ -24,7 +24,8 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). %% gen_server.
|
||||
|
||||
-record(state, {
|
||||
setid = 0 :: integer()
|
||||
setid = 0 :: integer(),
|
||||
objects = [] :: list()
|
||||
}).
|
||||
|
||||
%% API.
|
||||
@ -45,6 +46,7 @@ setid(Pid) ->
|
||||
init([UniID, QuestID, ZoneID, ZoneData]) ->
|
||||
SetID = rand_setid(proplists:get_value(sets, ZoneData, [100])),
|
||||
Set = egs_quests_db:set(QuestID, ZoneID, SetID),
|
||||
Objects = create_units(Set),
|
||||
{ok, #state{setid=SetID}}.
|
||||
|
||||
handle_call(setid, _From, State) ->
|
||||
@ -78,3 +80,34 @@ rand_setid(N, [Set|_Tail], I) when N < Set ->
|
||||
I;
|
||||
rand_setid(N, [Set|Tail], I) ->
|
||||
rand_setid(N - Set, Tail, I + 1).
|
||||
|
||||
%% @doc Create the objects for all units in a set.
|
||||
create_units(Set) ->
|
||||
create_units(Set, 0, []).
|
||||
create_units([], _MapNb, Acc) ->
|
||||
lists:flatten(lists:reverse(Acc));
|
||||
create_units([{{map, _MapID}, Groups}|Tail], MapNb, Acc) ->
|
||||
MapObjects = create_groups(Groups, MapNb),
|
||||
create_units(Tail, MapNb + 1, [MapObjects|Acc]).
|
||||
|
||||
%% @doc Create the objects for all groups in a unit.
|
||||
create_groups(Groups, MapNb) ->
|
||||
create_groups(Groups, MapNb, 0, []).
|
||||
create_groups([], _MapNb, _GroupNb, Acc) ->
|
||||
lists:flatten(lists:reverse(Acc));
|
||||
create_groups([Objects|Tail], MapNb, GroupNb, Acc) ->
|
||||
GroupObjects = create_objects(Objects, MapNb, GroupNb),
|
||||
create_groups(Tail, MapNb, GroupNb + 1, [GroupObjects|Acc]).
|
||||
|
||||
%% @doc Create the given objects.
|
||||
create_objects(Objects, MapNb, GroupNb) ->
|
||||
create_objects(Objects, MapNb, GroupNb, 0, []).
|
||||
create_objects([], _MapNb, _GroupNb, _ObjectNb, Acc) ->
|
||||
lists:reverse(Acc);
|
||||
create_objects([{ObjType, ObjPos, ObjRot, ObjParams}|Tail], MapNb, GroupNb, ObjectNb, Acc) ->
|
||||
Object = create_object(ObjType, ObjPos, ObjRot, ObjParams),
|
||||
create_objects(Tail, MapNb, GroupNb, ObjectNb + 1, [{{MapNb, GroupNb, ObjectNb}, Object}|Acc]).
|
||||
|
||||
%% @doc Create the given object.
|
||||
create_object(ObjType, ObjPos, ObjRot, ObjParams) ->
|
||||
{undefined, ObjType}.
|
||||
|
Loading…
Reference in New Issue
Block a user