Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.18 KB | None | 0 0
  1. -- Stadium server v1.35 for PES 2019 - assign the stadium for either home team or competition
  2. -- Custom content is used, not LiveCPK/game: content\stadium-server is the root
  3. -- author: zlac, 2018-2019
  4. -- originally posted on evo-web
  5.  
  6. -- local new_stadium_path
  7. local version = "1.35"
  8. local stadiumroot = ".\\content\\stadium-server\\"
  9. local stadium_switched = false
  10. local stadium_name_switched = false
  11. local last_choice
  12. local settings
  13.  
  14. -- "minus 1" will be applied to all values > 0
  15. local weather_TimeOfDay = 0 -- 0 (in-game selection), 1 (Day), 2 (Night)
  16. local weather_TimeOfDay_Info = {["0"]="Default", ["1"]="Day", ["2"]="Night"}
  17. local weather_Weather = 0 -- 0 (in-game selection), 1 (Fine/Sunny), 2 (Rainy), 3 (Snowy)
  18. local weather_Weather_Info = {["0"]="Default", ["1"]="Fine/Sunny", ["2"]="Rainy", ["3"]="Snowy"}
  19. local weather_WeatherEffects = 0 -- 0 (in-game selection), 3 (Force Rain/snow falling)
  20. local weather_WeatherEffects_Info = {["0"]="Default", ["3"]="Forced"}
  21. local weather_Season = 0 -- 0 (in-game selection), 1 (Summer), 2 (Winter)
  22. local weather_Season_Info = {["0"]="Default", ["1"]="Summer", ["2"]="Winter"}
  23.  
  24. --[[
  25. local replay_stad_id = nil
  26. local replay_source_stadium_map = nil
  27. local replay_source_stadium_key = nil
  28. ]]--
  29.  
  30. local random_num_comp -- which stadium to select randomly in competition modes from stadium server (depending on entries available per competition in map_competition.txt)
  31. local random_num_exhib -- which stadium to select randomly in exhibition modes from stadium server
  32. local rnd_server_or_cpk -- to serve random stadium from stadium server (depending on entries available per competition in map_competition.txt) or from default .cpk files (i.e. stadium server deactivates itself temporarily)
  33.  
  34. local team_assignment_map = {}
  35. local competition_assignment_map = {}
  36. local all_stadiums_map = {}
  37. local konami_stadiums_map = {}
  38.  
  39. local info_text = ""
  40. local weather_text = ""
  41. local manual_stad_idx
  42. local manual_stad_info = "Manually selected stadium: None"
  43. local manual_selection_status = "Off"
  44. local manual_selection_status_info = "Selection mode: automatic map assignments"
  45. local total_stadiums
  46.  
  47. local _stadium_info = {}
  48. local current_stadium_preview_path
  49.  
  50. local RELOAD_MAPS_KEY = 0x30 -- 0 key (not the NUMPAD zero!!)
  51. local WEATHER_TIMEOFDAY_KEY = 0x33 -- 3 key (not the NUMPAD 7!!)
  52. local WEATHER_WEATHER_KEY = 0x34 -- 4 key (not the NUMPAD 7!!)
  53. local WEATHER_WEATHER_EFFECTS_KEY = 0x35 -- 5 key (not the NUMPAD 7!!)
  54. local WEATHER_SEASON_KEY = 0x36 -- 6 key (not the NUMPAD 7!!)
  55. local SET_AS_FAVORITE_STAD_KEY = 0x37 -- 7 key (not the NUMPAD 7!!)
  56. local USE_FAVORITE_STAD_KEY = 0x38 -- 8 key (not the NUMPAD 8!!)
  57. local SWITCH_SELECTION_MODE_KEY = 0x39 -- 9 key (not the NUMPAD 9!!)
  58. local DEL_TEXT_KEY = 0x2E
  59. local PREVIOUS_STAD_KEY = 0x21 -- Page Up
  60. local NEXT_STAD_KEY = 0x22 -- Page Down
  61.  
  62. local stadium_config = {}
  63.  
  64. -- override_competitions contains comma-separated ID's of the competitions that allow for team-assigned stadiums to have precedence before competiton-assigned stadiums
  65. -- .. e.g. you've assigned a home stadium for ALL exhibition mode matches (tid 65535) in map_competitions.txt, but you still want to use
  66. -- .. custom home-team stadium for those teams that have it assigned in map_teams.txt -> add 65535 in override_competitions
  67. -- .. OR: you have assigned multiple stadiums to be selected randomly (e.g. for EPL) for those teams that do not have their own stadiums, but you
  68. -- .. still want to use custom home-team stadium for those teams that have it assigned in map_teams.txt -> add 17 too (EPL id) in override_competitions
  69. -- initially, all (at least, i hope so) Exhibition mode, League and League-Cup matches are included in competition overrides
  70. -- BEGIN CUSTOMIZABLE LUA TABLE
  71. local override_competitions = {65535, -- Exhibition matches
  72. 4, -- UCL knockout stage
  73. 6, -- UEL knockout stage
  74. 10, -- Copa Libertadores knockout stage
  75. 16, -- ACL knockout stage
  76. 17, 79, 23, 83, -- England 1st and 2nd div and cup and play offs
  77. 19, 25, 87, -- Spain 1st div league and cup and supercup (2-legged supercup, home&away matches)
  78. 18, 24, -- Italy 1st div league and cup
  79. 20, 81, 26, -- France 1st and 2nd div and cup
  80. 22, 28, -- Portugal league and cup
  81. 21, 27, -- Netherlands league and cup
  82. 30, 59, -- Argentina league and cup
  83. 29, 31, -- Brazil league and cup
  84. 67, 13400, 13401, 68, -- Chile league (first and second stage) and cup
  85. 50, 53, -- PEU league and cup
  86. 51, 10200, 10201, 54, -- PLA league (first and second stage) and cup
  87. 52, 55, -- PAS league and cup
  88. 120, 127, -- PEA (China) league and cup
  89. 115, 155, 156, 157, 158, 159, 122, -- Belgium 1st div (playoff groups 0 to 3, final knockout) and cup
  90. 116, 123, -- Russia 1st div and cup
  91. 117, 124, -- Switzerland 1st div and cup
  92. 118, 125, -- Turkey 1st div and cup
  93. 119, 23800, 23801, 160, 161, 126, -- Colombia 1st div (first and second stage, knockout 0 and 1) and cup
  94. 133, 134, 135, 136, 137, -- Scotland 1st div (playoff groups 0 to 2) and cup
  95. 141, 147, 148, 149, 150, 151, 142, -- Denmark 1st div (playoff groups 0 to 3, final knockout) and cup
  96. 161, -- Thailand 1st div
  97. }
  98. -- END CUSTOMIZABLE LUA TABLE
  99.  
  100. -- specify the IDs of the teams which already have their real homegrounds assigned via .cpk + EDIT00000000
  101. -- if not listed here, their .cpk homeground may be overriden by map_competition.txt assignment ...
  102. -- ... e.g. Barcelona and Camp Nou: if you assign generic stadiums to La Liga in map_competition.txt and DO NOT assign external Camp Nou to Barca via map_teams.txt, then ...
  103. -- ... Barcelona would never use Camp Nou from .cpk in La Liga-related competition modes - it would use one of the random generics for La Liga
  104. -- Only the teams with original Konami stadiums are listed initially (again, hopefully all of them)!
  105. -- ADD YOUR OWN TEAM ID'S, BASED ON YOUR EDIT00000000's STADIUM ASSIGNMENTS FROM THE .CPK PACK THAT YOU USE!!
  106. -- BEGIN CUSTOMIZABLE LUA TABLE
  107. local teams_with_cpk_homegrounds = {
  108. 10, -- Netherlands (Johan Cruijff Arena)
  109. 12, -- Italy (Stadio Olimipco)
  110. 45, -- Brazil (Estadio do Maracana)
  111. 47, -- Chile (Estadio Nacional de Chile)
  112. 50, -- Argentina (El Monumental)
  113. 101, -- Arsenal (Emirates)
  114. 103, -- Liverpool (Anfield)
  115. 108, -- Barcelona (Camp Nou)
  116. 112, -- Monaco (Stade Louis II)
  117. 116, -- Ajax (Johan Cruijff Arena)
  118. 119, -- Internazionale (Giuseppe Meazza)
  119. 121, -- Milan (San Siro)
  120. 122, -- Lazio (Stadio Olimpico)
  121. 125, -- Roma (Stadio Olimpico)
  122. 136, -- Vasco da Gama (Estadio Sao Januario)
  123. 137, -- Palmeiras (Allianz Parque)
  124. 138, -- River Plate (El Monumental)
  125. 139, -- Boca Juniors (Estadio Alberto J. Armando)
  126. 147, -- Urawa Red Diamonds (Saitama Stadium 2002)
  127. 184, -- Schalke 04 (Veltins Arena)
  128. 193, -- Sporting CP (Jose Alvalade)
  129. 197, -- Fenerbahce (Ülker stadium)
  130. 274, -- Cruzeiro (Toca da Raposa III)
  131. 1706, -- Basel (St. Jakob Park)
  132. 1247, -- Corinthians (Arena Corinthians)
  133. 1248, -- Flamengo (Estadio do Maracana)
  134. 1249, -- Fluminense (Estadio do Maracana)
  135. 1252, -- SC Internacional (Estadio Beira-Rio)
  136. 1254, -- Santos (Estadio Urbano Caldeira)
  137. 1255, -- Sao Paulo (Estadio do Morumbi)
  138. 1256, -- Colo Colo (Estadio Monumental)
  139. 2209, -- Universidad Chile (Estadio Nacional de Chile)
  140. 2287, -- Alianza Lima (Estadio Alejandro Villanueva)
  141. }
  142. -- END CUSTOMIZABLE LUA TABLE
  143.  
  144.  
  145. local function nil2str(value)
  146. if value ~= nil then
  147. return value
  148. else
  149. return "N/A"
  150. end
  151. end
  152.  
  153. -- log only if detailed logging is required in config.ini
  154. local function _log(msg)
  155. -- are settings available & configured?
  156. if settings and settings["detailed_logging"] then
  157. if settings["detailed_logging"] == 1 then
  158. log(msg)
  159. end
  160. -- fallback to default logging, if not
  161. else
  162. log(msg)
  163. end
  164. end
  165.  
  166. local function load_ini(filename)
  167. local t = {}
  168. local data = assert(io.lines(stadiumroot .. filename))
  169. _log(filename .. " found in " .. stadiumroot)
  170.  
  171. for line in data do
  172. local name, value = string.match(line, "^([%w_]+)%s*=%s*([-%w%d.]+)")
  173. if name and value then
  174. value = tonumber(value) or value
  175. t[name] = value
  176. _log(string.format("Using setting: %s = %s", name, value))
  177. end
  178. end
  179. return t
  180. end
  181.  
  182. local function load_addon_ini(filename)
  183. local t = {}
  184. local data = assert(io.lines(stadiumroot .. filename))
  185. _log(filename .. " found in " .. stadiumroot)
  186.  
  187. for line in data do
  188. local name, value = string.match(line, "^([%w_]+)%s*=%s*([-%w%d_ .]+)")
  189. if name and value then
  190. value = tonumber(value) or value
  191. t[name] = value
  192. _log(string.format("Using add-on mod: %s = %s", name, value))
  193. end
  194. end
  195. return t
  196. end
  197.  
  198. local function save_ini(filename)
  199. local f = io.open(stadiumroot .. filename, "wt")
  200. f:write(string.format("# StadiumServer settings. Generated by StadiumServer.lua\n"))
  201. f:write(string.format("# detailed_logging: 1 = more extensive logging; 0 = bare-bones logging\n"))
  202. f:write("\n")
  203. local keys = {}
  204. for name,value in pairs(settings) do
  205. keys[#keys + 1] = name
  206. end
  207. table.sort(keys)
  208. for i,name in ipairs(keys) do
  209. local value = settings[name]
  210. f:write(string.format("%s = %s\n", name, value))
  211. end
  212. f:write("\n")
  213. f:close()
  214. end
  215.  
  216.  
  217. local function file_exists(name)
  218. local f=io.open(name,"r")
  219. if f~=nil then
  220. io.close(f)
  221. return true
  222. else
  223. return false
  224. end
  225. end
  226.  
  227. -- remove trailing and leading whitespace from string
  228. local function trim(s)
  229. return s:gsub("^%s*(.-)%s*$", "%1")
  230. end
  231.  
  232.  
  233. local function split(s, inSplitPattern)
  234. local outResults = {}
  235. -- chop off the trailing comment, if present
  236. local theCommentStart = string.find( s, "#", 1 )
  237. local data = s
  238. if theCommentStart ~= nil then
  239. data = string.sub(s, 1, theCommentStart-1)
  240. end
  241.  
  242. -- now do the splits by main separator (inSplitPattern)
  243. local theStart = 1
  244. local theSplitStart, theSplitEnd = string.find( data, inSplitPattern, theStart )
  245. while theSplitStart do
  246. outResults[#outResults+1] = trim(string.sub( data, theStart, theSplitStart-1 ))
  247. theStart = theSplitEnd + 1
  248. theSplitStart, theSplitEnd = string.find( data, inSplitPattern, theStart )
  249. end
  250. outResults[#outResults+1] = trim(string.sub( data, theStart ))
  251. return outResults
  252. end
  253.  
  254. local function clear_table(t)
  255. for k,v in pairs(t) do
  256. t[k]=nil
  257. end
  258. end
  259.  
  260. local function dump_table(o)
  261. if type(o) == 'table' then
  262. local s = '{ '
  263. for k,v in pairs(o) do
  264. if type(k) ~= 'number' then k = '"'..k..'"' end
  265. s = s .. '['..k..'] = ' .. dump_table(v) .. ','
  266. end
  267. return s .. '} '
  268. else
  269. return tostring(o)
  270. end
  271. end
  272.  
  273. local function print_arr(tbl)
  274. for index, value in ipairs(tbl) do
  275. log(" " .. value)
  276. end
  277. end
  278.  
  279. local function tableLength(T)
  280. local count = 0
  281. for _ in pairs(T) do
  282. count = count + 1
  283. end
  284. return count
  285. end
  286.  
  287. local function valueArrayExistsInTable(tbl, val, startAt)
  288. for key, value in pairs(tbl) do
  289. if val[startAt] == value[1] and val[startAt+1] == value[2] then
  290. return true
  291. end
  292. end
  293. return false
  294. end
  295.  
  296. local function compare_stadium_names(a,b)
  297. return string.lower(a[2]) < string.lower(b[2]) -- {stadium_ID, stadium_name, stadium_path} triplets, compare names
  298. end
  299.  
  300. local function merge_maps()
  301. local idx = 1
  302. local idx_konami = 1
  303. clear_table(all_stadiums_map)
  304. clear_table(konami_stadiums_map)
  305.  
  306. for key, row in pairs(team_assignment_map) do
  307. if row[1] ~= nil and row[1] ~= "" and row[2] ~= nil and row[2] ~= "" and row[3] ~= nil and row[3] ~= "" and not valueArrayExistsInTable(all_stadiums_map, row, 1) then
  308. all_stadiums_map[idx] = {row[1], row[2], row[3]}
  309. idx = idx + 1
  310. end
  311. end
  312.  
  313. for key, value in pairs(competition_assignment_map) do
  314. for index, row in ipairs(value) do
  315. if row[1] ~= nil and row[1] ~= "" and row[2] ~= nil and row[2] ~= "" and row[3] ~= nil and row[3] ~= "" and not valueArrayExistsInTable(all_stadiums_map, row, 1) then
  316. all_stadiums_map[idx] = {row[1], row[2], row[3]}
  317. idx = idx + 1
  318. if string.match(string.lower(row[3]), "^konami") then -- stadium path begins with Konami ... should be one of the .cpk stadiums
  319. konami_stadiums_map[idx_konami] = {row[1], row[2], row[3] }
  320. idx_konami = idx_konami + 1
  321. end
  322. end
  323. -- see if the stadium for final match is already included ...
  324. if row[4] ~= nil and row[4] ~= "" and row[5] ~= nil and row[5] ~= "" and row[6] ~= nil and row[6] ~= "" and not valueArrayExistsInTable(all_stadiums_map, row, 4) then
  325. all_stadiums_map[idx] = {row[4], row[5], row[6]}
  326. idx = idx + 1
  327. if string.match(string.lower(row[6]), "^konami") then -- stadium path begins with Konami ... should be one of the .cpk stadiums
  328. konami_stadiums_map[idx_konami] = {row[4], row[5], row[6] }
  329. idx_konami = idx_konami + 1
  330. end
  331. end
  332. end
  333. end
  334.  
  335. -- dump_table(konami_stadiums_map)
  336.  
  337. total_stadiums = tableLength(all_stadiums_map)
  338. if total_stadiums > 0 then
  339. manual_stad_idx = 1
  340. end
  341. log(string.format("%s unique stadiums available for random selection in exhibition modes.", total_stadiums))
  342. table.sort(all_stadiums_map, compare_stadium_names)
  343. table.sort(konami_stadiums_map, compare_stadium_names)
  344. end
  345.  
  346. local function load_map_txt(filename)
  347. local delim = ","
  348.  
  349. local data = assert(io.lines(stadiumroot .. filename))
  350. log(filename .. " found in " .. stadiumroot .. filename)
  351.  
  352. if filename == "map_teams.txt" then
  353. clear_table(team_assignment_map)
  354. end
  355. if filename == "map_competitions.txt" then
  356. clear_table(competition_assignment_map)
  357. end
  358.  
  359. for line in data do
  360. line = trim(string.gsub(line, "^\239\187\191", "")) -- removes UTF BOM bytes at the beginning of the first line in .txt file and leading/trailing whitespaces in every line
  361. local fields = split(line, delim)
  362. if #fields > 1 then
  363. for i=1,#fields do
  364. fields[i] = trim(fields[i])
  365. end
  366. if fields[1] ~= nil and fields[1] ~= "" then
  367. if filename == "map_teams.txt" and fields[2] ~= nil and fields[3] ~= nil and fields[4] ~= nil then
  368. team_assignment_map[tonumber(fields[1])] = {fields[2], fields[3], fields[4]}
  369. _log(string.format(" ==> %s stadium assignment:: team_id: %s -> stadium_id: %s, stadium: %s (%s)", filename, fields[1], fields[2], fields[4], fields[3]))
  370. end
  371. if filename == "map_competitions.txt" and fields[2] ~= nil and fields[3] ~= nil and fields[4] ~= nil and fields[5] ~= nil and fields[6] ~= nil and fields[7] ~= nil then
  372. -- competition_assignment_map[tonumber(fields[1])] = {fields[2], fields[3], fields[4], fields[5], fields[6], fields[7]}
  373. if competition_assignment_map[tonumber(fields[1])] ~= nil then
  374. table.insert(competition_assignment_map[tonumber(fields[1])], {fields[2], fields[3], fields[4], fields[5], fields[6], fields[7]})
  375. else
  376. competition_assignment_map[tonumber(fields[1])] = { {fields[2], fields[3], fields[4], fields[5], fields[6], fields[7]} }
  377. end
  378. _log(string.format(" ==> %s stadium assignment:: competition: %s -> stadium_id: %s, stadium: %s (%s) (finals: %s %s (%s))", filename, fields[1], fields[2], fields[4], fields[3], fields[5], fields[7], fields[6]))
  379. end
  380. end
  381. end
  382. end
  383. end
  384.  
  385. local function has_value(tab, val)
  386. for index, value in ipairs(tab) do
  387. if value == val then
  388. return true
  389. end
  390. end
  391. return false
  392. end
  393.  
  394. local function get_random_stad(n)
  395. log("last_choice was: " .. tostring(last_choice))
  396. last_choice = last_choice or math.random(1,n)
  397. log("last_choice now: " .. tostring(last_choice))
  398. return last_choice
  399. end
  400.  
  401. local function select_random_stadium_source(ctx)
  402. local tid = tonumber(ctx.tournament_id)
  403.  
  404. --select random stadium for exhibition mode
  405. random_num_exhib = nil
  406. if tid == 65535 and rnd_server_or_cpk == 1 then
  407. -- if tid == 65535 and ( rnd_server_or_cpk == 1 or rnd_server_or_cpk == 2) then
  408. local tblLen = tableLength(all_stadiums_map)
  409. if tblLen == 1 then
  410. random_num_exhib = 1
  411. else
  412. -- math.randomseed(os.time())
  413. random_num_exhib = get_random_stad(tblLen) -- math.random(1, tblLen)
  414. _log(string.format("Selecting random stadium from stadium server for exhibition mode: %s (%s) ", all_stadiums_map[random_num_exhib][1], all_stadiums_map[random_num_exhib][2]))
  415. end
  416. end
  417.  
  418. --now for competiton modes ... whenever game selects new home_team, pick a random index of a stadium to be used on competition level (e.g. if multiple stadiums are assigned to one competition_ID)
  419. random_num_comp = nil
  420. if tid < 65535 and competition_assignment_map[tid] ~= nil then
  421. if #competition_assignment_map[tid] == 1 then
  422. -- if there's only one stadium assigned to competition, set "random" number to 1
  423. random_num_comp = 1
  424. else
  425. -- if there are more stadiums, select one index rendomly
  426. -- math.randomseed(os.time())
  427. random_num_comp = get_random_stad(#competition_assignment_map[tid]) -- math.random(1, #competition_assignment_map[tid])
  428. _log("Selecting random stadium for competition ID " .. tostring(tid) .. ": Stadium no. " .. tostring(random_num_comp) .. " (from " .. tostring(#competition_assignment_map[tid]) .. " stadium(s) available)")
  429. end
  430. end
  431.  
  432. end
  433.  
  434.  
  435.  
  436. local function teams_selected(ctx, team_id)
  437. local tid = tonumber(ctx.tournament_id)
  438.  
  439. -- set_stadium event is called multiple times ... stadium_switched = false would be better initialized when both team ID's are known???
  440. stadium_switched = false
  441. stadium_name_switched = false
  442. -- first_pass_done = false
  443. last_choice = nil
  444.  
  445. if manual_selection_status == "off" then
  446. manual_selection_status_info = "Selection mode: automatic map assignments"
  447. manual_stad_info = string.format("Manually selected stadium: None")
  448. current_stadium_preview_path = nil
  449. end
  450.  
  451. -- if in-game stadium settings for exhibition modes are set to 'Random', then decide where to choose the stadium from - stadium server or .cpk
  452. --[[
  453. math.randomseed(os.time())
  454. rnd_server_or_cpk = math.random(1, 100)
  455. if rnd_server_or_cpk % 2 == 0 then
  456. rnd_server_or_cpk = 1 -- if even number, use stadium from stadium server
  457. else
  458. rnd_server_or_cpk = 2 -- otherwise if odd, use stadium from .cpk
  459. end
  460. ]]--
  461. -- newer approach, sider 5.1.4 - easier for getting Konami stadium previews, all Konami stadiums must be assigned in map_competitions.txt to ID 0
  462. rnd_server_or_cpk = 1 -- always use stadium server as a source, Konami's stadiums are listed too
  463. _log("If 'Random' in-game setting will be used in exhibition modes:: Source of random stadiums - either stadium server (1) or from .cpk (2): " .. tostring(rnd_server_or_cpk) )
  464.  
  465. end
  466.  
  467.  
  468. local function is_it_stadium_file(filename)
  469. filename = string.lower(filename)
  470.  
  471. if
  472. string.match(filename, "asset\\model\\bg\\common") or -- sweeping match of every gfx-related common asset for stadiums (too generic, perhaps??)
  473. string.match(filename, "asset\\model\\bg\\st%d%d%d") or -- every stadium-specific asset (stXXX)
  474.  
  475. -- adboards? better to avoid them ... only allow custom config.xml database, for stadiums that want to remove adboards completely via blank template
  476. string.match(filename, "common\\bg\\model\\bg\\bill\\config\\config%.xml") or -- adboards config database
  477.  
  478. string.match(filename, "common\\bg\\model\\bg\\draw_parameter") or
  479. string.match(filename, "common\\bg\\model\\bg\\tv") or
  480.  
  481. -- stadium names mentioned in commentary
  482. string.match(filename, "%a%a%a\\sound\\awb\\50_main%.awb") or
  483.  
  484. string.match(filename, "common\\demo\\fixdemo") or
  485. string.match(filename, "common\\demo\\fixdemoobj") or
  486. string.match(filename, "common\\demo\\light") or
  487. string.match(filename, "common\\demo\\mob") or
  488. string.match(filename, "common\\demo\\prop") or
  489.  
  490. string.match(filename, "common\\render\\model\\bg\\hit\\stadium")
  491. then
  492. return true
  493. else
  494. return false
  495. end
  496. end
  497.  
  498. local function which_stadium_preview_tex(filename)
  499. return string.match(string.lower(filename), "common\\render\\thumbnail\\stadium\\(st%d+%.dds)")
  500. end
  501.  
  502. local function get_stadium_preview_path(stadium_info)
  503. if stadium_info then
  504. local stadium_id = stadium_info[1]
  505. local stadium_path = stadium_info[3]
  506. -- log("Overlay preview path: " .. string.format("%s%s\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, stadium_path, stadium_id))
  507. return string.format("%s%s\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, stadium_path, stadium_id)
  508. end
  509. end
  510.  
  511. local function get_new_stadium_path(ctx)
  512. local tid = tonumber(ctx.tournament_id)
  513. local stadium_path
  514. local custom_st_id
  515. local custom_name
  516.  
  517. -- if tid and not ctx.is_replay_gallery then
  518. if tid then
  519. if tid == 65535 then
  520. if manual_selection_status == "On" and manual_stad_idx then
  521. -- manual selection from overlay trumps everything
  522. stadium_path = all_stadiums_map[manual_stad_idx][3]
  523. custom_name = all_stadiums_map[manual_stad_idx][2]
  524. custom_st_id = all_stadiums_map[manual_stad_idx][1]
  525. elseif rnd_server_or_cpk and rnd_server_or_cpk == 1 and ctx.stadium_choice == 254 and random_num_exhib ~= nil then
  526. -- special case for exhibition mode with random stadium selection enabled (stadium from stadium server (rnd_server_or_cpk == 1) ...
  527. stadium_path = all_stadiums_map[random_num_exhib][3]
  528. custom_name = all_stadiums_map[random_num_exhib][2]
  529. custom_st_id = all_stadiums_map[random_num_exhib][1]
  530. elseif rnd_server_or_cpk and rnd_server_or_cpk == 2 and ctx.stadium_choice == 254 then
  531. return -- just leave, random .cpk stadium has been selected in exhibition mode
  532. elseif ctx.stadium_choice == 253 then
  533. if ctx.home_team ~= nil and team_assignment_map[ctx.home_team] ~= nil then
  534. -- individual home team assignments from map_teams.txt will be used here
  535. stadium_path = team_assignment_map[ctx.home_team][3]
  536. custom_name = team_assignment_map[ctx.home_team][2]
  537. custom_st_id = team_assignment_map[ctx.home_team][1]
  538. end
  539. end
  540. else
  541. if manual_selection_status == "On" and manual_stad_idx then
  542. -- manual selection from overlay trumps everything
  543. stadium_path = all_stadiums_map[manual_stad_idx][3]
  544. custom_name = all_stadiums_map[manual_stad_idx][2]
  545. custom_st_id = all_stadiums_map[manual_stad_idx][1]
  546.  
  547. elseif competition_assignment_map[tid] == nil and team_assignment_map[ctx.home_team] ~= nil and has_value(teams_with_cpk_homegrounds, ctx.home_team) == false then
  548. -- this particular competiton mode does not have the stadium assigned via map_competitions.txt
  549. -- .. individual home team assignments from map_teams.txt will be used here, if the team does not already ...
  550. -- .. have exclusive .cpk stadium homeground
  551. stadium_path = team_assignment_map[ctx.home_team][3]
  552. custom_name = team_assignment_map[ctx.home_team][2]
  553. custom_st_id = team_assignment_map[ctx.home_team][1]
  554. elseif competition_assignment_map[tid] ~= nil and team_assignment_map[ctx.home_team] ~= nil and has_value(override_competitions, tid)
  555. and has_value(teams_with_cpk_homegrounds, ctx.home_team) == false and ctx.match_info ~= 53 then
  556. -- this particular competiton mode HAS the stadium assigned via map_competitions.txt,
  557. -- .. but it is also listed in override_competitions,
  558. -- .. AND it is not FINAL match (e.g. in league cup, which may possibly be held at neutral ground - and having stadium assigned already in map_competitions.txt),
  559. -- .. AND the team DOES NOT have .cpk exclusive homeground,
  560. -- .. therefore, individual home team assignments from map_teams.txt will be used here again
  561. stadium_path = team_assignment_map[ctx.home_team][3]
  562. custom_name = team_assignment_map[ctx.home_team][2]
  563. custom_st_id = team_assignment_map[ctx.home_team][1]
  564. else
  565. -- nothing else but possible competition assignment in map_competitions.txt
  566. -- .. stadium from assignment from map_competitions.txt will be used, if there is any
  567. if tid < 65535 and competition_assignment_map[tid] ~= nil then
  568. if ctx.match_info == 53 and competition_assignment_map[tid][random_num_comp][4] ~= "" and competition_assignment_map[tid][random_num_comp][5] ~= "" and competition_assignment_map[tid][random_num_comp][6] ~= "" then
  569. -- is this the final match of a competition (53)?
  570. stadium_path = competition_assignment_map[tid][random_num_comp][6] -- use the stadium assigned for final match
  571. custom_name = competition_assignment_map[tid][random_num_comp][5]
  572. custom_st_id = competition_assignment_map[tid][random_num_comp][4]
  573. elseif has_value(teams_with_cpk_homegrounds, ctx.home_team) == false and
  574. competition_assignment_map[tid][random_num_comp][1] ~= "" and competition_assignment_map[tid][random_num_comp][2] ~= "" and
  575. competition_assignment_map[tid][random_num_comp][3] ~= "" then
  576. stadium_path = competition_assignment_map[tid][random_num_comp][3] -- use the regular stadium assigned for this competition
  577. custom_name = competition_assignment_map[tid][random_num_comp][2]
  578. custom_st_id = competition_assignment_map[tid][random_num_comp][1]
  579. end
  580. end
  581. end
  582. end
  583. --[[
  584. elseif ctx.is_replay_gallery and ctx.is_replay_gallery == true then
  585. if replay_source_stadium_map == "all_stadiums_map" then
  586. stadium_path = all_stadiums_map[replay_source_stadium_key][3]
  587. custom_name = all_stadiums_map[replay_source_stadium_key][2]
  588. custom_st_id = all_stadiums_map[replay_source_stadium_key][1]
  589. elseif replay_source_stadium_map == "team_assignment_map" then
  590. stadium_path = team_assignment_map[replay_source_stadium_key][3]
  591. custom_name = team_assignment_map[replay_source_stadium_key][2]
  592. custom_st_id = team_assignment_map[replay_source_stadium_key][1]
  593. end
  594. ]]--
  595. end
  596.  
  597. return stadium_path, custom_st_id, custom_name
  598. end
  599.  
  600. local function get_stadium_addon_config(ctx, stadium_path)
  601. local t = {}
  602. if file_exists(stadiumroot .. stadium_path .. "\\AddOn\\addon_config.ini") then
  603. t = load_addon_ini(stadium_path .. "\\AddOn\\addon_config.ini")
  604. return t
  605. end
  606. end
  607.  
  608. local function check_for_addon_override(ctx, stadium_path, st_id, filename)
  609. if stadium_path and st_id and filename then
  610. local override_found = false
  611. local weatherPrefix = nil
  612. local weatherTypePrefix = nil
  613. if ctx.season == 0 and ctx.timeofday == 0 then
  614. weatherPrefix = "Summer_Day"
  615. elseif ctx.season == 0 and ctx.timeofday == 1 then
  616. weatherPrefix = "Summer_Night"
  617. elseif ctx.season == 1 and ctx.timeofday == 0 then
  618. weatherPrefix = "Winter_Day"
  619. elseif ctx.season == 1 and ctx.timeofday == 1 then
  620. weatherPrefix = "Winter_Night"
  621. end
  622. if ctx.weather == 0 then
  623. weatherTypePrefix = "Fine"
  624. elseif ctx.weather == 1 then
  625. weatherTypePrefix = "Rainy"
  626. elseif ctx.weather == 2 then
  627. weatherTypePrefix = "Snowy"
  628. end
  629.  
  630. if ctx.stadserv_addons_list then
  631. -- weather-specific files for a specific stadium have priority ...
  632. if override_found == false and weatherPrefix and weatherTypePrefix then
  633. -- fine/rainy/snowy specifics first
  634. for idx_key, mod_name in pairs(ctx.stadserv_addons_list) do
  635. if file_exists(stadiumroot .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\" .. st_id .. "\\" .. weatherPrefix .. "\\" .. weatherTypePrefix .. "\\".. filename) then
  636. _log("Weather-type-specific, fixed-stadium AddOn file found: " .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\" .. weatherPrefix .. "\\" .. weatherTypePrefix .. "\\" .. filename )
  637. stadium_path = stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\" .. weatherPrefix .. "\\" .. weatherTypePrefix
  638. -- _log("stadium_path (weather-type-specific): " .. stadium_path)
  639. override_found = true
  640. break
  641. end
  642. end
  643. -- if not fine/rain/snowy, then fallback to weather-specific that considers only season and time of day
  644. if override_found == false then
  645. for idx_key, mod_name in pairs(ctx.stadserv_addons_list) do
  646. if file_exists(stadiumroot .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\" .. st_id .. "\\" .. weatherPrefix .. "\\" .. filename) then
  647. _log("Weather-specific, fixed-stadium AddOn file found: " .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\" .. weatherPrefix .. "\\" .. filename )
  648. stadium_path = stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\" .. weatherPrefix
  649. -- _log("stadium_path (weather-specific): " .. stadium_path)
  650. override_found = true
  651. break
  652. end
  653. end
  654. -- if not weather-specific, then perhaps there is a non weather-specific version of a file for a specific stadium id?
  655. if override_found == false then
  656. -- fine/rainy/snowy specifics first
  657. for idx_key, mod_name in pairs(ctx.stadserv_addons_list) do
  658. if file_exists(stadiumroot .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\Any_Weather\\" .. weatherTypePrefix .. "\\".. filename) then
  659. _log("Any-weather (type-specific), fixed-stadium AddOn file found: " .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\Any_Weather\\" .. weatherTypePrefix .. "\\".. filename )
  660. stadium_path = stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id.. "\\Any_Weather\\" .. weatherTypePrefix
  661. -- _log("stadium_path (any-weather, type-specific): " .. stadium_path)
  662. override_found = true
  663. break
  664. end
  665. end
  666. -- if not fine/rain/snowy, then fallback to any-weather
  667. if override_found == false then
  668. for idx_key, mod_name in pairs(ctx.stadserv_addons_list) do
  669. if file_exists(stadiumroot .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\Any_Weather\\" .. filename) then
  670. _log("Any-weather, fixed-stadium AddOn file found: " .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id .. "\\Any_Weather\\" .. filename )
  671. stadium_path = stadium_path .. "\\AddOn\\" .. mod_name .. "\\".. st_id.. "\\Any_Weather"
  672. -- _log("stadium_path (any-weather): " .. stadium_path)
  673. override_found = true
  674. break
  675. end
  676. end
  677.  
  678. -- if not non-weather fixed-stadium file too, then perhaps there is a generic version of a file for any weather and any stadium id?
  679. if override_found == false then
  680. for idx_key, mod_name in pairs(ctx.stadserv_addons_list) do
  681. if file_exists(stadiumroot .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\Global\\" .. filename) then
  682. _log("Global AddOn file found: " .. stadium_path .. "\\AddOn\\" .. mod_name .. "\\Global\\" .. filename )
  683. stadium_path = stadium_path .. "\\AddOn\\" .. mod_name .. "\\Global"
  684. -- _log("stadium_path (global): " .. stadium_path)
  685. break
  686. end
  687. end
  688.  
  689. -- if not stadium/pack-global file too, then perhaps there is a uber-generic version of a file for an entire stadium server?
  690. if override_found == false then
  691. if file_exists(stadiumroot .. "\\Super-Global\\" .. filename) then
  692. _log("StadiumServer-Global AddOn file found: " .. "Super-Global\\" .. filename )
  693. stadium_path = "\\Super-Global"
  694. -- _log("stadium_path (super-global): " .. stadium_path)
  695. end
  696. end
  697. end
  698. end
  699. end
  700. end
  701. end
  702. end
  703.  
  704. end
  705.  
  706. return stadium_path
  707.  
  708. end
  709.  
  710. local function make_key(ctx, filename)
  711. local custom_st_id
  712. local custom_name
  713. -- if ctx.is_edit_mode == nil and stadium_switched == true then -- do something only if edit mode is NOT active
  714. if stadium_switched == true then
  715. if is_it_stadium_file(filename) then -- any stadium file, but preview
  716. local new_stadium_path
  717. local custom_st_id
  718. local custom_name
  719. new_stadium_path, custom_st_id, custom_name = get_new_stadium_path(ctx)
  720. if new_stadium_path and custom_st_id then
  721. -- if new_stadium_path and custom_st_id and file_exists(stadiumroot .. new_stadium_path .. "\\" .. filename) then
  722. -- log(string.format("new_stadium_path: %s", new_stadium_path .. "\\" .. filename))
  723. if string.match(string.lower(filename), "common\\bg\\model\\bg\\bill\\config\\config.xml") then
  724. if file_exists(stadiumroot .. new_stadium_path .. "\\" .. filename) then
  725. log("Custom adboards config.xml found: " .. new_stadium_path .. "\\" .. filename)
  726. end
  727. end
  728. -- let's check for possible AddOn files ...
  729. new_stadium_path = check_for_addon_override(ctx, new_stadium_path, custom_st_id, filename)
  730.  
  731. return new_stadium_path .. "\\" .. filename
  732. end
  733. end
  734. -- now override the preview, if the stadium has already been predetermined by the game
  735. local spt_fname = which_stadium_preview_tex(filename)
  736. if spt_fname then
  737. local new_stadium_path
  738. local custom_st_id
  739. local custom_name
  740. new_stadium_path, custom_st_id, custom_name = get_new_stadium_path(ctx)
  741. if new_stadium_path then
  742. return string.gsub(new_stadium_path .. "\\" .. filename, "\\st%d%d%d%.dds", string.format("\\st%s.dds", custom_st_id))
  743. end
  744. end
  745. end
  746. end
  747.  
  748. local function get_filepath(ctx, filename, key)
  749. -- if ctx.is_edit_mode == nil then -- do something only if edit mode is NOT active
  750.  
  751. if key and filename and filename ~= key then -- filename ~= key shoud ensure that it really is a file from custom repository, with modified path prefix???
  752. -- log(string.format("Stadium file assignment for team ID %s (competition ID %s) - %s\\%s", nil2str(ctx.home_team), nil2str(ctx.tournament_id), stadiumroot, key))
  753. return string.format("%s\\%s", stadiumroot, key)
  754. end
  755. -- end
  756. end
  757.  
  758.  
  759. local function get_stadium_data_from_konami_stadiums_map(stadium_id)
  760. if stadium_id then
  761. for key, value in pairs(konami_stadiums_map) do
  762. if value[1] == string.format("%03d", stadium_id) then
  763. return value[2], value[3]
  764. end
  765. end
  766. end
  767. end
  768.  
  769. -- this event allows only stadium_id to be changed in options!! other params are read-only (time of day/weather/weather effects/season)
  770. local function set_stadium(ctx, options)
  771. random_num_exhib = nil
  772. random_num_comp = nil
  773.  
  774. -- if ctx.is_edit_mode == nil and ctx.tournament_id then
  775. -- if ctx.tournament_id and first_pass_done == true then
  776. if ctx.tournament_id then
  777. local tid = tonumber(ctx.tournament_id)
  778. local custom_st_id
  779. local custom_name
  780. local custom_path
  781. local map_source
  782.  
  783. if tid == 65535 then
  784. if manual_selection_status == "On" and manual_stad_idx then
  785. -- manual selection from overlay trumps everything
  786. custom_st_id = all_stadiums_map[manual_stad_idx][1]
  787. custom_name = all_stadiums_map[manual_stad_idx][2]
  788. custom_path = all_stadiums_map[manual_stad_idx][3]
  789. stadium_switched = true
  790. log("Switching to stadium with ID " .. custom_st_id .. " (exhibition mode, manual selection via overlay)")
  791. elseif ctx.stadium_choice and ctx.stadium_choice ~= 253 and ctx.stadium_choice ~= 254 then
  792. -- exhibition modes, and the choice is neither "Home stadium" nor "Random" (i.e. - the choice is fixed stadium)
  793. -- therefore, do not change the stadium
  794. return
  795. elseif ctx.stadium_choice and ctx.stadium_choice == 253 and has_value(teams_with_cpk_homegrounds, ctx.home_team) then
  796. -- exhibition modes, the choice is "Home", but the team is listed to use exclusive .cpk home ground
  797. -- therefore, do not change the stadium
  798. return
  799. elseif ctx.stadium_choice and ctx.stadium_choice == 253 then
  800. -- handle home team assignment via map_teams.txt
  801. if manual_selection_status == "On" and manual_stad_idx then
  802. -- manual selection from overlay trumps everything
  803. custom_st_id = all_stadiums_map[manual_stad_idx][1]
  804. custom_name = all_stadiums_map[manual_stad_idx][2]
  805. custom_path = all_stadiums_map[manual_stad_idx][3]
  806. stadium_switched = true
  807. log("Switching to stadium with ID " .. custom_st_id .. " (exhibition mode, manual selection via overlay)")
  808. elseif ctx.home_team ~= nil and team_assignment_map[ctx.home_team] ~= nil then
  809. custom_st_id = team_assignment_map[ctx.home_team][1]
  810. custom_name = team_assignment_map[ctx.home_team][2]
  811. custom_path = team_assignment_map[ctx.home_team][3]
  812. stadium_switched = true
  813. map_source = "exhibition mode, team-level assignment"
  814. log("Switching to stadium with ID " .. custom_st_id .. " (exhibition mode, team-level assignment)")
  815. end
  816. elseif ctx.stadium_choice and ctx.stadium_choice == 254 then
  817. -- exhibition modes, the choice is "Random"
  818. -- change the stadium depending on the value of rnd_server_or_cpk
  819. -- select_random_stadium_source(ctx)
  820. if rnd_server_or_cpk then
  821. if rnd_server_or_cpk == 2 then
  822. -- if .cpk is the source (rnd_server_or_cpk == 2), do not change the stadium
  823. select_random_stadium_source(ctx)
  824. map_source = "exhibition mode, random assignment (stadium from .cpk selected)"
  825. manual_selection_status_info = string.format("Selection mode: %s)", map_source)
  826. return
  827. else
  828. -- Random setting in exhibition modes, stadium server is the source - always allow for random selection, even if the team has exclusive .cpk home ground
  829. select_random_stadium_source(ctx)
  830. custom_st_id = all_stadiums_map[random_num_exhib][1]
  831. custom_name = all_stadiums_map[random_num_exhib][2]
  832. custom_path = all_stadiums_map[random_num_exhib][3]
  833. stadium_switched = true
  834. -- map_source = "exhibition mode, random assignment (stadium from stadium-server selected)"
  835. map_source = "exhibition mode, random assignment"
  836. -- log("Switching to stadium with ID " .. custom_st_id .. " (" .. custom_name .. ")" .. " exhibition mode, random assignment (stadium from stadium-server selected)")
  837. log("Switching to stadium with ID " .. custom_st_id .. " (" .. custom_name .. ")" .. " exhibition mode, random assignment")
  838. end
  839. end
  840. end
  841. else
  842. if manual_selection_status == "On" and manual_stad_idx then
  843. -- manual selection from overlay trumps everything
  844. custom_st_id = all_stadiums_map[manual_stad_idx][1]
  845. custom_name = all_stadiums_map[manual_stad_idx][2]
  846. custom_path = all_stadiums_map[manual_stad_idx][3]
  847. stadium_switched = true
  848. log("Switching to stadium with ID " .. custom_st_id .. " (competition mode, manual selection via overlay)")
  849. elseif ctx.home_team ~= nil and competition_assignment_map[tid] == nil and team_assignment_map[ctx.home_team] ~= nil then
  850. custom_st_id = team_assignment_map[ctx.home_team][1]
  851. custom_name = team_assignment_map[ctx.home_team][2]
  852. custom_path = team_assignment_map[ctx.home_team][3]
  853. stadium_switched = true
  854. map_source = "competition mode, team-level assignment"
  855. log("Switching to stadium with ID " .. custom_st_id .. " (competition mode, team-level assignment)")
  856. elseif ctx.home_team ~= nil and competition_assignment_map[tid] ~= nil and team_assignment_map[ctx.home_team] ~= nil and has_value(override_competitions, tid) == true and ctx.match_info ~= 53 then
  857. -- comptition assignment will be overriden by team assignment
  858. custom_st_id = team_assignment_map[ctx.home_team][1]
  859. custom_name = team_assignment_map[ctx.home_team][2]
  860. custom_path = team_assignment_map[ctx.home_team][3]
  861. stadium_switched = true
  862. map_source = "competition mode, team-level assignment (overrides competition-level assignment)"
  863. log("Switching to stadium with ID " .. custom_st_id .. " (competition mode, team-level assignment (overrides competition-level assignment))")
  864. elseif tid < 65535 and competition_assignment_map[tid] ~= nil then
  865. select_random_stadium_source(ctx)
  866. if ctx.match_info == 53 and competition_assignment_map[tid][random_num_comp][4] ~= "" and competition_assignment_map[tid][random_num_comp][5] ~= "" and competition_assignment_map[tid][random_num_comp][6] ~= "" then
  867. -- is this the final match of a competition (53)?
  868. custom_st_id = competition_assignment_map[tid][random_num_comp][4]
  869. custom_name = competition_assignment_map[tid][random_num_comp][5]
  870. custom_path = competition_assignment_map[tid][random_num_comp][6]
  871. stadium_switched = true
  872. map_source = "competition mode (final match), competition-level assignment"
  873. log("Switching to stadium with ID " .. custom_st_id .. " (competition mode (final match of the competition), competition-level assignment)")
  874. else
  875. if has_value(teams_with_cpk_homegrounds, ctx.home_team) == false and competition_assignment_map[tid][random_num_comp][1] ~= "" and competition_assignment_map[tid][random_num_comp][2] ~= "" and competition_assignment_map[tid][random_num_comp][3] ~= "" then
  876. -- competition mode, pre-finals, no exclusive .cpk home ground -> change the stadium
  877. custom_st_id = competition_assignment_map[tid][random_num_comp][1]
  878. custom_name = competition_assignment_map[tid][random_num_comp][2]
  879. custom_path = competition_assignment_map[tid][random_num_comp][3]
  880. stadium_switched = true
  881. map_source = "competition mode, competition-level assignment"
  882. log("Switching to stadium with ID " .. custom_st_id .. " (competition mode (pre-finals stage of the competition), competition-level assignment)")
  883. end
  884. end
  885. end
  886.  
  887. end
  888.  
  889. if stadium_switched == true then
  890. -- get_stadium_config(ctx)
  891. ctx.stadserv_addons_list = get_stadium_addon_config(ctx, custom_path) or {}
  892. --log("After get_stadium_addon_config - addons_list dump: ")
  893. --for k, v in pairs(ctx.stadserv_addons_list) do
  894. -- log(k.. ": " .. v)
  895. --end
  896. if manual_selection_status == "Off" then
  897. if custom_name then
  898. manual_selection_status_info = string.format("Selection mode: automatic map assignments (using stadium %s, %s)", custom_name, map_source)
  899. elseif not custom_name then
  900. manual_selection_status_info = string.format("Selection mode: %s)", map_source)
  901. end
  902. end
  903. if custom_st_id and custom_path then
  904. _stadium_info[1] = custom_st_id
  905. _stadium_info[2] = custom_name
  906. _stadium_info[3] = custom_path
  907. current_stadium_preview_path = get_stadium_preview_path(_stadium_info)
  908. _log("current_stadium_preview_path: " .. current_stadium_preview_path)
  909. end
  910. return { stadium = tonumber(custom_st_id) } -- Stadium id of the served stadium
  911. else
  912. current_stadium_preview_path = nil
  913. if manual_selection_status == "Off" then
  914. if ctx.stadium_choice and ctx.stadium_choice == 254 and rnd_server_or_cpk and rnd_server_or_cpk == 2 then
  915. manual_selection_status_info = string.format("Selection mode: %s)", map_source)
  916. else
  917. manual_selection_status_info = string.format("Selection mode: automatic map assignments (using stadium: %s)", "Custom stadium not assigned, reverting to default")
  918. end
  919. end
  920. end
  921. -- elseif ctx.tournament_id and first_pass_done == false then
  922. -- first_pass_done = true
  923. end
  924. end
  925.  
  926.  
  927. local function change_gfx_preview_fallback(ctx)
  928. -- bound to after_set_conditions event -- use it only for matches where .cpk stadiums are used, to override potentialy old data
  929. -- or not only when .cpk stadiums are used? competition mode seems to fall back erroneously to generic ".cpk stadium" and no preview too often
  930. local custom_name
  931. local custom_path
  932. local tid = ctx.tournament_id
  933.  
  934. if tid == 65535 and ctx.stadium_choice and ctx.stadium_choice ~= 253 and ctx.stadium_choice ~= 254 then
  935. -- exhibition modes, and the choice is neither "Home stadium" nor "Random" (i.e. - the choice is fixed stadium)
  936. custom_name, custom_path = get_stadium_data_from_konami_stadiums_map(ctx.stadium_choice)
  937. if custom_name and custom_path then
  938. current_stadium_preview_path = string.format("%s%s\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, custom_path, ctx.stadium_choice)
  939. manual_selection_status_info = string.format("Selection mode: exhibition mode (%s: %s)", "Fixed stadium from in-game menu", custom_name)
  940. else
  941. manual_selection_status_info = string.format("Selection mode: exhibition mode (using stadium: %s)", "Fixed stadium from in-game menu")
  942. current_stadium_preview_path = nil
  943. end
  944. elseif tid == 65535 and ctx.stadium_choice and ctx.stadium_choice == 253 and has_value(teams_with_cpk_homegrounds, ctx.home_team) then
  945. -- exhibition modes, the choice is "Home", but the team is listed to use exclusive .cpk home ground
  946. custom_name, custom_path = get_stadium_data_from_konami_stadiums_map(ctx.stadium)
  947. if custom_name and custom_path then
  948. current_stadium_preview_path = string.format("%s%s\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, custom_path, ctx.stadium)
  949. manual_selection_status_info = string.format("Selection mode: exhibition mode (%s: %s)", "Exclusive .cpk homeground", custom_name)
  950. else
  951. manual_selection_status_info = string.format("Selection mode: exhibition mode (using stadium: %s)", "Exclusive .cpk homeground")
  952. current_stadium_preview_path = nil
  953. end
  954.  
  955.  
  956. elseif tid < 65535 and competition_assignment_map[tid] == nil and team_assignment_map[ctx.home_team] ~= nil and has_value(teams_with_cpk_homegrounds, ctx.home_team) == false then
  957. -- this particular competiton mode does not have the stadium assigned via map_competitions.txt
  958. -- .. individual home team assignments from map_teams.txt has been used for that team, unless the team already ...
  959. -- .. has exclusive .cpk stadium homeground
  960.  
  961. -- do nothing, simply return (correct data was probably displayed and then overridden by generic ".cpk stadium" and no preview
  962. return
  963.  
  964. elseif tid < 65535 and competition_assignment_map[tid] ~= nil and team_assignment_map[ctx.home_team] ~= nil and has_value(override_competitions, tid)
  965. and has_value(teams_with_cpk_homegrounds, ctx.home_team) == false and ctx.match_info ~= 53 then
  966. -- this particular competiton mode HAS the stadium assigned via map_competitions.txt,
  967. -- .. but it is also listed in override_competitions,
  968. -- .. AND it is not FINAL match (e.g. in league cup, which may possibly be held at neutral ground - and having stadium assigned already in map_competitions.txt),
  969. -- .. AND the team DOES NOT have .cpk exclusive homeground,
  970. -- .. therefore, individual home team assignments from map_teams.txt has been used for that team again
  971.  
  972. -- do nothing, simply return (correct data was probably displayed and then overridden by generic ".cpk stadium" and no preview
  973. return
  974.  
  975.  
  976.  
  977. elseif tid < 65535 and competition_assignment_map[tid] == nil then
  978. -- no assignment for home team, no assignment to competition ... one of the default .cpk stadiums was probably selected
  979. -- just handle the preview and name on overlay
  980. custom_name, custom_path = get_stadium_data_from_konami_stadiums_map(ctx.stadium)
  981. if custom_name and custom_path then
  982. current_stadium_preview_path = string.format("%s%s\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, custom_path, ctx.stadium)
  983. manual_selection_status_info = string.format("Selection mode: competition mode (%s: %s)", ".cpk stadium", custom_name)
  984. else
  985. manual_selection_status_info = string.format("Selection mode: competition mode (using stadium: %s)", ".cpk stadium")
  986. current_stadium_preview_path = nil
  987. end
  988. elseif tid < 65535 and competition_assignment_map[tid] ~= nil and has_value(teams_with_cpk_homegrounds, ctx.home_team) and ctx.match_info ~= 53 then
  989. -- competition has assignments, but home team uses exclusive .cpk home ground ... one of the default .cpk stadiums is selected
  990. -- just handle the preview and name on overlay
  991. custom_name, custom_path = get_stadium_data_from_konami_stadiums_map(ctx.stadium)
  992. if custom_name and custom_path then
  993. current_stadium_preview_path = string.format("%s%s\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, custom_path, ctx.stadium)
  994. manual_selection_status_info = string.format("Selection mode: competition mode (%s: %s)", "Exclusive .cpk homeground", custom_name)
  995. else
  996. manual_selection_status_info = string.format("Selection mode: competition mode (using stadium: %s)", "Exclusive .cpk homeground")
  997. current_stadium_preview_path = nil
  998. end
  999.  
  1000. end
  1001.  
  1002. end
  1003.  
  1004.  
  1005. local function change_stadium_name(ctx, stadium_name, stadium_id)
  1006. -- if ctx.is_edit_mode == nil then -- do something only if edit mode is NOT active
  1007. if ctx.tournament_id then -- ctx.tournament_id should not be available in EDIT mode ...
  1008. if ctx.stadium_choice and ctx.tournament_id == 65535 and not stadium_switched then
  1009. -- if it is exhibition mode and stadium selection has not been finalized yet ==> then do nothing.
  1010. return
  1011. end
  1012.  
  1013. local new_stadium_path
  1014. local custom_st_id
  1015. local new_stadium_name
  1016.  
  1017. new_stadium_path, custom_st_id, new_stadium_name = get_new_stadium_path(ctx)
  1018. if new_stadium_name ~= nil and new_stadium_name ~= "" then
  1019. _log(string.format("switching stadium-name: %s --> %s", stadium_name, new_stadium_name))
  1020. stadium_name_switched = true
  1021. return new_stadium_name
  1022. end
  1023. end
  1024. end
  1025.  
  1026. local function set_weather_conditions(ctx, options)
  1027. local changed = false
  1028. local external_opts = nil
  1029.  
  1030. -- initial check if season is set via overlay - WeatherConditions.lua makes decisions based on season
  1031. if weather_Season > 0 then
  1032. options.season = weather_Season - 1
  1033. end
  1034.  
  1035. -- delegate weather decisions to WeatherConditions module
  1036. if file_exists(ctx.sider_dir .. "\\modules\\WeatherConditions.lua") and ctx.weather_conditions then
  1037. _log("StadiumServer calling WeatherConditions ... ")
  1038. external_opts = ctx.weather_conditions.set_conditions(ctx, options, "StadiumServer")
  1039. if external_opts then
  1040. changed = true
  1041. options = external_opts
  1042. end
  1043. _log("StadiumServer finished calling WeatherConditions.")
  1044. else
  1045. log("WeatherConditions.lua script not found or its' weather_conditions context is not available ...")
  1046. log("Script path: " .. ctx.sider_dir .. "\\modules\\WeatherConditions.lua")
  1047. log("ctx.weather_conditions status: " .. nil2str(ctx.weather_conditions))
  1048. end
  1049.  
  1050. -- and now override options returned from WeatherConditions.lua, if non-default settings are selected via stadium-server's overlay
  1051. if weather_TimeOfDay > 0 then
  1052. options.timeofday = weather_TimeOfDay - 1
  1053. changed = true
  1054. end
  1055. if weather_Weather > 0 then
  1056. options.weather = weather_Weather - 1
  1057. changed = true
  1058. end
  1059. if weather_WeatherEffects > 0 then
  1060. options.weather_effects = weather_WeatherEffects - 1
  1061. changed = true
  1062. end
  1063. if weather_Season > 0 then
  1064. options.season = weather_Season - 1
  1065. changed = true
  1066. end
  1067.  
  1068. if changed then
  1069. return options
  1070. end
  1071.  
  1072. end
  1073.  
  1074. local opts = { image_width = 0.3, image_aspect_ratio = 1.777778 }
  1075. local function overlay_on(ctx)
  1076. weather_text = string.format("Weather settings: Time of day (%s), Type of weather (%s), Force rain/snow (%s), Season (%s)\n",
  1077. weather_TimeOfDay_Info[tostring(weather_TimeOfDay)],
  1078. weather_Weather_Info[tostring(weather_Weather)],
  1079. weather_WeatherEffects_Info[tostring(weather_WeatherEffects)],
  1080. weather_Season_Info[tostring(weather_Season)]
  1081. )
  1082.  
  1083. local text = string.format("version %s\nStadiumServer commands:\nPress [0] to reload map .txt files\nPress [DEL] to clear info messages\n\nWeather options (always active, unless set to 'Default'):\n [3] To select time of day\n [4] To select type of weather\n [5] To enforce rain/snow\n [6] To select season of the year\n %s\nPress [9] to switch between using map assignments/manual selection\n Manual selection mode subcommands:\n [PageUp][PageDn] to manually select previous/next stadium\n [7] to set current manual selection as favorite stadium\n [8] to use your favorite stadium \n\n%s\n%s\n\n%s", version, weather_text, manual_selection_status_info, manual_stad_info, info_text)
  1084. local image = current_stadium_preview_path
  1085. -- if image and ctx.stadium and not file_exists(current_stadium_preview_path) then
  1086. -- let's try with super-global folder, for Konami's .cpk stadium previews
  1087. -- current_stadium_preview_path = string.format("%s\\Super-Global\\common\\render\\thumbnail\\stadium\\st%03d.dds", stadiumroot, ctx.stadium)
  1088. -- end
  1089.  
  1090. return text, image, opts
  1091. end
  1092.  
  1093. local function key_down(ctx, vkey)
  1094. if vkey == RELOAD_MAPS_KEY then
  1095. _log("Starting manual map files reload ... ")
  1096. load_map_txt("map_teams.txt")
  1097. load_map_txt("map_competitions.txt")
  1098. merge_maps()
  1099. manual_stad_idx = nil
  1100. manual_stad_info = "Manually selected stadium: None"
  1101. if total_stadiums > 0 then
  1102. manual_stad_idx = 1
  1103. end
  1104. info_text = info_text .. "map_teams.txt and map_competitions.txt reloaded\n"
  1105. _log("Manual map files reloading finished.")
  1106. elseif vkey == DEL_TEXT_KEY then
  1107. info_text = ""
  1108. elseif vkey == SWITCH_SELECTION_MODE_KEY then
  1109. if manual_selection_status == "Off" then
  1110. manual_selection_status = "On"
  1111. manual_selection_status_info = "Selection mode: manual selection [PageUp]/[PageDn]"
  1112. manual_stad_info = string.format("Manually selected stadium: %s\n", all_stadiums_map[manual_stad_idx][2])
  1113. current_stadium_preview_path = get_stadium_preview_path(all_stadiums_map[manual_stad_idx])
  1114. else
  1115. manual_selection_status = "Off"
  1116. manual_selection_status_info = "Selection mode: automatic map assignments"
  1117. manual_stad_info = string.format("Manually selected stadium: None")
  1118. info_text = ""
  1119. current_stadium_preview_path = nil
  1120. end
  1121. elseif vkey == PREVIOUS_STAD_KEY then
  1122. if manual_selection_status == "On" and total_stadiums > 0 and manual_stad_idx then
  1123. manual_stad_idx = manual_stad_idx - 1
  1124. if manual_stad_idx < 1 then
  1125. manual_stad_idx = total_stadiums
  1126. end
  1127. manual_stad_info = string.format("Manually selected stadium: %s\n", all_stadiums_map[manual_stad_idx][2])
  1128. current_stadium_preview_path = get_stadium_preview_path(all_stadiums_map[manual_stad_idx])
  1129. end
  1130. elseif vkey == NEXT_STAD_KEY then
  1131. if manual_selection_status == "On" and total_stadiums > 0 and manual_stad_idx then
  1132. manual_stad_idx = manual_stad_idx + 1
  1133. if manual_stad_idx > total_stadiums then
  1134. manual_stad_idx = 1
  1135. end
  1136. manual_stad_info = string.format("Manually selected stadium: %s\n", all_stadiums_map[manual_stad_idx][2])
  1137. current_stadium_preview_path = get_stadium_preview_path(all_stadiums_map[manual_stad_idx])
  1138. end
  1139. elseif vkey == SET_AS_FAVORITE_STAD_KEY then
  1140. if manual_selection_status == "On" and manual_stad_idx then
  1141. if all_stadiums_map[manual_stad_idx] then
  1142. settings["favorite_stadium"] = manual_stad_idx
  1143. save_ini("config.ini")
  1144. info_text = info_text .. string.format("Stadium %s saved as favorite\n", all_stadiums_map[manual_stad_idx][2])
  1145. else
  1146. info_text = info_text .. "Could not save favorite stadium\n"
  1147. end
  1148. end
  1149. elseif vkey == USE_FAVORITE_STAD_KEY then
  1150. if manual_selection_status == "On" and settings["favorite_stadium"] then
  1151. if all_stadiums_map[tonumber(settings["favorite_stadium"])] then
  1152. manual_stad_idx = settings["favorite_stadium"]
  1153. manual_stad_info = string.format("Manually selected stadium: %s\n", all_stadiums_map[manual_stad_idx][2])
  1154. info_text = info_text .. string.format("Favorite stadium %s set as active\n", all_stadiums_map[manual_stad_idx][2])
  1155. current_stadium_preview_path = get_stadium_preview_path(all_stadiums_map[manual_stad_idx])
  1156. else
  1157. info_text = info_text .. string.format("Could not find favorite stadium (idx: %s)\n", settings["favorite_stadium"])
  1158. end
  1159. end
  1160. elseif vkey == WEATHER_TIMEOFDAY_KEY then
  1161. weather_TimeOfDay = weather_TimeOfDay + 1
  1162. if weather_TimeOfDay > 2 then
  1163. weather_TimeOfDay = 0
  1164. end
  1165. elseif vkey == WEATHER_WEATHER_KEY then
  1166. weather_Weather = weather_Weather + 1
  1167. if weather_Weather > 3 then
  1168. weather_Weather = 0
  1169. end
  1170. elseif vkey == WEATHER_WEATHER_EFFECTS_KEY then
  1171. if weather_WeatherEffects == 0 then
  1172. weather_WeatherEffects = 3
  1173. else
  1174. weather_WeatherEffects = 0
  1175. end
  1176. elseif vkey == WEATHER_SEASON_KEY then
  1177. weather_Season = weather_Season + 1
  1178. if weather_Season > 2 then
  1179. weather_Season = 0
  1180. end
  1181. end
  1182.  
  1183. end
  1184.  
  1185. local function init(ctx)
  1186. if stadiumroot:sub(1,1)=='.' then
  1187. stadiumroot = ctx.sider_dir .. stadiumroot
  1188. end
  1189. math.randomseed(os.time())
  1190. settings = load_ini("config.ini")
  1191. load_map_txt("map_teams.txt")
  1192. load_map_txt("map_competitions.txt")
  1193. merge_maps() -- create one master-table, which is going to have one entry for every stadium assigned - either via teams or competitions
  1194.  
  1195. ctx.register("set_stadium", set_stadium)
  1196. ctx.register("set_conditions", set_weather_conditions)
  1197. ctx.register("get_stadium_name", change_stadium_name)
  1198. ctx.register("livecpk_make_key", make_key)
  1199. ctx.register("livecpk_get_filepath", get_filepath)
  1200. ctx.register("set_teams", teams_selected)
  1201. ctx.register("overlay_on", overlay_on)
  1202. ctx.register("key_down", key_down)
  1203. ctx.register("after_set_conditions", change_gfx_preview_fallback)
  1204. end
  1205.  
  1206. return { init = init }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement