Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///@function create_affinity();
- ///@description Creates a new ds_map in global.AFFINITIES which has the instance ID as a key
- /// and contains all other creatures as id-affinity tuples.
- /// Also adds an id-affinity tuple for the main instance in every other creature's affinity ds_map
- var _inst_first = id;
- var _inst_first_affinities = ds_map_create();
- var _inst_second;
- var _inst_second_affinities;
- var _affinity;
- var _devote = global.FRIEND_VALUE[friendship.devote];
- var _friendly = global.FRIEND_VALUE[friendship.friendly];
- var _size;
- //ADD MAIN INSTANCE TO OTHER CREATURES' AFFINITY DS_MAP
- //NOTE: Only runs through creatures which already have an entry in global.AFFINITIES
- _inst_second = ds_map_find_first(global.AFFINITIES);
- _size = ds_map_size(global.AFFINITIES);
- for (var i = 0; i < _size; i++){
- if (_inst_second != _inst_first) {
- _inst_second_affinities = ds_map_find_value(global.AFFINITIES,_inst_second);
- _max_affinity = (_inst_second.groupID != noone) ? _friendly : _devote;
- _affinity = (_inst_first.trueNeutral) ? _devote/2 : irandom_range(0, _max_affinity);
- ds_map_replace(_inst_second_affinities, _inst_first, _affinity);
- ds_map_replace(global.AFFINITIES, _inst_second, _inst_second_affinities);
- }
- _inst_second = ds_map_find_next(global.AFFINITIES, _inst_second);
- }
- //CREATE CREATURE'S AFFINITIES DS_MAP
- with (obj_creature) {
- _inst_second = id;
- if (_inst_second != _inst_first) {
- //ADD OTHER CREATURES TO MAIN INSTANCE'S AFFINITY
- _max_affinity = (_inst_first.groupID != noone) ? _friendly : _devote;
- _affinity = (_inst_first.trueNeutral) ? _devote/2 : irandom_range(0, _max_affinity);
- ds_map_replace(_inst_first_affinities,_inst_second,_affinity);
- if (_affinity > _friendly) _inst_first.groupID = 1;
- }
- }
- ds_map_add_map(global.AFFINITIES, _inst_first, _inst_first_affinities);
- ds_map_destroy(_inst_first_affinities);
- _inst_first_affinities = -1;
- if (_size > 1) {
- ds_map_destroy(_inst_second_affinities);
- _inst_second_affinities = -1;
- }
- _inst_first.groupID = noone;
Advertisement
Add Comment
Please, Sign In to add comment