Adds minimal players requirements for random event

This commit is contained in:
c0
2016-03-29 08:49:17 +03:00
parent 33ecd490b0
commit 23fb45ba6e
24 changed files with 67 additions and 27 deletions

View File

@@ -332,13 +332,19 @@
for(var/client/C in show_to) for(var/client/C in show_to)
C.images -= I C.images -= I
/proc/get_active_player_count() /proc/get_active_player_count(var/alive_check = 0, var/afk_check = 0, var/human_check = 0)
// Get active players who are playing in the round // Get active players who are playing in the round
var/active_players = 0 var/active_players = 0
for(var/i = 1; i <= player_list.len; i++) for(var/i = 1; i <= player_list.len; i++)
var/mob/M = player_list[i] var/mob/M = player_list[i]
if(M && M.client) if(M && M.client)
if(istype(M, /mob/new_player)) // exclude people in the lobby if(alive_check && M.stat)
continue
else if(afk_check && M.client.is_afk())
continue
else if(human_check && !istype(M, /mob/living/carbon/human))
continue
else if(istype(M, /mob/new_player)) // exclude people in the lobby
continue continue
else if(isobserver(M)) // Ghosts are fine if they were playing once (didn't start as observers) else if(isobserver(M)) // Ghosts are fine if they were playing once (didn't start as observers)
var/mob/dead/observer/O = M var/mob/dead/observer/O = M

View File

@@ -70,19 +70,14 @@ var/datum/subsystem/events/SSevent
// if(E) E.runEvent() // if(E) E.runEvent()
return return
var/gamemode = ticker.mode.config_tag
var/players_amt = get_active_player_count(alive_check = 1, afk_check = 1, human_check = 1)
// Only alive, non-AFK human players count towards this.
var/sum_of_weights = 0 var/sum_of_weights = 0
for(var/datum/round_event_control/E in control) for(var/datum/round_event_control/E in control)
if(E.occurrences >= E.max_occurrences) if(!E.canSpawnEvent(players_amt, gamemode))
continue continue
if(E.earliest_start >= world.time)
continue
if(E.gamemode_blacklist.len && (ticker.mode.config_tag in E.gamemode_blacklist))
continue
if(E.gamemode_whitelist.len && !(ticker.mode.config_tag in E.gamemode_whitelist))
continue
if(E.holidayID)
if(!holidays || !holidays[E.holidayID])
continue
if(E.weight < 0) //for round-start events etc. if(E.weight < 0) //for round-start events etc.
if(E.runEvent() == PROCESS_KILL) if(E.runEvent() == PROCESS_KILL)
E.max_occurrences = 0 E.max_occurrences = 0
@@ -96,17 +91,8 @@ var/datum/subsystem/events/SSevent
sum_of_weights = rand(0,sum_of_weights) //reusing this variable. It now represents the 'weight' we want to select sum_of_weights = rand(0,sum_of_weights) //reusing this variable. It now represents the 'weight' we want to select
for(var/datum/round_event_control/E in control) for(var/datum/round_event_control/E in control)
if(E.occurrences >= E.max_occurrences) if(!E.canSpawnEvent(players_amt, gamemode))
continue continue
if(E.earliest_start >= world.time)
continue
if(E.gamemode_blacklist.len && (ticker.mode.config_tag in E.gamemode_blacklist))
continue
if(E.gamemode_whitelist.len && !(ticker.mode.config_tag in E.gamemode_whitelist))
continue
if(E.holidayID)
if(!holidays || !holidays[E.holidayID])
continue
sum_of_weights -= E.weight sum_of_weights -= E.weight
if(sum_of_weights <= 0) //we've hit our goal if(sum_of_weights <= 0) //we've hit our goal

View File

@@ -4,6 +4,7 @@
weight = 5 weight = 5
max_occurrences = 1 max_occurrences = 1
min_players = 5
earliest_start = 18000 // 30 min earliest_start = 18000 // 30 min
gamemode_blacklist = list("nuclear","wizard","revolution","abduction") gamemode_blacklist = list("nuclear","wizard","revolution","abduction")

View File

@@ -2,6 +2,8 @@
name = "Alien Infestation" name = "Alien Infestation"
typepath = /datum/round_event/alien_infestation typepath = /datum/round_event/alien_infestation
weight = 5 weight = 5
min_players = 10
max_occurrences = 1 max_occurrences = 1
/datum/round_event/alien_infestation /datum/round_event/alien_infestation

View File

@@ -1,6 +1,8 @@
/datum/round_event_control/anomaly /datum/round_event_control/anomaly
name = "Anomaly: Energetic Flux" name = "Anomaly: Energetic Flux"
typepath = /datum/round_event/anomaly typepath = /datum/round_event/anomaly
min_players = 1
max_occurrences = 0 //This one probably shouldn't occur! It'd work, but it wouldn't be very fun. max_occurrences = 0 //This one probably shouldn't occur! It'd work, but it wouldn't be very fun.
weight = 15 weight = 15

View File

@@ -1,6 +1,8 @@
/datum/round_event_control/anomaly/anomaly_flux /datum/round_event_control/anomaly/anomaly_flux
name = "Anomaly: Hyper-Energetic Flux" name = "Anomaly: Hyper-Energetic Flux"
typepath = /datum/round_event/anomaly/anomaly_flux typepath = /datum/round_event/anomaly/anomaly_flux
min_players = 10
max_occurrences = 5 max_occurrences = 5
weight = 20 weight = 20

View File

@@ -1,6 +1,8 @@
/datum/round_event_control/anomaly/anomaly_vortex /datum/round_event_control/anomaly/anomaly_vortex
name = "Anomaly: Vortex" name = "Anomaly: Vortex"
typepath = /datum/round_event/anomaly/anomaly_vortex typepath = /datum/round_event/anomaly/anomaly_vortex
min_players = 20
max_occurrences = 2 max_occurrences = 2
weight = 5 weight = 5

View File

@@ -4,6 +4,7 @@
weight = 5 weight = 5
max_occurrences = 1 max_occurrences = 1
min_players = 20
earliest_start = 18000 //30 minutes earliest_start = 18000 //30 minutes
gamemode_blacklist = list("blob") //Just in case a blob survives that long gamemode_blacklist = list("blob") //Just in case a blob survives that long

View File

@@ -2,6 +2,8 @@
name = "Brand Intelligence" name = "Brand Intelligence"
typepath = /datum/round_event/brand_intelligence typepath = /datum/round_event/brand_intelligence
weight = 5 weight = 5
min_players = 15
max_occurrences = 1 max_occurrences = 1
/datum/round_event/brand_intelligence /datum/round_event/brand_intelligence

View File

@@ -2,6 +2,7 @@
name = "Carp Migration" name = "Carp Migration"
typepath = /datum/round_event/carp_migration typepath = /datum/round_event/carp_migration
weight = 15 weight = 15
min_players = 2
earliest_start = 6000 earliest_start = 6000
max_occurrences = 6 max_occurrences = 6

View File

@@ -2,6 +2,7 @@
name = "Disease Outbreak" name = "Disease Outbreak"
typepath = /datum/round_event/disease_outbreak typepath = /datum/round_event/disease_outbreak
max_occurrences = 1 max_occurrences = 1
min_players = 10
weight = 5 weight = 5
/datum/round_event/disease_outbreak /datum/round_event/disease_outbreak

View File

@@ -2,6 +2,7 @@
name = "Electrical Storm" name = "Electrical Storm"
typepath = /datum/round_event/electrical_storm typepath = /datum/round_event/electrical_storm
earliest_start = 6000 earliest_start = 6000
min_players = 5
weight = 40 weight = 40
alertadmins = 0 alertadmins = 0

View File

@@ -1,6 +1,6 @@
//this datum is used by the events controller to dictate how it selects events //this datum is used by the events controller to dictate how it selects events
/datum/round_event_control /datum/round_event_control
var/name //The name human-readable name of the event var/name //The human-readable name of the event
var/typepath //The typepath of the event datum /datum/round_event var/typepath //The typepath of the event datum /datum/round_event
var/weight = 10 //The weight this event has in the random-selection process. var/weight = 10 //The weight this event has in the random-selection process.
@@ -8,9 +8,10 @@
//10 is the default weight. 20 is twice more likely; 5 is half as likely as this default. //10 is the default weight. 20 is twice more likely; 5 is half as likely as this default.
var/earliest_start = 12000 //The earliest world.time that an event can start (round-duration in deciseconds) default: 20 mins var/earliest_start = 12000 //The earliest world.time that an event can start (round-duration in deciseconds) default: 20 mins
var/min_players = 0 //The minimum amount of alive, non-AFK human players on server required to start the event.
var/occurrences = 0 //How many times this event has occured var/occurrences = 0 //How many times this event has occured
var/max_occurrences = 20 //The maximum number of times this event can occur (naturally), it can still be forced. var/max_occurrences = 20 //The maximum number of times this event can occur (naturally), it can still be forced.
//By setting this to 0 you can effectively disable an event. //By setting this to 0 you can effectively disable an event.
var/holidayID = "" //string which should be in the SSevents.holidays list if you wish this event to be holiday-specific var/holidayID = "" //string which should be in the SSevents.holidays list if you wish this event to be holiday-specific
@@ -26,10 +27,28 @@
/datum/round_event_control/wizard /datum/round_event_control/wizard
wizardevent = 1 wizardevent = 1
// Checks if the event can be spawned. Used by event controller and "false alarm" event.
// Admin-created events override this.
/datum/round_event_control/proc/canSpawnEvent(var/players_amt, var/gamemode)
if(occurrences >= max_occurrences)
return FALSE
if(earliest_start >= world.time)
return FALSE
if(players_amt < min_players)
return FALSE
if(gamemode_blacklist.len && (gamemode in gamemode_blacklist))
return FALSE
if(gamemode_whitelist.len && !(gamemode in gamemode_whitelist))
return FALSE
if(holidayID && (!SSevent.holidays || !SSevent.holidays[holidayID]))
return FALSE
return TRUE
/datum/round_event_control/proc/runEvent() /datum/round_event_control/proc/runEvent()
if(!ispath(typepath,/datum/round_event)) if(!ispath(typepath,/datum/round_event))
return PROCESS_KILL return PROCESS_KILL
var/datum/round_event/E = new typepath() var/datum/round_event/E = new typepath()
E.current_players = get_active_player_count(alive_check = 1, afk_check = 1, human_check = 1)
E.control = src E.control = src
feedback_add_details("event_ran","[E]") feedback_add_details("event_ran","[E]")
occurrences++ occurrences++
@@ -47,6 +66,7 @@
var/endWhen = 0 //When in the lifetime the event should end. var/endWhen = 0 //When in the lifetime the event should end.
var/activeFor = 0 //How long the event has existed. You don't need to change this. var/activeFor = 0 //How long the event has existed. You don't need to change this.
var/current_players = 0 //Amount of of alive, non-AFK human players on server at the time of event start
//Called first before processing. //Called first before processing.
//Allows you to setup your event, such as randomly //Allows you to setup your event, such as randomly

View File

@@ -10,11 +10,14 @@
/datum/round_event/falsealarm/announce() /datum/round_event/falsealarm/announce()
var/list/events_list = list() var/list/events_list = list()
var/players_amt = get_active_player_count(alive_check = 1, afk_check = 1, human_check = 1)
var/gamemode = ticker.mode.config_tag
for(var/datum/round_event_control/E in SSevent.control) for(var/datum/round_event_control/E in SSevent.control)
if(E.holidayID || E.wizardevent) if(!E.canSpawnEvent(players_amt, gamemode))
continue
if(E.earliest_start >= world.time)
continue continue
var/datum/round_event/event = E.typepath var/datum/round_event/event = E.typepath
if(initial(event.announceWhen) <= 0) if(initial(event.announceWhen) <= 0)
continue continue

View File

@@ -10,6 +10,7 @@ In my current plan for it, 'solid' will be defined as anything with density == 1
/datum/round_event_control/immovable_rod /datum/round_event_control/immovable_rod
name = "Immovable Rod" name = "Immovable Rod"
typepath = /datum/round_event/immovable_rod typepath = /datum/round_event/immovable_rod
min_players = 15
max_occurrences = 5 max_occurrences = 5
/datum/round_event/immovable_rod /datum/round_event/immovable_rod

View File

@@ -5,6 +5,7 @@
name = "Ion Storm" name = "Ion Storm"
typepath = /datum/round_event/ion_storm typepath = /datum/round_event/ion_storm
weight = 15 weight = 15
min_players = 2
/datum/round_event/ion_storm /datum/round_event/ion_storm
var/botEmagChance = 10 var/botEmagChance = 10

View File

@@ -3,6 +3,7 @@
typepath = /datum/round_event/mass_hallucination typepath = /datum/round_event/mass_hallucination
weight = 7 weight = 7
max_occurrences = 2 max_occurrences = 2
min_players = 1
/datum/round_event/mass_hallucination/start() /datum/round_event/mass_hallucination/start()
for(var/mob/living/carbon/C in living_mob_list) for(var/mob/living/carbon/C in living_mob_list)

View File

@@ -2,6 +2,7 @@
name = "Meteor Wave" name = "Meteor Wave"
typepath = /datum/round_event/meteor_wave typepath = /datum/round_event/meteor_wave
weight = 5 weight = 5
min_players = 5
max_occurrences = 3 max_occurrences = 3
/datum/round_event/meteor_wave /datum/round_event/meteor_wave

View File

@@ -2,6 +2,7 @@
name = "Portal Storm: Syndicate Shocktroops" name = "Portal Storm: Syndicate Shocktroops"
typepath = /datum/round_event/portal_storm/syndicate_shocktroop typepath = /datum/round_event/portal_storm/syndicate_shocktroop
weight = 2 weight = 2
min_players = 15
earliest_start = 18000 earliest_start = 18000
/datum/round_event/portal_storm/syndicate_shocktroop /datum/round_event/portal_storm/syndicate_shocktroop

View File

@@ -2,6 +2,7 @@
name = "Prison Break" name = "Prison Break"
typepath = /datum/round_event/prison_break typepath = /datum/round_event/prison_break
max_occurrences = 2 max_occurrences = 2
min_players = 5
/datum/round_event/prison_break /datum/round_event/prison_break
announceWhen = 50 announceWhen = 50

View File

@@ -3,6 +3,7 @@
typepath = /datum/round_event/spacevine typepath = /datum/round_event/spacevine
weight = 15 weight = 15
max_occurrences = 3 max_occurrences = 3
min_players = 10
/datum/round_event/spacevine/start() /datum/round_event/spacevine/start()
var/list/turfs = list() //list of all the empty floor turfs in the hallway areas var/list/turfs = list() //list of all the empty floor turfs in the hallway areas

View File

@@ -3,6 +3,7 @@
typepath = /datum/round_event/spider_infestation typepath = /datum/round_event/spider_infestation
weight = 5 weight = 5
max_occurrences = 1 max_occurrences = 1
min_players = 15
/datum/round_event/spider_infestation /datum/round_event/spider_infestation
announceWhen = 400 announceWhen = 400

View File

@@ -4,6 +4,7 @@
weight = 20 weight = 20
max_occurrences = 4 max_occurrences = 4
earliest_start = 6000 earliest_start = 6000
min_players = 5 // To make your chance of getting help a bit higher.
/datum/round_event/spontaneous_appendicitis/start() /datum/round_event/spontaneous_appendicitis/start()
for(var/mob/living/carbon/human/H in shuffle(living_mob_list)) for(var/mob/living/carbon/human/H in shuffle(living_mob_list))

View File

@@ -3,6 +3,7 @@
typepath = /datum/round_event/wormholes typepath = /datum/round_event/wormholes
max_occurrences = 3 max_occurrences = 3
weight = 2 weight = 2
min_players = 2
/datum/round_event/wormholes /datum/round_event/wormholes