Files
Bubberstation/code/modules/capture_the_flag/ctf_player_component.dm
Mothblocks c1d68698fb Micro-optimize qdel by only permitting one parameter (#80628)
Productionizes #80615.

The core optimization is this:

```patch
-	var/hint = to_delete.Destroy(arglist(args.Copy(2))) // Let our friend know they're about to get fucked up.
+	var/hint = to_delete.Destroy(force) // Let our friend know they're about to get fucked up.
```

We avoid a heap allocation in the form of copying the args over to a new
list. A/B testing shows this results in 33% better overtime, and in a
real round shaving off a full second of self time and 0.4 seconds of
overtime--both of these would be doubled in the event this is merged as
the new proc was only being run 50% of the time.
2023-12-28 13:52:44 -08:00

81 lines
3.2 KiB
Plaintext

///A component added to the mind of anyone who is playing in an ongoing CTF match. Any player specific CTF functionality should be implimented here. (someone should impliment score tracking here)
/datum/component/ctf_player
///The team that this player is associated with.
var/team
///A reference to the players mob, cleared after they die, restored on respawn.
var/mob/living/player_mob
///Weather or not the player is currently able to respawn.
var/can_respawn = TRUE
///Reference to the game this player is participating in.
var/datum/ctf_controller/ctf_game
///Item dropped on death,
var/death_drop = /obj/effect/powerup/ammo/ctf
///Reference to players ckey, used for sending messages to them relating to CTF.
var/ckey_reference
/datum/component/ctf_player/Initialize(team, ctf_game, death_drop)
src.team = team
src.ctf_game = ctf_game
src.death_drop = death_drop
if(!istype(parent, /datum/mind))
return COMPONENT_INCOMPATIBLE
var/datum/mind/true_parent = parent
player_mob = true_parent.current
ckey_reference = player_mob.ckey
register_mob()
/datum/component/ctf_player/PostTransfer()
if(!istype(parent, /datum/mind))
return COMPONENT_INCOMPATIBLE
var/datum/mind/true_parent = parent
player_mob = true_parent.current
register_mob()
/// Called when we get a new player mob, register signals and set up the mob.
/datum/component/ctf_player/proc/register_mob()
RegisterSignal(player_mob, COMSIG_MOB_AFTER_APPLY_DAMAGE, PROC_REF(damage_type_check))
RegisterSignal(player_mob, COMSIG_MOB_GHOSTIZED, PROC_REF(ctf_dust))
ADD_TRAIT(player_mob, TRAIT_PERMANENTLY_MORTAL, CTF_TRAIT)
///Stamina and oxygen damage will not dust a player by themself.
/datum/component/ctf_player/proc/damage_type_check(datum/source, damage, damage_type)
SIGNAL_HANDLER
if(damage_type != STAMINA && damage_type != OXY)
ctf_dust()
///Dusts the player and starts a respawn countdown.
/datum/component/ctf_player/proc/ctf_dust()
SIGNAL_HANDLER
if(!HAS_TRAIT(player_mob, TRAIT_CRITICAL_CONDITION) && !player_mob.stat == DEAD && player_mob.client)
return
UnregisterSignal(player_mob, list(COMSIG_MOB_AFTER_APPLY_DAMAGE, COMSIG_MOB_GHOSTIZED))
var/turf/death_turf = get_turf(player_mob)
player_mob.dust()
player_mob = null
can_respawn = FALSE
addtimer(CALLBACK(src, PROC_REF(allow_respawns)), ctf_game.respawn_cooldown, TIMER_UNIQUE)
if(death_drop)
new death_drop(death_turf)
///Called after a period of time pulled from ctf_game, allows the player to respawn in CTF.
/datum/component/ctf_player/proc/allow_respawns()
can_respawn = TRUE
send_message(span_notice("You can now respawn in CTF!"))
///Sends a message to the player.
/datum/component/ctf_player/proc/send_message(message)
to_chat(GLOB.directory[ckey_reference], message)
///Called when the associated CTF game ends or their associated team is deleted, dusts the player and deletes this component to ensure no data from it is carried over to future games.
/datum/component/ctf_player/proc/end_game()
if(player_mob)
for(var/obj/item/ctf_flag/flag in player_mob)
player_mob.dropItemToGround(flag)
player_mob.dust()
qdel(src)
/datum/component/ctf_player/Destroy(force)
if(player_mob)
UnregisterSignal(player_mob, list(COMSIG_MOB_AFTER_APPLY_DAMAGE, COMSIG_MOB_GHOSTIZED))
return ..()