/*
* class chapter_07
*
*
* Can NOT be used in network game !
*/
class tutorial.chapter_06 extends basic_chapter
{
chapter_name = ch6_name
chapter_coord = coord_chapter_6
startcash = 500000 // pl=0 startcash; 0=no reset
gl_wt = wt_air
//Step 2 =====================================================================================
ch6_cov_lim1 = {a = 0, b = 0}
//Step 3 =====================================================================================
ch6_cov_lim2 = {a = 0, b = 0}
//Step 4 =====================================================================================
ch6_cov_lim3 = {a = 0, b = 0}
c_way = coord(0,0)
cty1 = {name = ""}
cty2 = {name = ""}
cty1_lim = {a = null, b = null}
cty2_lim = {a = null, b = null}
sch_cov_correct = false
// Step 1 =====================================================================================
// Pista de aterrizaje --------------------------
c1_track = {a = coord(112,174), b = coord(112,178), dir = 4}
c1_start = coord(112,174)
c1_is_way = null
obj1_way_name = get_obj_ch6(1)
// Pista de maniobras --------------------------
c2_track = {a = coord(112,176), b = coord(114,176), dir = 2}
c2_start = coord(112,176)
c2_is_way = null
obj2_way_name = get_obj_ch6(2)
// Step 2 =====================================================================================
d1_cnr = null //auto started
plane1_obj = get_veh_ch6(1)
line1_name = "ch6_l1"
// Step 3 =====================================================================================
//c_dep2 = coord(115,185)
d2_cnr = null //auto started
veh1_obj = get_veh_ch6(2)
line2_name = "ch6_l2"
// Step 4 =====================================================================================
d3_cnr = null //auto started
veh2_obj = get_veh_ch6(3)
line3_name = "ch6_l3"
//Script
//----------------------------------------------------------------------------------
sc_sta1 = get_obj_ch6(3)
sc_sta2 = get_obj_ch6(4)
sc_dep1 = get_obj_ch6(5)
sc_dep2 = get_obj_ch6(6)
function start_chapter() //Inicia solo una vez por capitulo
{
local lim_idx = cv_list[(persistent.chapter - 2)].idx
ch6_cov_lim1 = {a = cv_lim[lim_idx].a, b = cv_lim[lim_idx].b}
ch6_cov_lim2 = {a = cv_lim[lim_idx+1].a, b = cv_lim[lim_idx+1].b}
ch6_cov_lim3 = {a = cv_lim[lim_idx+2].a, b = cv_lim[lim_idx+2].b}
d1_cnr = get_dep_cov_nr(ch6_cov_lim1.a,ch6_cov_lim1.b)
d2_cnr = get_dep_cov_nr(ch6_cov_lim2.a,ch6_cov_lim2.b)
d3_cnr = get_dep_cov_nr(ch6_cov_lim3.a,ch6_cov_lim3.b)
cty1.name = get_city_name(city1_tow)
cty2.name = get_city_name(city7_tow)
line1_name = "Air " + cty1.name + " - " + cty2.name
line2_name = "City " + cty1.name + " - Airport"
line3_name = "City " + cty2.name + " - Airport"
/*
//Schedule list form current convoy
if(this.step == 2){
local c_dep = this.my_tile(city1_road_depot)
local c_list = city1_halt_1
start_sch_tmpsw(pl, c_dep, c_list)
}
else if(this.step == 3){
local c_dep = this.my_tile(city1_road_depot)
local c_list = city1_halt_2
start_sch_tmpsw(pl, c_dep, c_list)
}
else if(this.step == 4){
local c_dep = this.my_tile(city1_road_depot)
local c_list = city2_halt_1
start_sch_tmpsw(pl, c_dep, c_list)
}*/
}
function set_goal_text(text){
switch (this.step) {
case 1:
text.c1_a = "("+c1_track.a.tostring()+")"
text.c1_b = "("+c1_track.b.tostring()+")"
text.c2_a = "("+c2_track.a.tostring()+")"
text.c2_b = "("+c2_track.b.tostring()+")"
text.st1 = "("+city1_city7_air[0].tostring()+")"
text.st2 = "("+city1_halt_airport_extension[0].tostring()+")"
break
case 2:
local list_tx = ""
local c_list = city1_city7_air
local siz = c_list.len()
for (local j=0;j%s %d: %s %s
", translate("Stop"), j+1, st_halt.get_name(), translate("OK"))
continue
}
if(tmpsw[j]==0 ){
list_tx += format("%s %d: %s
", translate("Stop"), j+1, c.href(st_halt.get_name()+" ("+c.tostring()+")"))
}
else{
list_tx += format("%s %d: %s %s
", translate("Stop"), j+1, st_halt.get_name(), translate("OK"))
}
}
local c = coord(c_list[get_waiting_halt(6)].x, c_list[get_waiting_halt(6)].y)
text.stnam = (get_waiting_halt(6)+1) + ") " + my_tile(c).get_halt().get_name()+" ("+c.tostring()+")"
text.list = list_tx
text.plane = translate(plane1_obj)
text.load = set_loading_capacity(5)
text.wait = get_wait_time_text(set_waiting_time(8))
text.cnr = d1_cnr
break
case 3:
local list_tx = ""
local c_list = city1_halt_airport
local siz = c_list.len()
for (local j=0;j "+st_halt.get_name()+" ("+tile.x+","+tile.y+")"
}
if(sch_cov_correct){
list_tx += format("%s %d: %s %s
", translate("Stop"), j+1, st_halt.get_name(), translate("OK"))
continue
}
if(tmpsw[j]==0 ){
list_tx += format("%s %d: %s
", translate("Stop"), j+1, c.href(st_halt.get_name()+" ("+c.tostring()+")"))
}
else{
list_tx += format("%s %d: %s %s
", translate("Stop"), j+1, st_halt.get_name(), translate("OK"))
}
}
local c = coord(c_list[get_waiting_halt(7)].x, c_list[get_waiting_halt(7)].y)
text.stnam = (get_waiting_halt(7)+1) + ") " + my_tile(c).get_halt().get_name()+" ("+c.tostring()+")"
text.stx = list_tx
text.dep2 = " ("+city1_road_depot.tostring()+")"
text.load = set_loading_capacity(6)
text.wait = get_wait_time_text(set_waiting_time(9))
text.cnr = d2_cnr
break
case 4:
local list_tx = ""
local c_list = city7_halt
local siz = c_list.len()
for (local j=0;j "+st_halt.get_name()+" ("+tile.x+","+tile.y+")"
}
if(sch_cov_correct){
list_tx += format("%s %d: %s %s
", translate("Stop"), j+1, st_halt.get_name(), translate("OK"))
continue
}
if(tmpsw[j]==0 ){
list_tx += format("%s %d: %s
", translate("Stop"), j+1, c.href(st_halt.get_name()+" ("+c.tostring()+")"))
}
else{
list_tx += format("%s %d: %s %s
", translate("Stop"), j+1, st_halt.get_name(), translate("OK"))
}
}
local c = coord(c_list[get_waiting_halt(8)].x, c_list[get_waiting_halt(8)].y)
text.stnam = (get_waiting_halt(8)+1) + ") " + my_tile(c).get_halt().get_name()+" ("+c.tostring()+")"
text.stx = list_tx
text.dep3 = "("+city7_road_depot.tostring()+")"
text.load = set_loading_capacity(7)
text.wait = get_wait_time_text(set_waiting_time(10))
text.cnr = d3_cnr
break
}
text.w1name = translate(obj1_way_name)
text.w2name = translate(obj2_way_name)
text.bus1 = translate(veh1_obj)
text.bus2 = translate(veh2_obj)
text.cit1 = city1_tow.href(cty1.name.tostring())
text.cit2 = city7_tow.href(cty2.name.tostring())
text.dep1 = "("+ch6_air_depot.a.tostring()+")"
return text
}
function is_chapter_completed(pl) {
save_glsw()
save_pot()
persistent.ch_max_steps = 4
local chapter_step = persistent.step
persistent.ch_max_sub_steps = 0 // count all sub steps
persistent.ch_sub_step = 0 // actual sub step
switch (this.step) {
case 1:
if (pot0==0){
local tile = my_tile(c1_start)
c1_is_way = tile.find_object(mo_way)
local ta = my_tile(c1_track.a)
local tb = my_tile(c1_track.b)
local wt = gl_wt
local name_list = [obj1_way_name]
local dir = c1_track.dir
local fullway = check_way(ta, tb, wt, name_list, dir)
if (fullway.result){
c_way = coord(0,0)
pot0=1
}
else
c_way = fullway.c
//return 5
}
else if (pot0==1 && pot1==0){
local tile = my_tile(c2_start)
c2_is_way = tile.find_object(mo_way)
local ta = my_tile(c2_track.a)
local tb = my_tile(c2_track.b)
local wt = gl_wt
local name_list = [obj1_way_name, obj2_way_name]
local dir = c2_track.dir
local fullway = check_way(ta, tb, wt, name_list, dir)
if (fullway.result){
c_way = coord(0,0)
pot1=1
}
else
c_way = fullway.c
//return 10
}
else if (pot1==1 && pot2==0){
local tile = my_tile(city1_city7_air[0])
local way = tile.find_object(mo_way)
local buil = tile.find_object(mo_building)
local name = translate("Build here")
public_label(tile, name)
if(way && buil){
tile.remove_object(player_x(1), mo_label)
pot2 = 1
}
//return 15
}
else if (pot2==1 && pot3==0){
local tile = my_tile(city1_halt_airport_extension[0])
local buil = tile.find_object(mo_building)
local name = translate("Build here")
public_label(tile, name)
if(buil){
tile.remove_object(player_x(1), mo_label)
pot3 = 1
}
//return 20
}
else if (pot3==1 && pot4==0){
local tile = my_tile(ch6_air_depot.a)
local way = tile.find_object(mo_way)
local depot = tile.find_object(mo_depot_air)
local name = translate("Build here")
public_label(tile, name)
if(way && depot){
tile.remove_object(player_x(1), mo_label)
tile.remove_object(player_x(1), mo_label)
pot4 = 1
}
//return 25
}
else if (pot4==1 && pot5==0){
local tile = my_tile(city1_halt_airport[0])
local buil = tile.find_object(mo_building)
if(buil && buil.get_owner().nr == 1){
pot5 = 1
}
//return 30
}
else if (pot5==1 && pot6==0){
this.next_step()
}
break;
case 2:
local c_dep = my_tile(ch6_air_depot.a)
local line_name = line1_name
set_convoy_schedule(pl, c_dep, wt_air, line_name)
local depot = depot_x(c_dep.x, c_dep.y, c_dep.z)
local cov_list = depot.get_convoy_list() //Lista de vehiculos en el deposito
local convoy = convoy_x(gcov_id)
if (cov_list.len()>=1){
convoy = cov_list[0]
}
local all_result = checks_convoy_schedule(convoy, pl)
sch_cov_correct = all_result.res == null ? true : false
if(current_cov == ch6_cov_lim1.b){
sch_cov_correct = false
this.next_step()
}
//return 50
break;
case 3:
local c_dep = my_tile(city1_road_depot)
local line_name = line2_name
set_convoy_schedule(pl, c_dep, wt_road, line_name)
local depot = depot_x(c_dep.x, c_dep.y, c_dep.z)
local cov_list = depot.get_convoy_list() //Lista de vehiculos en el deposito
local convoy = convoy_x(gcov_id)
if (cov_list.len()>=1){
convoy = cov_list[0]
}
local all_result = checks_convoy_schedule(convoy, pl)
sch_cov_correct = all_result.res == null ? true : false
if(current_cov == ch6_cov_lim2.b){
sch_cov_correct = false
this.next_step()
}
//return 65
break;
case 4:
if (pot0==0){
local tile = my_tile(city7_road_depot)
local way = tile.find_object(mo_way)
local depot = tile.find_object(mo_depot_road)
if(way && depot){
pot0 = 1
}
//return 25
}
else if (pot0==1 && pot1==0){
local c_dep = my_tile(city7_road_depot)
local line_name = line3_name
set_convoy_schedule(pl, c_dep, wt_road, line_name)
local depot = depot_x(c_dep.x, c_dep.y, c_dep.z)
local cov_list = depot.get_convoy_list() //Lista de vehiculos en el deposito
local convoy = convoy_x(gcov_id)
if (cov_list.len()>=1){
convoy = cov_list[0]
}
local all_result = checks_convoy_schedule(convoy, pl)
sch_cov_correct = all_result.res == null ? true : false
if(current_cov == ch6_cov_lim3.b){
sch_cov_correct = false
this.next_step()
}
}
//return 80
break;
case 5:
this.step=1
persistent.step=1
persistent.status.step = 1
//return 100
break;
}
local percentage = chapter_percentage(persistent.ch_max_steps, chapter_step, persistent.ch_max_sub_steps, persistent.ch_sub_step)
return percentage
}
function is_work_allowed_here(pl, tool_id, name, pos, tool) {
local result = null // null is equivalent to 'allowed'
result = translate("Action not allowed")
local t = tile_x(pos.x, pos.y, pos.z)
local ribi = 0
local wt = 0
//local tmark = t.is_marked()
local buil = t.find_object(mo_building)
//if(buil)
//gui.add_message(""+buil.get_desc().get_name())
local depot = t.find_object(mo_depot_air)
//if(depot)
//gui.add_message(""+depot.get_desc().get_name())
local way = t.find_object(mo_way)
//local gcursor = t.find_object(mo_pointer)
//local cursor = null
//local hold_way = null
if (way){
wt = way.get_waytype()
if (tool_id!=4111)
ribi = way.get_dirs()
if (!t.has_way(gl_wt))
ribi = 0
}
if (tool_id==4096)
return null
switch (this.step) {
case 1:
local climate = square_x(pos.x, pos.y).get_climate()
//return climate
if (pot0==0){
if ((pos.x>=c1_track.a.x)&&(pos.y>=c1_track.a.y)&&(pos.x<=c1_track.b.x)&&(pos.y<=c1_track.b.y)){
if (way && way.get_name() != obj1_way_name){
if(tool_id == tool_remover || tool_id == tool_remove_way) return null
result = format(translate("The track is not correct it must be: %s, use the 'Remove' tool"),translate(obj1_way_name)) + " ("+c1_start.tostring()+")."
if(tool_id == tool_build_way) return result
}
else if (way) result = translate("The track is correct.")
if(tool_id == tool_build_way) return null
}
else return translate("Build here") + ": ("+c_way.tostring()+")!."
}
else if (pot0==1 && pot1==0){
if (pos.x == c2_track.a.x && pos.y == c2_track.a.y){
if(tool_id == tool_remover || tool_id == tool_remove_way) return result
else if(tool_build_way) return null
}
if ((pos.x>=c2_track.a.x)&&(pos.y>=c2_track.a.y)&&(pos.x<=c2_track.b.x)&&(pos.y<=c2_track.b.y)){
if (way && way.get_name() != obj2_way_name){
if(tool_id == tool_remover || tool_id == tool_remove_way) return null
result = format(translate("The track is not correct it must be: %s, use the 'Remove' tool"),translate(obj2_way_name)) + " ("+c2_start.tostring()+")."
if(tool_id == tool_build_way){
return result
}
}
else if (way) result = translate("The track is correct.")
if(tool_id == tool_build_way) return null
}
else return translate("Build here") + ": ("+c_way.tostring()+")!."
}
else if (pot1==1 && pot2==0){
if(pos.x == city1_city7_air[0].x && pos.y == city1_city7_air[0].y){
if(tool_id == tool_build_way){
if (way){
return translate("The track is correct.")
}
else return null
}
if(tool_id == tool_build_station){
if(buil){
return translate("There is already a station.")
}
else return null
}
}
else return translate("Build here") + ": ("+city1_halt_airport[0].tostring()+")!."
}
else if (pot2==1 && pot3==0){
if(pos.x == city1_halt_airport_extension[0].x && pos.y == city1_halt_airport_extension[0].y){
if(tool_id == tool_build_station){
if (buil){
return translate("There is already a station.")
}
else return null
}
}
else return translate("Build here") + ": ("+city1_halt_airport_extension[0].tostring()+")!."
}
else if (pot3==1 && pot4==0){
if((pos.x == ch6_air_depot.b.x && pos.y == ch6_air_depot.b.y) || (pos.x == ch6_air_depot.a.x && pos.y == ch6_air_depot.a.y)){
if(tool_id == tool_build_way){
return null
}
if(tool_id == tool_build_depot){
if(depot){
return translate("The Hangar is correct.")
}
else return null
}
}
else return translate("Build here") + ": ("+ch6_air_depot.a.tostring()+")!."
}
else if (pot4==1 && pot5==0){
if(pos.x == city1_halt_airport[0].x && pos.y == city1_halt_airport[0].y){
if(tool_id == tool_make_stop_public){
if(buil){
return null
}
else return null
}
}
else return translate("Click on the stop") + " ("+city1_halt_airport[0].tostring()+")!."
}
break;
case 2:
if (tool_id==4108) {
/*for ( local j = 0; j < city1_city7_air.len(); j++ ) {
if (glsw[j]==0){
if(pos.x == city1_city7_air[j].x && pos.y == city1_city7_air[j].y) {
glsw[j]=1
return null
}
else return translate("Click on the stop") + " ("+city1_city7_air[j].tostring()+")!."
}
}*/
local c_list = city1_city7_air //Lista de todas las paradas de autobus
local c_dep = ch6_air_depot.a //Coordeadas del deposito
local siz = c_list.len() //Numero de paradas
result = translate("The route is complete, now you may dispatch the vehicle from the depot")+" ("+c_dep.tostring()+")."
return is_stop_allowed(result, siz, c_list, pos)
}
break;
case 3:
if (tool_id==4108) {
local c_list = city1_halt_airport //Lista de todas las paradas de autobus
local c_dep = city1_road_depot //Coordeadas del deposito
local siz = c_list.len() //Numero de paradas
result = translate("The route is complete, now you may dispatch the vehicle from the depot")+" ("+c_dep.tostring()+")."
return is_stop_allowed(result, siz, c_list, pos)
}
break;
case 4:
if (pot0==0){
if(pos.x == city7_road_depot.x && pos.y == city7_road_depot.y){
if(tool_id == tool_build_depot){
if(depot){
return translate("The Depot is correct.")
}
else return null
}
}
else return translate("Build here") + ": ("+city7_road_depot.tostring()+")!."
}
if (pot0==1 && pot1==0){
if (tool_id==4108) {
local c_list = city7_halt //Lista de todas las paradas de autobus
local c_dep = city7_road_depot //Coordeadas del deposito
local siz = c_list.len() //Numero de paradas
result = translate("The route is complete, now you may dispatch the vehicle from the depot")+" ("+c_dep.tostring()+")."
return is_stop_allowed(result, siz, c_list, pos)
}
}
break;
}
if (tool_id==4096)
return null
return result
}
function is_schedule_allowed(pl, schedule) {
local result=null // null is equivalent to 'allowed'
switch (this.step) {
case 2:
if ( schedule.waytype != wt_air )
result = translate("Only air schedules allowed")
reset_glsw()
local selc = get_waiting_halt(6)
local load = set_loading_capacity(5)
local time = set_waiting_time(8)
local c_list = city1_city7_air
result = compare_schedule(result, pl, schedule, selc, load, time, c_list, false)
if(result == null){
update_convoy_schedule(pl, wt_air, line1_name, schedule)
}
return result
break
case 3:
if ( schedule.waytype != wt_road )
result = translate("Only road schedules allowed")
reset_glsw()
local selc = get_waiting_halt(7)
local load = set_loading_capacity(6)
local time = set_waiting_time(9)
local c_list = city1_halt_airport
result = compare_schedule(result, pl, schedule, selc, load, time, c_list, true)
if(result == null){
update_convoy_schedule(pl, wt_road, line2_name, schedule)
}
return result
break
case 4:
if ( schedule.waytype != wt_road )
result = translate("Only road schedules allowed")
reset_glsw()
local selc = get_waiting_halt(8)
local load = set_loading_capacity(7)
local time = set_waiting_time(10)
local c_list = city7_halt
result = compare_schedule(result, pl, schedule, selc, load, time, c_list, true)
if(result == null){
update_convoy_schedule(pl, wt_road, line3_name, schedule)
}
return result
break
}
return translate("Action not allowed")
}
function is_convoy_allowed(pl, convoy, depot)
{
local result=null // null is equivalent to 'allowed'
switch (this.step) {
case 2:
local wt = gl_wt
if ((depot.x != ch6_air_depot.a.x)||(depot.y != ch6_air_depot.a.y))
return translate("You must select the deposit located in")+" ("+ch6_air_depot.a.tostring()+")."
if (current_cov>ch6_cov_lim1.a && current_covch6_cov_lim2.a && current_covch6_cov_lim3.a && current_cov ch6_cov_lim1.a && current_cov< ch6_cov_lim1.b){
local pl = player
local c_depot = my_tile(ch6_air_depot.a)
try {
comm_destroy_convoy(pl, c_depot) // Limpia los vehiculos del deposito
}
catch(ev) {
return null
}
local sched = schedule_x(gl_wt, [])
local c_list = city1_city7_air
for(local j = 0; jch6_cov_lim2.a && current_covch6_cov_lim3.a && current_cov= coorb.x && coora.y == coorb.y){
coora.x--
dir_start = 8
}
else if(coora.x <= coorb.x && coora.y == coorb.y){
coora.x++
dir_start = 2
}
else if(coora.x == coorb.x && coora.y >= coorb.y){
coora.y--
dir_start = 4
}
else if(coora.x == coorb.x && coora.y <= coorb.y){
coora.y++
dir_start = 1
}
break
}
local tile_test = tile_x(coora.x, coora.y, coora.z)
local way_test = tile_test.find_object(mo_way)
if (!way_test){
return {c = sve_coord, result = false}
}
way_start.unmark()
tile_start.remove_object(player_x(1), mo_label)
while(true){
local current_dir = 0
local tile = tile_x(coora.x, coora.y, coora.z)
local way = tile.find_object(mo_way)
if(way){
way.unmark()
local current_wt = way.get_waytype()
if(current_wt != wt){
way.mark()
public_label(tile_start, name)
return {c = coora, result = false}
}
local current_name = way.get_name()
for(local j = 0;j