Hello all, been a while since I worked on this MOD of mine, but I figure I may as well work on it some more. I guess the game will have died long before I finish it, but what ever, it passes the time.
any way here is my problem. I am trying to create an array of all the villages sorted by distance from the party I am talking to. the idea being I meet one of my caravans I have on the map, and tell them to go do something. hire troops, buy food, sell loot, etc. any way what I want is to make this list and sort it by distance from the party I am talking to.
I am using sphere's dynamic arrays to do this. but for some reason the list does not seem to get created correctly. I am sure it is an easy fix I am over looking due to my long time away from this, but any help would be nice.
any way here is my problem. I am trying to create an array of all the villages sorted by distance from the party I am talking to. the idea being I meet one of my caravans I have on the map, and tell them to go do something. hire troops, buy food, sell loot, etc. any way what I want is to make this list and sort it by distance from the party I am talking to.
I am using sphere's dynamic arrays to do this. but for some reason the list does not seem to get created correctly. I am sure it is an easy fix I am over looking due to my long time away from this, but any help would be nice.
Code:
(call_script, "script_array_create"),
(assign, ":Array_Village_List", reg0),
(call_script, "script_array_create"),
(assign, ":Array_Village_Distance", reg0),
(assign, ":Array_Write",0),
# this will give us a ":Distance" sorted list of villiages from our current position.
(assign, ":Village_List_Index", 0),
(try_for_range, ":Village_ID", villages_begin, villages_end),
(store_distance_to_party_from_party, ":Distance", ":Village_ID", "$g_encountered_party"),
(call_script,"script_array_get_size", ":Array_Village_List"),
(assign, ":List_Size", reg0),
(try_for_range, ":Village_List_Index", 0, ":List_Size"),
(call_script, "script_array_get_element", ":Array_Village_Distance", ":Village_List_Index", 0),
(assign, ":Current_Array_Distance", reg0),
(try_begin),
(lt, ":Distance", ":Current_Array_Distance"),
(call_script, "script_array_insert", ":Array_Village_List", ":Village_List_Index", ":Village_ID"),
(call_script, "script_array_insert", ":Array_Village_Distance", ":Village_List_Index", ":Distance"),
(assign, ":Array_Written",1), #set flag for data written
(try_end),
(try_end),
#if we have reached the end of the list and not inserted the values append them to the end.
(try_begin),
(eq, ":Array_Written",0), #If the value has not been written to the array
(call_script, "script_array_pushback", ":Array_Village_List", ":Village_ID"),
(call_script, "script_array_pushback", ":Array_Village_Distance", ":Distance"),
(try_end),
(try_end),