preload button hover image:
Current Time: May 26, 2020, 11:49:34 am
 Mount&Blade Repository » Mod Source Files » Lav's AgentFinder OSP script library
Registration is not required to download. However, it will allow you to vote, comment, and request upload access. Forgot your password?
View this file on the M&B NexusFile Listing: Lav's AgentFinder OSP script library
Last Updated: Aug 13, 2011, 07:51:06 am
First Created: Jul 30, 2011, 05:39:01 am
File version: 2.00
For M&B version: Warband 1.143
Downloads: 291 (320) Size: 304.4 KB
Views: 3,051 (3,200) Type: RAR
Home:  Forum Thread
Rating (0 votes): Unrated
AgentFinder script is a ModuleSystem-based code library to efficiently search for agents on the field matching various search criteria, including distance. This may be useful for developers who want efficient agent processing but refrain from using Warband Script Enhancer.

Code is extensively documented so shouldn't be a problem to use. Besides, it includes a number of debugging scripts which can be used as usage examples (or deleted if you no longer need them). Also, see the forum thread for more detailed explanations.

Update History.
Version 2.0 (major change) wrote:
Converted the data storage model from arrays to lists. Now there's absolutely no limit to the number of agents tracked by a single cell, no matter the grid size.
Version 1.01 (bugfix) wrote:
Fixed a bug where dead agents would not be properly removed from processing (thanks to cmpxchg8b).
Version 1 Description wrote:
This is a script library which tracks agents on the mission map, allowing you to do the following:

1. Search effectively for all agents within specified radius of any map position, matching custom filter criteria. This is obviously less effective than WSE, but considerably more effective than direct iteration through all agents on the scene.
2. Library splits the map into a grid of smaller cells, each containing a number of agents. Library allows you to access both individual cells and rectangular sets of cells, extracting lists of agents present in those cells, filter those lists with custom filter criteria, counting number of agents matching criteria (when you don't need the list), or extracting an "agent presence" matrix for a cell range, containing the number of agents matching your filter in each cell.

Code usage examples:

(call_script, "script_agent_get_agents_near_self", <agent_no>, <slot_id_to_store_resulting_list>, <radius>, <filter_criteria>),
(call_script, "script_agent_get_agents_near_position", <agent_no>, <slot_id_to_store_resulting_list>, <position>, <radius>, <filter_criteria>),
These two are top-level functions, fully abstracting the internal workings of the library (grid and cell structure of the map etc). You just call them and voila - in the slots of the <agent_no>, starting from the <slot_id>, there's a list of agents who are located in the requested region and match the filter criteria (with list size stored in reg0).

(call_script, "script_agent_filter_agents_list", <agent_no>, <slot_id_where_list_starts>, <list_length>, <filter_criteria>),
(call_script, "script_agent_filter_agents_list_by_circle", <agent_no>, <slot_id_where_list_starts>, <list_length>, <position>, <radius>),
Once you have a list of agents, you can further filter it either by filter criteria, or by physical location.

(call_script, "script_agent_get_agents_in_cell", <agent_no>, <slot_id_to_store_resulting_list>, <cell_x>, <cell_y>),
(call_script, "script_agent_get_agents_in_cellrange", <agent_no>, <slot_id_to_store_resulting_list>, <topleft_cell_x>, <topleft_cell_y>, <bottomright_cell_x>, <bottomright_cell_y>),
These functions allow you to get a list of agents in a rectangular area of the map (either a single cell, or a cell range). This list can then be filtered as necessary.

(call_script, "script_agent_count_agents_in_cell", <agent_no>, <cell_x>, <cell_y>, <filter_criteria>),
(call_script, "script_agent_count_agents_in_cellrange", <agent_no>, <topleft_cell_x>, <topleft_cell_y>, <bottomright_cell_x>, <bottomright_cell_y>, <filter_criteria>),
These functions allow you to calculate the number of agents matching the filter in the specified rectangular area of the map.

(call_script, "script_agent_get_agents_presence_matrix", <agent_no>, <slot_id_to_store_matrix>, <topleft_cell_x>, <topleft_cell_y>, <bottomright_cell_x>, <bottomright_cell_y>, <filter_criteria>),
Same as above, but this function not only returns the total number of matching agents in the area, but also records a per-cell matrix of how many agents matching the filter are in each respective cell. This function was written with AI in mind. For example, your agent can easily scan a 5x5 area centered on himself, determining number of enemies and friends in each cell, then proceed to estimating his situation.
More From This Author
IP: logged
 Lav's AgentFinder OSP script librar (v 2.00)  » posted by Belendor on Aug 15, 2011, 02:36:39 am
Very useful. :)

Hosted by Hypernia.
Website © 2020 FenriSoft. The core site script is PHCDownload (© 2005-2020).