Skip to content

Commit

Permalink
map rotation base code
Browse files Browse the repository at this point in the history
  • Loading branch information
MrStonedOne committed Sep 30, 2015
1 parent ac89c3f commit fcc8402
Show file tree
Hide file tree
Showing 17 changed files with 295 additions and 71 deletions.
2 changes: 1 addition & 1 deletion _maps/tgstation2.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ z7 = empty space
#include "map_files\generic\z7.dmm"

#define MAP_FILE "tgstation.2.1.3.dmm"
#define MAP_NAME "TGstation 2"
#define MAP_NAME "Box Station"

#elif !defined(MAP_OVERRIDE)

Expand Down
5 changes: 5 additions & 0 deletions code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@
#endif

#define USE_BYGEX


#ifndef SERVERTOOLS
#define SERVERTOOLS 1
#endif
58 changes: 58 additions & 0 deletions code/controllers/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
var/announce_admin_logout = 0
var/announce_admin_login = 0

var/list/datum/votablemap/maplist = list()
var/datum/votablemap/defaultmap = null
var/maprotation = 1

/datum/configuration/New()
var/list/L = typesof(/datum/game_mode) - /datum/game_mode
for(var/T in L)
Expand Down Expand Up @@ -354,6 +358,8 @@
config.announce_admin_logout = 1
if("announce_admin_login")
config.announce_admin_login = 1
if("maprotation")
config.maprotation = 1
else
diary << "Unknown setting in configuration: '[name]'"

Expand Down Expand Up @@ -529,6 +535,58 @@
if(fps <= 0)
fps = initial(fps)


/datum/configuration/proc/loadmaplist(filename)
var/list/Lines = file2list(filename)

var/datum/votablemap/currentmap = null
for(var/t in Lines)
if(!t) continue

t = trim(t)
if(length(t) == 0)
continue
else if(copytext(t, 1, 2) == "#")
continue

var/pos = findtext(t, " ")
var/command = null
var/data = null

if(pos)
command = lowertext(copytext(t, 1, pos))
data = copytext(t, pos + 1)
else
command = lowertext(t)

if(!command)
continue

if (!currentmap && command != "map")
continue

switch (command)
if ("map")
currentmap = new (data)
if ("friendlyname")
currentmap.friendlyname = data
if ("minplayers","minplayer")
currentmap.minusers = text2num(data)
if ("maxplayers","maxplayer")
currentmap.maxusers = text2num(data)
if ("friendlyname")
currentmap.friendlyname = data
if ("weight","voteweight")
currentmap.voteweight = text2num(data)
if ("default","defaultmap")
config.defaultmap = currentmap
if ("endmap")
config.maplist[currentmap.name] = currentmap
currentmap = null
else
diary << "Unknown command in map vote config: '[command]'"


/datum/configuration/proc/loadsql(filename)
var/list/Lines = file2list(filename)
for(var/t in Lines)
Expand Down
80 changes: 79 additions & 1 deletion code/controllers/subsystem/ticker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ var/datum/subsystem/ticker/ticker

var/obj/screen/cinematic = null //used for station explosion cinematic

var/maprotatechecked = 0


/datum/subsystem/ticker/New()
NEW_SS_GLOBAL(ticker)
Expand Down Expand Up @@ -100,6 +102,7 @@ var/datum/subsystem/ticker/ticker
if(GAME_STATE_PLAYING)
mode.process(wait * 0.1)
check_queue()
check_maprotate()

if(!mode.explosion_in_progress && mode.check_finished() || force_ending)
current_state = GAME_STATE_FINISHED
Expand Down Expand Up @@ -458,4 +461,79 @@ var/datum/subsystem/ticker/ticker
if(25 to INFINITY) //No response from the next in line when a vacancy exists, remove he
next_in_line << "<span class='danger'>No response recieved. You have been removed from the line.</span>"
queued_players -= next_in_line
queue_delay = 0
queue_delay = 0

/datum/subsystem/ticker/proc/check_maprotate(var/force = 0)
if (!config.maprotation && !force)
return
if ((SSshuttle.emergency.mode != SHUTTLE_ESCAPE || SSshuttle.canRecall()) && !force)
return
if (maprotatechecked && !force)
return

maprotatechecked = 1

//map rotate chance is length of the round (in minutes) divided by 2
if (!prob((world.time/600)/2) && !force)
return

var/players = clients.len
var/list/mapvotes = list()
//count votes
for (var/client/c in clients)
var/vote = c.prefs.preferred_map
mapvotes[vote] += 1
//filter votes
for (var/map in mapvotes)
if (!map)
if (!config.defaultmap)
mapvotes.Remove(map)
continue
mapvotes[config.defaultmap.name] += mapvotes[map]
if (!(map in config.maplist))
mapvotes.Remove(map)
continue
var/datum/votablemap/VM = config.maplist[map]
if (!VM)
mapvotes.Remove(map)
continue
if (VM.voteweight <= 0)
mapvotes.Remove(map)
continue
if (VM.minusers > 0 && players < VM.minusers)
mapvotes.Remove(map)
continue
if (VM.maxusers > 0 && players < VM.maxusers)
mapvotes.Remove(map)
continue

mapvotes[map] = mapvotes[map]*VM.voteweight

var/pickedmap = pickweight(mapvotes)
if (!pickedmap)
return

var/file = file("setnewmap.bat")
file << "\nset MAPROTATE=[pickedmap]\n"
var/exitcode = shell("..\\bin\\maprotate.bat")
switch (exitcode)
if (null)
message_admins("Failed to rotate map: Could not run map rotator")
log_game("Failed to rotate map: Could not run map rotator")
if (0)
var/datum/votablemap/VM = config.maplist[pickedmap]
world << "<span class='boldannounce'>Map rotation has choosen [VM.friendlyname] for next round!</span>"
if (1)
message_admins("Failed to rotate map: Map rotator script couldn't find file listing new map")
log_game("Failed to rotate map: Map rotator script couldn't find file listing new map")
if (2)
message_admins("Failed to rotate map: Map rotator script couldn't find tgstation-tools framework")
log_game("Failed to rotate map: Map rotator script couldn't find tgstation-tools framework")
if (3)
message_admins("Failed to rotate map: Could not compile new map:[pickedmap]")
log_game("Failed to rotate map: Could not compile new map:[pickedmap]")
else
message_admins("Failed to rotate map: Unknown error")
log_game("Failed to rotate map: Unknown error")


10 changes: 10 additions & 0 deletions code/datums/votablemap.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/datum/votablemap
var/name = ""
var/friendlyname = ""
var/minusers = 0
var/maxusers = 0
var/voteweight = 1

/datum/votablemap/New(name)
src.name = name
src.friendlyname = name
18 changes: 18 additions & 0 deletions code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var/global/list/special_roles = list( //keep synced with the defines BE_* in set
var/chat_toggles = TOGGLES_DEFAULT_CHAT
var/ghost_form = "ghost"
var/allow_midround_antag = 1
var/preferred_map = null

//character preferences
var/real_name //our character's name
Expand Down Expand Up @@ -355,6 +356,8 @@ var/global/list/special_roles = list( //keep synced with the defines BE_* in set
dat += "<b>BYOND Membership Publicity:</b> <a href='?_src_=prefs;preference=publicity'>[(toggles & MEMBER_PUBLIC) ? "Public" : "Hidden"]</a><br>"
dat += "<b>Ghost Form:</b> <a href='?_src_=prefs;task=input;preference=ghostform'>[ghost_form]</a><br>"

if (SERVERTOOLS && config.maprotation)
dat += "<b>Preferred Map:</b> <a href='?_src_=prefs;preference=preferred_map;task=input'>[preferred_map ? preferred_map : "Default[config.defaultmap ? " ([config.defaultmap.friendlyname])":""]"]</a>"

dat += "</td><td width='300px' height='300px' valign='top'>"

Expand Down Expand Up @@ -955,6 +958,21 @@ var/global/list/special_roles = list( //keep synced with the defines BE_* in set
custom_names["deity"] = new_deity_name
else
user << "<font color='red'>Invalid name. Your name should be at least 2 and at most [MAX_NAME_LEN] characters long. It may only contain the characters A-Z, a-z, -, ' and .</font>"
if ("preferred_map")
var/maplist = list()
var/default = "Default"
if (config.defaultmap)
default += " ([config.defaultmap.friendlyname])"
for (var/M in config.maplist)
var/datum/votablemap/VM = config.maplist[M]
var/friendlyname = "[VM.friendlyname] "
if (VM.voteweight <= 0)
friendlyname += " (disabled)"
maplist[friendlyname] = VM.name
maplist[default] = null
var/pickedmap = input(user, "Choose your preferred map. This will be used to help weight random map selection.", "Character Preference") as null|anything in maplist
if (pickedmap)
preferred_map = maplist[pickedmap]


else
Expand Down
3 changes: 3 additions & 0 deletions code/modules/client/preferences_savefile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
chat_toggles = TOGGLES_DEFAULT_CHAT
toggles = TOGGLES_DEFAULT


//should this proc get fairly long (say 3 versions long),
//just increase SAVEFILE_VERSION_MIN so it's not as far behind
//SAVEFILE_VERSION_MAX and then delete any obsolete if clauses
Expand Down Expand Up @@ -104,6 +105,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
S["chat_toggles"] >> chat_toggles
S["toggles"] >> toggles
S["ghost_form"] >> ghost_form
S["preferred_map"] >> preferred_map

//try to fix any outdated data if necessary
if(needs_update >= 0)
Expand Down Expand Up @@ -137,6 +139,7 @@ SAVEFILE UPDATING/VERSIONING - 'Simplified', or rather, more coder-friendly ~Car
S["toggles"] << toggles
S["chat_toggles"] << chat_toggles
S["ghost_form"] << ghost_form
S["preferred_map"] << preferred_map

return 1

Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ var/list/slot_equipment_priority = list( \
..()

if(statpanel("Status"))
stat(null, "Map: [MAP_NAME]")
stat(null, "Server Time: [time2text(world.realtime, "YYYY-MM-DD hh:mm")]")
var/ETA
switch(SSshuttle.emergency.mode)
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/new_player/new_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

if(statpanel("Lobby"))
stat("Game Mode:", (ticker.hide_mode) ? "Secret" : "[master_mode]")
stat("Map:", MAP_NAME)

if(ticker.current_state == GAME_STATE_PREGAME)
stat("Time To Start:", (ticker.timeLeft >= 0) ? "[round(ticker.timeLeft / 10)]s" : "DELAYED")
Expand Down
3 changes: 3 additions & 0 deletions code/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
config.load("config/config.txt")
config.load("config/game_options.txt","game_options")
config.loadsql("config/dbconfig.txt")
if (config.maprotation)
config.loadmaplist("config/maps.txt")

// apply some settings from config..
abandon_allowed = config.respawn

Expand Down
7 changes: 4 additions & 3 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
#include "code\datums\spell.dm"
#include "code\datums\supplypacks.dm"
#include "code\datums\uplink_item.dm"
#include "code\datums\votablemap.dm"
#include "code\datums\diseases\_disease.dm"
#include "code\datums\diseases\_MobProcs.dm"
#include "code\datums\diseases\anxiety.dm"
Expand Down Expand Up @@ -834,9 +835,9 @@
#include "code\modules\admin\NewBan.dm"
#include "code\modules\admin\newbanjob.dm"
#include "code\modules\admin\player_panel.dm"
#include "code\modules\admin\secrets.dm"
#include "code\modules\admin\stickyban.dm"
#include "code\modules\admin\sql_notes.dm"
#include "code\modules\admin\secrets.dm"
#include "code\modules\admin\sql_notes.dm"
#include "code\modules\admin\stickyban.dm"
#include "code\modules\admin\topic.dm"
#include "code\modules\admin\watchlist.dm"
#include "code\modules\admin\DB ban\functions.dm"
Expand Down
Loading

0 comments on commit fcc8402

Please sign in to comment.