/** * Script to add achievements in-game. Player who reaches first XX points wins. */ /// specify the savegame to load map.file = "online.sve" /// short description to be shown in finance window /// and in standard implementation of get_about_text scenario.short_description = "Regions" scenario.author = "dwachs and Yona-TYT" scenario.version = "4.7" scenario.translation <- "Yona-TYT" const save_version = 1 //Coordenadas para eliminar construcciones removercoord <- [{x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}, {x=null, y=null, z=null}] //Coordenadas para aƱadir construcciones addcoord <- [{x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}, {x1=null, y1=null, z1=null, x2=null, y2=null, z2=null, px=null, py=null}] savetxt <- [(""),(""),(""),(""),(""),(""),(""),(""),(""),(""),(""),("")] remover <- null build <- [{way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0}, {way=null, waycont=0, pw=null, pwcont=0} ] pwcoord <-[{cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}, {cxa1=null,cya1=null, cxa2=null, cya2=null, cxa3=null, cya3=null, cxa4=null, cya4=null, cxb1=null,cyb1=null, cxb2=null, cyb2=null, cxb3=null, cyb3=null, cxb4=null, cyb4=null}] clime <- null climesw <- null globtool <- null swcl <- null swnr <- null shared <- null swpl <- [{sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null}, {sw=null} ] // waytype handling all_waytypes <- [wt_road, wt_rail, wt_water, wt_monorail, wt_maglev, wt_tram, wt_narrowgauge, wt_air] max_waytypes <- all_waytypes.reduce(max) +1 vehicle_names <- array(max_waytypes) vehicle_names[wt_road] = translate("buses and trucks") vehicle_names[wt_rail] = translate("trains") vehicle_names[wt_water] = translate("ships") vehicle_names[wt_monorail] = translate("monorail trains") vehicle_names[wt_maglev] = translate("futuristic maglevs") vehicle_names[wt_tram] = translate("trams") vehicle_names[wt_narrowgauge] = translate("narrow gauge trains") vehicle_names[wt_air] = translate("planes") include("regions") // helper function function save_coord(p) { return "{x="+p.x+",y="+p.y+",z="+p.z+"}"; } // current standing - calculated current_standing_text <- "" function get_info_text(pl) { local info = ttextfile("info.txt") local text = ttext("") local plnr = null local plsave = null local num = totalpl[0].tl if (totalpl[0].tl==null)num=12 if ((pl-2)("+(coord_label1[pl-2].x )+"," + ""+coord_label1[pl-2].y+")
") info.sreg = ttext(savetxt[pl-2] + translate("Reload using remove tool here") + " ("+(coord_label1[pl-2].x + 2)+"," + ""+coord_label1[pl-2].y+") .") } else info.sreg = ttext("") info.cs = ttext(current_standing_text) info.gp = ttext(get_player_text(pl,"")) return info.tostring() } function get_rule_text(pl) { local num = totalpl[0].tl if (totalpl[0].tl==null)num=12 local rule = ttextfile("rule.txt") if (pl==1) rule = ttextfile("rule_pub.txt") if (pl==1){rule.st1pub = ttext("" + translate("Text label") + " ("+(coord_label1pub[0].x )+"," + ""+coord_label1pub[0].y+") ")} if ((pl-2)" + translate("Text label") + " ("+(coord_label1[pl-2].x )+"," + ""+coord_label1[pl-2].y+") ") else rule.label1 = ttext(translate("Text label")) if ((pl-2)" + " ("+(coord_label1[pl-2].x + 1)+"," + ""+coord_label1[pl-2].y+") ") else rule.point = ttext("(x,y)") return rule.tostring() } // results for active players - calculated result_text <- array(16) function get_result_text(pl) { local result = ttextfile("result.txt") result.rt = result_text[pl] return result.tostring() } function get_goal_text(pl) { local goal = ttextfile("goal.txt") return goal.tostring() } // class goal_base { points = 0 /// performs checks, returns nothing function check(po) { } /// return true if goal is completed function completed() { return true; } /// returns null if nothing still achieved function get_text(po) { return null; } function get_points(po) { return points; } } // deepest/highest station // largest station // longest bridge // most construction cost // transport per month / year / company lifetime ? // made me smile: staion name contains :) // boring / interesting station // random yearly challenges: points awarded to winning player class level_goal_base extends goal_base { level = 100 maxlevel = 1 factor = 1 pincrease= 1 reached_level=0 constructor(l,f,pi,sav_) { level = l; factor = f; maxlevel = 0x7fffffff / factor; pincrease = pi; points = 0; } // overload this function get_number(po) { return 1; } function check(po) { local res = get_number(po) while (res >= level && level < maxlevel) { reached_level = level level *= factor points += pincrease } } // only completes on overflow function completed() { return level>=maxlevel; } } class transported_passengers_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(100, 10, 1, _saved_table); } function get_number(po) { return po.get_transported_pax().reduce( max ); } function get_text(po) { return points > 0 ? translate("Transported ") + integer_to_string(reached_level) + translate(" passengers in one month.") : null; } function _save() { return "transported_passengers_month()"; } } class transported_mail_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(50, 8, 2, _saved_table); } function get_number(po) { return po.get_transported_mail().reduce( max ); } function get_text(po) { return points > 0 ? translate("Transported ") + integer_to_string(reached_level) + translate(" bags of mail in one month.") : null; } function _save() { return "transported_mail_month()"; } } class deliver_power_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(400, 5, 1, _saved_table) } function get_number(po) { return po.get_powerline().reduce( max ); } function get_text(po) { return points > 0 ? translate("Delivered ") + integer_to_string(reached_level) + translate("MW of power to various industries.") : null; } function _save() { return "deliver_power_month()"; } } class burn_money_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(100000, 10, 1, _saved_table) } function get_number(po) { return -po.get_construction().reduce( min ); } function get_text(po) { return points > 0 ? translate("Burnt ") + money_to_string(reached_level) + translate(" for constructions in one month.") : null; } function _save() { return "burn_money_month()"; } } class hoard_money_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(1000000, 10, 1, _saved_table) } function get_number(po) { return po.get_cash().reduce( max ); } function get_text(po) { return points > 0 ? translate("Hoarded ") + money_to_string(reached_level) + translate(" at the bank.") : null; } function _save() { return "hoard_money_month()"; } } class profite_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(10000, 10, 1, _saved_table) } function get_number(po) { return po.get_profit().reduce( max ); } function get_text(po) { return points > 0 ? translate("Earned ") + money_to_string(reached_level) + translate(" in one month.") : null; } function _save() { return "profite_month()"; } } class toll_plus_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(1000, 10, 1, _saved_table) } function get_number(po) { return po.get_profit().reduce( max ); } function get_text(po) { return points > 0 ? translate("Robbed others for ") + money_to_string(reached_level) + translate(" in tolls for one month.") : null; } function _save() { return "toll_plus_month()"; } } class deliver_goods_month extends level_goal_base { constructor(_saved_table = null) { base.constructor(1000, 10, 1, _saved_table) } function get_number(po) { return po.get_transported_goods().reduce( max ); } function get_text(po) { return points > 0 ? translate("Delivered ") + integer_to_string(reached_level) + translate(" units of cargo in one month.") : null; } function _save() { return "deliver_goods_month()"; } } class convoy_profitable extends level_goal_base { wt = 0 constructor(wt_ = wt_invalid, _saved_table = null) { wt = wt_; base.constructor(1, 10, 1, _saved_table) } function get_number(po) { return company_goal_info[po.nr].cnv_profitable[wt]; } function _save() { return "convoy_profitable(" + wt + ")"; } function get_text(po) { return points > 0 ? translate("Has ") + reached_level + " " + vehicle_names[wt] + translate(" running with profit.") : null } } class convoy_distance extends level_goal_base { constructor(_saved_table = null) { base.constructor(100, 10, 1, _saved_table) } function get_number(po) { return company_goal_info[po.nr].max_dist; } function _save() { return "convoy_distance()"; } function get_text(po) { return points > 0 ? translate("Has a convoy running more than ") + integer_to_string(reached_level) + translate(" kilometres.") : null } } class headquarter extends goal_base { function check(po) { points = po.get_headquarter_level(); } function get_text(po) { points > 0 ? translate("Built an adequate headquarter."): null; } function _save() { return "headquarter()"; } } // simulate static data for longest_bridge goal - persistent longest_bridge_info <- { player_nr = -1 /// player who receives points max_length = -1 } class longest_bridge extends goal_base { info = longest_bridge_info // points = length of longest bridge function get_points(po) { return info.player_nr == po.nr && info.max_length > 0 ? info.max_length /2 : 0; } // completed - only check after bridge building function get_text(po) { return info.player_nr == po.nr && info.max_length > 0 ? translate("Built longest bridge ever.") : null; } function _save() { return "longest_bridge()"; } } class save_historic_building extends goal_base { pos = null desc = null constructor(p,d) { pos = clone p; if (typeof(d)=="string") { desc = building_desc_x(d) } else { desc = d; } points = 5; } // check whether building is still there function check(po) { local t = tile_x(pos.x,pos.y,pos.z) if (t) { local d = t.find_object(mo_building) if (d) { if (desc.is_equal( d.get_desc() )) { // everything ok return } } } // fail - building has vanished desc = null points = -10 } function completed() { return points <= 0; } function get_text(po) { if (points > 0) { return translate("Saved a historic building from being demolished.") } else if (points < 0) { return translate("Demolished an exceptionally important historic building.") } return null; } function get_points(po) { return points; } function _save() { return "save_historic_building("+save_coord(pos)+", \""+desc.get_name()+"\")"; } } class underground_station extends goal_base { constructor() { points = 1 } function get_text(po) { return translate("Built an underground station.") } function _save() { return "underground_station()" } } class aboveground_station extends goal_base { constructor() { points = 1 } function get_text(po) { return translate("Built a station above our heads.") } function _save() { return "aboveground_station()" } } // goals to check - persistent pending_goals <- array(16) // index of next goal to check - calculated pending_index <- array(16,0) // name/total points of players - calculated active_players <- array(16) // results of removed/bankrupt players - persistent inactive_players <- [] active_players_default <- { name = "", points = 0, is_active = 1} // static info per company - persistent company_goal_info <- array(16) // default value for static info function get_company_goal_info_default() { local t = {} t.historic <- 0 t.underground_station <- 0 t.aboveground_station <- 0 t.cnv_profitable <- array(max_waytypes,0) t.max_dist <- 0 return t; } // tiles to check for strange things - persistent pending_tile_checks <- [] // generator to do the convoy checks // perform_convoy_checks will suspend itself generator_cnv_checks <- null function is_scenario_completed(pl) { //Para configutar los bordes //----------------------------------------------------------------------------------------------------------- local num = totalpl[0].tl if (totalpl[0].tl==null)num=12 if (pl == 1 && get_bord(pl) != null && clime !=2)clime=1 if (swcl != bordsave[0].cl || swnr != bordsave[0].nr)clime=1 else clime=null if (clime ==2) climesw = 1 if (clime == 1 || climesw == 1) { swcl = bordsave[0].cl swnr = bordsave[0].nr totalpl[0].tl = bordsave[0].nr if (climesw==1) get_coordyxpl(0) else if (clime==1) get_coordyxpl(1) get_bord_map(0) clime=null climesw=null } //Para las regiones //------------------------------------------------------------------ if (pl == 1 && !tile_x(coord_label1pub[0].x, coord_label1pub[0].y, coord_label1pub[0].z).find_object(mo_label)) { local t1 = command_x(tool_remover) local err1 = t1.work(player_x(1), square_x(coord_label1pub[0].x, coord_label1pub[0].y).get_ground_tile(), "") local c_label = {x=coord_label1pub[0].x, y=coord_label1pub[0].y} label_x.create(c_label, player_x(pl), translate("Clime nr,Region Siz")) player_x(pl).book_cash(10000) } if (player_x(pl).is_active() && (pl-2)j) { pwtilea = tile_x(pwcoord[pl-2].cxb1, pwcoord[pl-2].cyb1, 0) if (!pwtilea.find_object(mo_powerline)) { build[pl-2].pwcont--; break; } } if(j==1 && build[pl-2].pwcont>j) { pwtilea = tile_x(pwcoord[pl-2].cxb2, pwcoord[pl-2].cyb2, 0) if (!pwtilea.find_object(mo_powerline)) { build[pl-2].pwcont--; break; } } if(j==2 && build[pl-2].pwcont>j) { pwtilea = tile_x(pwcoord[pl-2].cxb3, pwcoord[pl-2].cyb3, 0) if (!pwtilea.find_object(mo_powerline)) { build[pl-2].pwcont--; break; } } if(j==3 && build[pl-2].pwcont>j) { pwtilea = tile_x(pwcoord[pl-2].cxb4, pwcoord[pl-2].cyb4, 0) if (!pwtilea.find_object(mo_powerline)) { build[pl-2].pwcont--; break; } } } if (build[pl-2].pwcont<0)build[pl-2].pwcont=0 if (build[pl-2].pw == 3 ) { if (add_way.find_object(mo_powerline)) { local t1 = command_x(tool_remover) local err1 = t1.work(player_x(1), square_x(addcoord[pl-2].px, addcoord[pl-2].py).get_ground_tile(), "") local t2 = command_x(tool_remover) local err2 = t2.work(player_x(1), square_x(addcoord[pl-2].x1, addcoord[pl-2].y1).get_ground_tile(), "") local t3 = command_x(tool_build_way) local err3 = t3.work(player_x(1), square_x(addcoord[pl-2].px, addcoord[pl-2].py).get_ground_tile(), square_x(addcoord[pl-2].x1, addcoord[pl-2].y1).get_ground_tile(), "Powerline") local t4 = command_x(tool_remover) local err4 = t4.work(player_x(1), square_x(addcoord[pl-2].x1, addcoord[pl-2].y1).get_ground_tile(), "") } build[pl-2].pw = null } if (remover == 1) { //Remover marcadore de posicion if (rem_building.find_object(mo_label)) //Detecta si hay una etiqueta de texto { if (globtool != 4096 && globtool != 4102) { rem_building.remove_object(player_x(1),mo_label) remover = null } } //Elimina una estacion y resta -1,000.00 de efectivo if (rem_building.find_object(mo_building)) //Detecta si hay un construcion { rem_building.remove_object(player_x(1),mo_building) // elimina la estacion player_x(pl).book_cash(-100000) //Resta -100000 remover = null } /* //Elimina un puente y resta -2,500.00 if (rem_building.find_object(mo_bridge)) //Detecta si hay un construcion { rem_building.remove_object(player_x(1),mo_bridge) // elimina el puente player_x(pl).book_cash(-250000) //Resta -2,500.00 remover = null }*/ } } //------------------------------------------------------------------ if (pl == 1) { // public player does not compete - time for special checks switch(pending_index[pl]) { case 1: check_activity() break case 2: perform_tilechecks() break case 3: // call the routine, which just returns the generator if (generator_cnv_checks==null) { generator_cnv_checks = perform_convoy_checks(); } // actually do the checks, routine may suspend itself if ( !(resume generator_cnv_checks) ) { generator_cnv_checks = null } break default: pending_index[pl] = 0 } pending_index[pl]++ return 1; } // fill goal array if necessary if (!pending_goals[pl]) { pending_goals[pl] = generate_pending_goals() company_goal_info[pl] = get_company_goal_info_default() } if (!active_players[pl]) { active_players[pl] = clone active_players_default } local our_goals = pending_goals[pl] // check index, on overflow do maintenance work if (pending_index[pl] >= our_goals.len()) { pending_index[pl] = 0; compile_result_text(pl) //print("Result : " + pl + " / " + pending_index[pl]) if (pl == 0) { compile_current_standing(); } return 1; } // check next goal local po = player_x(pl) if (po && po.is_active()) { local goal = our_goals[ pending_index[pl] ] if (!goal.completed()) { goal.check(po) } } pending_index[pl]++ return 1 } function perform_tilechecks() { // first filter out old checks pending_tile_checks = pending_tile_checks.filter(tile_check_base.filter); // .. now iterate foreach(tc in pending_tile_checks) { tc.check() tc.tries -- } persistent.pending_tile_checks = pending_tile_checks; } function compile_result_text(pl) { local res = null local total = 0 local po = player_x(pl) foreach(goal in pending_goals[pl]) { local text = goal.get_text(po) local points = goal.get_points(po) if (text) { if (res) res += "
"; else res = "" res += "(" + (points>0?"+":"") + points + ") " + text total += points } //if (points) print(text) } if (res) { res += "

" + total + translate(" Points total achieved.") } else { res = translate("
No points achieved.") } result_text[pl] = res active_players[pl].points = total active_players[pl].name = po.get_name() } function compile_current_standing() { local st = [] for(local pl = 0; pl < 15; pl ++) { if (pl != 1 && active_players[pl]) { st.append( clone active_players[pl] ) } } st.extend(inactive_players) st.sort( @(sa,sb) ( sb.points<=>sa.points )) current_standing_text = "" foreach(idx,sa in st) { local ia = sa.is_active current_standing_text += ia ? "" : "" current_standing_text += "[" + (idx+1) + "] " + sa.name + " (" + sa.points + translate(" points)") current_standing_text += ia ? "" : "" current_standing_text += "
\n" } //print(current_standing_text) } function check_activity() { for(local pl = 0; pl < 15; pl ++) { if (pl == 1) continue local player = player_x(pl) if (pending_goals[pl] && !player.is_active()) { local inact = clone active_players[pl] inact.is_active = 0 inactive_players.append(inact) pending_goals[pl] = null } } } function generate_pending_goals() { local a = [ transported_passengers_month(), transported_mail_month(), deliver_goods_month(), deliver_power_month(), hoard_money_month(), burn_money_month(), profite_month(), longest_bridge(), convoy_distance(), ]; foreach(wt in all_waytypes) { a.append(convoy_profitable(wt)) } return a } function is_work_allowed_here(pl, tool_id, pos) { // catch bridge building here ... if (tool_id == tool_build_bridge) { // store bridge position ... print("Caught bridge at (" + pos.x + ", " +pos.y + ", " +pos.z +")") pending_tile_checks.append( checkforbridge(pos, pl) ) } // buy historic building if (tool_id == tool_buy_house && company_goal_info[pl].historic == 0) { print("Caught buy-house at (" + pos.x + ", " +pos.y + ", " +pos.z +")") pending_tile_checks.append( checkhistoric(pos, pl) ) } // catch station building here ... if (tool_id == tool_build_station) { local tile = tile_x(pos.x, pos.y, pos.z) if (!tile.is_ground()) { pending_tile_checks.append( checkstation(pos, pl) ) } } return null } // class tile_check_base { tries = 5 pos = null pl = -1 constructor(p, pl_, t_ = 5) { tries = t_; pos = clone p; pl = pl_;} function check() {} static function filter(idx, val) { return val.tries>0; } } class checkforbridge extends tile_check_base { function check() { local start = tile_x(pos.x,pos.y,pos.z) if (!start.is_bridge() || !start.is_ground()) return; // first way on bridge - now find bridge direction local way = start.find_object(mo_way); if (!way) return; local wt = way.get_waytype(); local max_length = 0 foreach(r in dir.nsew) { local length = 1 local tile = start.get_neighbour(wt,r) while (tile && tile.is_bridge() && !tile.is_ground()) { tile = tile.get_neighbour(wt,r) length ++ } if (tile && tile.is_bridge()) length ++; if (length > max_length) max_length = length; } // do not check again tries = 0 if (max_length > longest_bridge_info.max_length) { longest_bridge_info.max_length = max_length // get owner of bridge local bridge = start.find_object(mo_bridge); longest_bridge_info.player_nr = bridge ? bridge.get_owner().nr : -1; } print("Check for bridge at (" + pos.x + ", " +pos.y + ", " +pos.z +") ==> " + max_length) } function _save() { return "checkforbridge("+save_coord(pos)+","+pl+","+tries+")"; } } class checkhistoric extends tile_check_base { function check() { if (company_goal_info[pl].historic != 0) return local t = tile_x(pos.x,pos.y,pos.z) if (t) { local d = t.find_object(mo_building) if (d) { if (d.get_owner().nr == pl) { if (d.get_desc().is_retired( world.get_time() ) ){ // this is an old building pending_goals[pl].append(save_historic_building(pos, d.get_desc())) company_goal_info[pl].historic = 1 } // do not check again tries = 0 } } } } function _save() { return "checkhistoric("+save_coord(pos)+","+pl+","+tries+")"; } } class checkstation extends tile_check_base { function check() { local t = tile_x(pos.x,pos.y,pos.z) if (t && !t.is_ground()) { local st = t.find_object(mo_building) if (st && st.get_owner().nr == pl) { local b = st.get_desc() if (b.get_type() == building_desc_x.station) { if (t.is_tunnel()) { if (company_goal_info[pl].underground_station == 0) { company_goal_info[pl].underground_station = 1; pending_goals[pl].append(underground_station()) } } else { if (company_goal_info[pl].aboveground_station == 0) { company_goal_info[pl].aboveground_station = 1; pending_goals[pl].append(aboveground_station()) } } } // do not check again tries = 0 } } } function _save() { return "checkstation("+save_coord(pos)+","+pl+","+tries+")"; } } function perform_convoy_checks() { local iteration = 0; local cnv_counter = array(15) local max_dist = array(15,0) for(local i=0; i<15; i++) { cnv_counter[i] = array(max_waytypes,0) } foreach(cnv in convoy_list_x()) { local pl = cnv.get_owner().nr local is_profitable = cnv.get_profit().reduce(max) > 0 if (is_profitable) { cnv_counter[ pl ][ cnv.get_waytype() ] ++ } local distance = cnv.get_distance_traveled_total() if (distance > max_dist[pl]) { max_dist[pl] = distance } iteration++ if (iteration % 100 == 0) { yield true } } for(local pl=0; pl<15; pl++) { foreach(wt in all_waytypes) { local c = cnv_counter[ pl ][ wt ] if (c>0) { company_goal_info[pl].cnv_profitable[wt] = max(company_goal_info[pl].cnv_profitable[wt], c); } } if (max_dist[pl]>0) { company_goal_info[pl].max_dist = max(company_goal_info[pl].max_dist, max_dist[pl]) } } return null } //Para las regiones //------------------------------------------------------------------------ // Se obtienen lo valores de coordenadas y los nr de jugadores regionshare <- { plsavesave = playersave stationcoordsav = stationsave sws = sw total = totalpl bord = bordsave swspl = swpl build_pub = build pw_pub = pwcoord } class data_share { // Numeros de los jugadores function get_plsave() {return regionshare.plsavesave } // Coordenadas compartidas function get_stationsave() {return regionshare.stationcoordsav } // Guarda sw function get_sw() {return regionshare.sws } function get_totalpl() {return regionshare.total } function get_bord() {return regionshare.bord } function get_swspl() {return regionshare.swspl } function get_build() {return regionshare.build_pub } function get_pwcoord() {return regionshare.pw_pub } // Se guardan los datos function _save() { return "data_share()"; } } //------------------------------------------------------------------------ persistent <- { pending_goals = pending_goals company_goal_info = company_goal_info pending_tile_checks = pending_tile_checks longest_bridge_info = longest_bridge_info inactive_players = inactive_players regionshare = regionshare } function start() { get_coordyxpl(0) persistent.save_version <- save_version init() } function is_tool_allowed(pl, tool_id, wt) { return true } function resume_game() { climesw = 1 init() pending_goals = persistent.pending_goals company_goal_info = persistent.company_goal_info pending_tile_checks = persistent.pending_tile_checks inactive_players = persistent.inactive_players // save game version if ( !("save_version" in persistent) ) { persistent.save_version <- 0 } // copy it piece by piece otherwise the reference longest_bridge::info will be off foreach(key,value in persistent.longest_bridge_info) { longest_bridge_info.rawset(key,value) } persistent.longest_bridge_info = longest_bridge_info // Datos guardados para las regiones //----------------------------------------------------- // copy it piece by piece otherwise the reference foreach(key,value in persistent.regionshare) { regionshare.rawset(key,value) } persistent.regionshare = regionshare // Se obtienen los datos guardados playersave = data_share().get_plsave() stationsave = data_share().get_stationsave() sw = data_share().get_sw() totalpl = data_share().get_totalpl() bordsave = data_share().get_bord() swpl = data_share().get_swspl() build = data_share().get_build() pwcoord = data_share().get_pwcoord() //------------------------------------------------------- totalpl[0].tl = bordsave[0].nr get_coordyxpl(0) // refresh point calculations for(local pl = 0; pl < 15; pl++) { local po = player_x(pl) if (pl != 1 && po.is_active()) { // fill goal array if necessary if (!pending_goals[pl]) { pending_goals[pl] = generate_pending_goals() company_goal_info[pl] = get_company_goal_info_default() } else { // update switch(persistent.save_version) { case 0: pending_goals[pl].insert(2, deliver_goods_month()) print("Ha" + pl) } } // player info active_players[pl] = clone active_players_default // check goals foreach(goal in pending_goals[pl]) { goal.check(po) } // .. and compile result compile_result_text(pl) } } compile_current_standing() // everything updated... persistent.save_version = save_version } function init() { scenario.forbidden_tools = scenario.forbidden_tools.filter( @(index,val)( val != tool_switch_player) ) for(local pl=0; pl<16; pl++) { result_text[pl] = translate("Results are being calculated...") } } //------------------------------------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------------------------------------ xmin <- 0 xmax <- 0 ymin <- 0 ymax <- 0 gtpla <- null gtplb <- null coord3 <- [{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0},{x1=0,y1=0,x2=0,y2=0}] function is_work_allowed_here(pl, tool_id, pos) { local result = translate("This region belongs to another player!.") // set standard error message if (pl==1) return result = null else if ( pl==0 || pl==14) {if (tool_id == 4096) return null} else result = translate("This region belongs to another player!.") if ( pl==0 || pl==14) return result //local result2 = 0 local num = totalpl[0].tl if (totalpl[0].tl==null)num=12 if ((pl-2)stationsave[pl-2].x2) { stationsave[pl-2].x1 = camb2 stationsave[pl-2].x2 = camb1 } camb1 = stationsave[pl-2].y1 camb2 = stationsave[pl-2].y2 if (stationsave[pl-2].y1>stationsave[pl-2].y2) { stationsave[pl-2].y1 = camb2 stationsave[pl-2].y2 = camb1 } region_shared(pl, tool_id, pos, result) return result = translate("Coord B:") + " ("+pos.x+","+pos.y+")." } //Elimina un marcador de posicion si el jugador es el propietario if (tile_x(pos.x, pos.y, pos.z).find_object(mo_label)) { if (map_object_x(pos.x, pos.y, pos.z, mo_label).get_owner().nr == pl) { if (tool_id == 4097 || tool_id == 4096) return result = null else result = translate("This region belongs to another player!.") } } //Elimina una estacion si el jugador es el propietario if (tile_x(pos.x, pos.y, pos.z).find_object(mo_building)) { if (map_object_x(pos.x, pos.y, pos.z, mo_building).get_owner().nr == pl) { if (tool_id == 4097 || tool_id == 4096) return result = null else result = translate("This region belongs to another player!.") } } if (pos.x+1 >= plregions[pl-2].x1 && pos.x <= plregions[pl-2].x2+1 && pos.y+1 >= plregions[pl-2].y2 && pos.y<= plregions[pl-2].y1+1 ) { result = null local rem_building = tile_x(pos.x, pos.y, pos.z) local add_way = tile_x(pos.x, pos.y, pos.z) //Para eliminar marcadores de otros jugadores pero dentro de nuestra region if (rem_building.find_object(mo_label)) { if (map_object_x(pos.x, pos.y, pos.z, mo_label).get_owner().nr == pl) return result = null //Elimina Si el jugador es el propietario if (map_object_x(pos.x, pos.y, pos.z, mo_label).get_owner().nr != 1) { globtool = tool_id removercoord[pl-2].x=pos.x removercoord[pl-2].y=pos.y removercoord[pl-2].z=pos.z remover = 1 return result = translate("The text was deleted.") } } //Para eliminar Estaciones de otros jugadores pero dentro de nuestra region if (rem_building.find_object(mo_building)) { if (map_object_x(pos.x, pos.y, pos.z, mo_building).get_owner().nr == pl) return result = null //Elimina Si el jugador es el propietario globtool = tool_id removercoord[pl-2].x=pos.x removercoord[pl-2].y=pos.y removercoord[pl-2].z=pos.z if (tool_id == 4097 && rem_building.get_halt() != null && rem_building.find_object(mo_building).get_factory()== null) { remover = 1 return result = translate("You have eliminated the station another player.") } } // Para construir via de tren publica if(tool_id == 4110 && add_way.find_object(mo_way) && build[pl-2].way != 2) { if (map_object_x(pos.x, pos.y, pos.z, mo_way).get_owner().nr == pl && map_object_x(pos.x, pos.y, pos.z, mo_way).get_owner().nr != 1) { globtool = tool_id addcoord[pl-2].x1=pos.x addcoord[pl-2].y1=pos.y addcoord[pl-2].z1=pos.z build[pl-2].way = 2 result = null } } if(tool_id == 4110 && add_way.find_object(mo_way) && build[pl-2].way == 2) { if (map_object_x(pos.x, pos.y, pos.z, mo_way).get_owner().nr != pl && map_object_x(pos.x, pos.y, pos.z, mo_way).get_owner().nr != 1) { build[pl-2].way = null globtool = tool_id addcoord[pl-2].x2=pos.x addcoord[pl-2].y2=pos.y addcoord[pl-2].z2=pos.z if (addcoord[pl-2].x1 == addcoord[pl-2].x2) { if(pos.y==addcoord[pl-2].y1+1) { build[pl-2].waycont++ build[pl-2].way = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } if(pos.y==addcoord[pl-2].y1-1) { build[pl-2].waycont++ build[pl-2].way = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } } if (addcoord[pl-2].y1 == addcoord[pl-2].y2) { if(pos.x==addcoord[pl-2].x1+1) { build[pl-2].waycont++ build[pl-2].way = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } if(pos.x==addcoord[pl-2].x1-1) { build[pl-2].waycont++ build[pl-2].way = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } } } } else build[pl-2].way = null // Para construir tendido electrico publica if(tool_id==4110 && add_way.find_object(mo_powerline) && build[pl-2].pw != 2) { if (map_object_x(pos.x, pos.y, pos.z, mo_powerline).get_owner().nr == pl && map_object_x(pos.x, pos.y, pos.z, mo_powerline).get_owner().nr != 1) { globtool = tool_id addcoord[pl-2].x1=pos.x addcoord[pl-2].y1=pos.y addcoord[pl-2].z1=pos.z build[pl-2].pw = 2 result = null } } if(tool_id == 4110 && add_way.find_object(mo_powerline) && build[pl-2].pw == 2) { if (map_object_x(pos.x, pos.y, pos.z, mo_powerline).get_owner().nr != pl && map_object_x(pos.x, pos.y, pos.z, mo_powerline).get_owner().nr != 1) { build[pl-2].pw = null globtool = tool_id addcoord[pl-2].x2=pos.x addcoord[pl-2].y2=pos.y addcoord[pl-2].z2=pos.z if (addcoord[pl-2].x1 == addcoord[pl-2].x2) { if(pos.y==addcoord[pl-2].y1+1) { result = translate("You have reached the limit of connections, try to delete some") + " ("+pos.x+","+pos.y+")." addcoord[pl-2].px = addcoord[pl-2].x1 addcoord[pl-2].py = addcoord[pl-2].y1-- for (j=0;j<=4;j++) { if(j==4)return result if(j==build[pl-2].pwcont) { if(j==0) { pwcoord[pl-2].cxa1=pos.x pwcoord[pl-2].cya1=addcoord[pl-2].y1 pwcoord[pl-2].cxb1=pos.x pwcoord[pl-2].cyb1=addcoord[pl-2].y1+1 } if(j==1) { pwcoord[pl-2].cxa2=pos.x pwcoord[pl-2].cya2=addcoord[pl-2].y1 pwcoord[pl-2].cxb2=pos.x pwcoord[pl-2].cyb2=addcoord[pl-2].y1+1 } if(j==2) { pwcoord[pl-2].cxa3=pos.x pwcoord[pl-2].cya3=addcoord[pl-2].y1 pwcoord[pl-2].cxb3=pos.x pwcoord[pl-2].cyb3=addcoord[pl-2].y1+1 } if(j==3) { pwcoord[pl-2].cxa4=pos.x pwcoord[pl-2].cya4=addcoord[pl-2].y1 pwcoord[pl-2].cxb4=pos.x pwcoord[pl-2].cyb4=addcoord[pl-2].y1+1 } build[pl-2].pwcont++ build[pl-2].pw = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } } } else result = translate("The distance between the two points is very large") + " ("+pos.x+","+pos.y+")." if(pos.y==addcoord[pl-2].y1-1) { result = translate("You have reached the limit of connections, try to delete some") + " ("+pos.x+","+pos.y+")." addcoord[pl-2].px = addcoord[pl-2].x1 addcoord[pl-2].py = addcoord[pl-2].y1++ for (j=0;j<=4;j++) { if(j==4)return result if(j==build[pl-2].pwcont) { if(j==0) { pwcoord[pl-2].cxa1=pos.x pwcoord[pl-2].cya1=addcoord[pl-2].y1 pwcoord[pl-2].cxb1=pos.x pwcoord[pl-2].cyb1=addcoord[pl-2].y1-1 } if(j==1) { pwcoord[pl-2].cxa2=pos.x pwcoord[pl-2].cya2=addcoord[pl-2].y1 pwcoord[pl-2].cxb2=pos.x pwcoord[pl-2].cyb2=addcoord[pl-2].y1-1 } if(j==2) { pwcoord[pl-2].cxa3=pos.x pwcoord[pl-2].cya3=addcoord[pl-2].y1 pwcoord[pl-2].cxb3=pos.x pwcoord[pl-2].cyb3=addcoord[pl-2].y1-1 } if(j==3) { pwcoord[pl-2].cxa4=pos.x pwcoord[pl-2].cya4=addcoord[pl-2].y1 pwcoord[pl-2].cxb4=pos.x pwcoord[pl-2].cyb4=addcoord[pl-2].y1-1 } build[pl-2].pwcont++ build[pl-2].pw = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } } } else result = translate("The distance between the two points is very large") + " ("+pos.x+","+pos.y+")." } if (addcoord[pl-2].y1 == addcoord[pl-2].y2) { if(pos.x==addcoord[pl-2].x1+1) { result = translate("You have reached the limit of connections, try to delete some") + " ("+pos.x+","+pos.y+")." addcoord[pl-2].px = addcoord[pl-2].x1-- addcoord[pl-2].py = addcoord[pl-2].y1 for (j=0;j<=4;j++) { if(j==4)return result if(j==build[pl-2].pwcont) { if(j==0) { pwcoord[pl-2].cxa1=addcoord[pl-2].x1 pwcoord[pl-2].cya1=pos.y pwcoord[pl-2].cxb1=addcoord[pl-2].x1+1 pwcoord[pl-2].cyb1=pos.y } if(j==1) { pwcoord[pl-2].cxa2=addcoord[pl-2].x1 pwcoord[pl-2].cya2=pos.y pwcoord[pl-2].cxb2=addcoord[pl-2].x1+1 pwcoord[pl-2].cyb2=pos.y } if(j==2) { pwcoord[pl-2].cxa3=addcoord[pl-2].x1 pwcoord[pl-2].cya3=pos.y pwcoord[pl-2].cxb3=addcoord[pl-2].x1+1 pwcoord[pl-2].cyb3=pos.y } if(j==3) { pwcoord[pl-2].cxa4=addcoord[pl-2].x1 pwcoord[pl-2].cya4=pos.y pwcoord[pl-2].cxb4=addcoord[pl-2].x1+1 pwcoord[pl-2].cyb4=pos.y } build[pl-2].pwcont++ build[pl-2].pw = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } } } else result = translate("The distance between the two points is very large") + " ("+pos.x+","+pos.y+")." if(pos.x==addcoord[pl-2].x1-1) { result = translate("You have reached the limit of connections, try to delete some") + " ("+pos.x+","+pos.y+")." addcoord[pl-2].px = addcoord[pl-2].x1++ addcoord[pl-2].py = addcoord[pl-2].y1 for (j=0;j<=4;j++) { if(j==4)return result if(j==build[pl-2].pwcont) { if(j==0) { pwcoord[pl-2].cxa1=addcoord[pl-2].x1 pwcoord[pl-2].cya1=pos.y pwcoord[pl-2].cxb1=addcoord[pl-2].x1-1 pwcoord[pl-2].cyb1=pos.y } if(j==1) { pwcoord[pl-2].cxa2=addcoord[pl-2].x1 pwcoord[pl-2].cya2=pos.y pwcoord[pl-2].cxb2=addcoord[pl-2].x1-1 pwcoord[pl-2].cyb2=pos.y } if(j==2) { pwcoord[pl-2].cxa3=addcoord[pl-2].x1 pwcoord[pl-2].cya3=pos.y pwcoord[pl-2].cxb3=addcoord[pl-2].x1-1 pwcoord[pl-2].cyb3=pos.y } if(j==3) { pwcoord[pl-2].cxa4=addcoord[pl-2].x1 pwcoord[pl-2].cya4=pos.y pwcoord[pl-2].cxb4=addcoord[pl-2].x1-1 pwcoord[pl-2].cyb4=pos.y } build[pl-2].pwcont++ build[pl-2].pw = 3 return result = translate("Connected!") + " ("+pos.x+","+pos.y+")." } } } else result = translate("The distance between the two points is very large") + " ("+pos.x+","+pos.y+")." } } } else build[pl-2].pw = null } //Punto para ingrsar coordenadas if (pos.x == plregions[pl-2].x1+1 && pos.y == plregions[pl-2].y2) { if (tool_id == 4097 && !tile_x(coord_label1[pl-2].x, coord_label1[pl-2].y, coord_label1[pl-2].z).find_object(mo_label)) return translate("You must first place a text label here! ("+coord_label1[pl-2].x+","+coord_label1[pl-2].y+").") if (playersave[pl-2].plsave == pl)return result = translate("Enter a valid value here!") + " ("+coord_label1[pl-2].x+","+coord_label1[pl-2].y+")." if (tool_id == 4097 ){ result = translate("Enter the coordinates A and B."); if (playersave[pl-2].plsave != pl) swpl[pl-2].sw = null;} if ( tool_id == 4096){ result = translate("Enter the coordinates A and B."); if (playersave[pl-2].plsave != pl) swpl[pl-2].sw = null;} //get_removercoord(pl) } //Punto para recargar if (pos.x == plregions[pl-2].x1+2 && pos.y == plregions[pl-2].y2) { if (tool_id == 4097){ result = translate("Reloading..."); if (playersave[pl-2].plsave != pl) swpl[pl-2].sw = null;} if (tool_id == 4096){ result = translate("Reloading..."); if (playersave[pl-2].plsave != pl) swpl[pl-2].sw = null;} //get_removercoord(pl) } } result = region_shared(pl, tool_id, pos, result) if (tool_id == 4096 || tool_id == 4102) if ( pos.x != plregions[pl-2].x1+6 && pos.y != plregions[pl-2].y2) result = null return result } function region_shared(pl, tool_id, pos, result) { local num = totalpl[0].tl if (totalpl[0].tl==null)num=12 //Compartir region con otros jugadores if (totalpl[0].tl==null)num=12 if ((pl-2)= plregions[gtplb-2].x1 && pos.x <= plregions[gtplb-2].x2+1 && pos.y+1 >= plregions[gtplb-2].y2 && pos.y<= plregions[gtplb-2].y1+1 ) { if (pos.x >= stationsave[gtplb-2].x1 && pos.x <= stationsave[gtplb-2].x2 && pos.y >= stationsave[gtplb-2].y1 && pos.y <= stationsave[gtplb-2].y2 ) { result = null if(tool_id==4097 || tool_id==4110) { local tile = tile_x(pos.x, pos.y, pos.z) if (tile.find_object(mo_label) && map_object_x(pos.x, pos.y, pos.z, mo_label).get_owner().nr != pl){ return result = translate("You can only remove if it is within your region") + " ("+pos.x+","+pos.y+")."} if (tile.find_object(mo_building) && map_object_x(pos.x, pos.y, pos.z, mo_building).get_owner().nr != pl){ return result = translate("You can only remove if it is within your region") + " ("+pos.x+","+pos.y+")."} if (tool_id==4110 && tile.find_object(mo_way) && map_object_x(pos.x, pos.y, pos.z, mo_way).get_owner().nr != pl && map_object_x(pos.x, pos.y, pos.z, mo_way).get_owner().nr != 1){ return result = translate("The connections are only possible within their region!") + " ("+pos.x+","+pos.y+")."} if (tool_id==4110 && tile.find_object(mo_powerline) && map_object_x(pos.x, pos.y, pos.z, mo_powerline).get_owner().nr != pl){ return result = translate("The connections are only possible within their region!") + " ("+pos.x+","+pos.y+")."} } } } } } } return result }