SHARE
TWEET

Untitled

a guest Jun 17th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*Current movespeed modification list format: list(id = list(
  3.     priority,
  4.     flags,
  5.     legacy slowdown/speedup amount,
  6.     movetype_flags
  7.     ))
  8. */
  9.  
  10. //ANY ADD/REMOVE DONE IN UPDATE_MOVESPEED MUST HAVE THE UPDATE ARGUMENT SET AS FALSE!
  11. /mob/proc/add_movespeed_modifier(id, update=TRUE, priority=0, flags=NONE, override=FALSE, multiplicative_slowdown=0, movetypes=ALL, blacklisted_movetypes=NONE, conflict=FALSE)
  12.     var/list/temp = list(priority, flags, multiplicative_slowdown, movetypes, blacklisted_movetypes, conflict) //build the modification list
  13.     var/resort = TRUE
  14.     if(LAZYACCESS(movespeed_modification, id))
  15.         var/list/existing_data = movespeed_modification[id]
  16.         if(movespeed_modifier_identical_check(existing_data, temp))
  17.             return FALSE
  18.         if(!override)
  19.             return FALSE
  20.         if(priority == existing_data[MOVESPEED_DATA_INDEX_PRIORITY])
  21.             resort = FALSE // We don't need to re-sort if we're replacing something already there and it's the same priority
  22.     LAZYSET(movespeed_modification, id, temp)
  23.     if(update)
  24.         update_movespeed(resort)
  25.     return TRUE
  26.  
  27. /mob/proc/remove_movespeed_modifier(id, update = TRUE)
  28.     if(!LAZYACCESS(movespeed_modification, id))
  29.         return FALSE
  30.     LAZYREMOVE(movespeed_modification, id)
  31.     UNSETEMPTY(movespeed_modification)
  32.     if(update)
  33.         update_movespeed(FALSE)
  34.     return TRUE
  35.  
  36. /mob/vv_edit_var(var_name, var_value)
  37.     var/slowdown_edit = (var_name == NAMEOF(src, cached_multiplicative_slowdown))
  38.     var/diff
  39.     if(slowdown_edit && isnum(cached_multiplicative_slowdown) && isnum(var_value))
  40.         remove_movespeed_modifier(MOVESPEED_ID_ADMIN_VAREDIT)
  41.         diff = var_value - cached_multiplicative_slowdown
  42.     . = ..()
  43.     if(. && slowdown_edit && isnum(diff))
  44.         add_movespeed_modifier(MOVESPEED_ID_ADMIN_VAREDIT, TRUE, 100, override = TRUE, multiplicative_slowdown = diff)
  45.  
  46. /mob/proc/has_movespeed_modifier(id)
  47.     return LAZYACCESS(movespeed_modification, id)
  48.  
  49. /mob/proc/update_config_movespeed()
  50.     add_movespeed_modifier(MOVESPEED_ID_CONFIG_SPEEDMOD, FALSE, 100, override = TRUE, multiplicative_slowdown = get_config_multiplicative_speed())
  51.  
  52. /mob/proc/get_config_multiplicative_speed()
  53.     if(!islist(GLOB.mob_config_movespeed_type_lookup) || !GLOB.mob_config_movespeed_type_lookup[type])
  54.         return 0
  55.     else
  56.         return GLOB.mob_config_movespeed_type_lookup[type]
  57.  
  58. /mob/proc/update_movespeed(resort = TRUE)
  59.     if(resort)
  60.         sort_movespeed_modlist()
  61.     . = 0
  62.     var/list/conflict_tracker = list()
  63.     for(var/id in get_movespeed_modifiers())
  64.         var/list/data = movespeed_modification[id]
  65.         if(!(data[MOVESPEED_DATA_INDEX_MOVETYPE] & movement_type)) // We don't affect any of these move types, skip
  66.             continue
  67.         if(data[MOVESPEED_DATA_INDEX_BL_MOVETYPE] & movement_type) // There's a movetype here that disables this modifier, skip
  68.             continue
  69.         var/conflict = data[MOVESPEED_DATA_INDEX_CONFLICT]
  70.         var/amt = data[MOVESPEED_DATA_INDEX_MULTIPLICATIVE_SLOWDOWN]
  71.         if(conflict)
  72.             // Conflicting modifiers prioritize the larger slowdown or the larger speedup
  73.             // We purposefuly don't handle mixing speedups and slowdowns on the same id
  74.             if(abs(conflict_tracker[conflict]) < abs(amt))
  75.                 conflict_tracker[conflict] = amt
  76.             else
  77.                 continue
  78.         . += amt
  79.     cached_multiplicative_slowdown = .
  80.  
  81. /mob/proc/get_movespeed_modifiers()
  82.     return movespeed_modification
  83.  
  84. /mob/proc/movespeed_modifier_identical_check(list/mod1, list/mod2)
  85.     if(!islist(mod1) || !islist(mod2) || mod1.len < MOVESPEED_DATA_INDEX_MAX || mod2.len < MOVESPEED_DATA_INDEX_MAX)
  86.         return FALSE
  87.     for(var/i in 1 to MOVESPEED_DATA_INDEX_MAX)
  88.         if(mod1[i] != mod2[i])
  89.             return FALSE
  90.     return TRUE
  91.  
  92. /mob/proc/total_multiplicative_slowdown()
  93.     . = 0
  94.     for(var/id in get_movespeed_modifiers())
  95.         var/list/data = movespeed_modification[id]
  96.         . += data[MOVESPEED_DATA_INDEX_MULTIPLICATIVE_SLOWDOWN]
  97.  
  98. /proc/movespeed_data_null_check(list/data)      //Determines if a data list is not meaningful and should be discarded.
  99.     . = TRUE
  100.     if(data[MOVESPEED_DATA_INDEX_MULTIPLICATIVE_SLOWDOWN])
  101.         . = FALSE
  102.  
  103. /mob/proc/sort_movespeed_modlist()          //Verifies it too. Sorts highest priority (first applied) to lowest priority (last applied)
  104.     if(!movespeed_modification)
  105.         return
  106.     var/list/assembled = list()
  107.     for(var/our_id in movespeed_modification)
  108.         var/list/our_data = movespeed_modification[our_id]
  109.         if(!islist(our_data) || (our_data.len < MOVESPEED_DATA_INDEX_PRIORITY) || movespeed_data_null_check(our_data))
  110.             movespeed_modification -= our_id
  111.             continue
  112.         var/our_priority = our_data[MOVESPEED_DATA_INDEX_PRIORITY]
  113.         var/resolved = FALSE
  114.         for(var/their_id in assembled)
  115.             var/list/their_data = assembled[their_id]
  116.             if(their_data[MOVESPEED_DATA_INDEX_PRIORITY] < our_priority)
  117.                 assembled.Insert(assembled.Find(their_id), our_id)
  118.                 assembled[our_id] = our_data
  119.                 resolved = TRUE
  120.                 break
  121.         if(!resolved)
  122.             assembled[our_id] = our_data
  123.     movespeed_modification = assembled
  124.     UNSETEMPTY(movespeed_modification)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top