Skip to content

Commit

Permalink
Bugs fix, useless code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Yona-TYT committed Aug 12, 2021
1 parent cc826e2 commit 75fd7a6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 117 deletions.
52 changes: 18 additions & 34 deletions class/class_basic_chapter.nut
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class basic_chapter

function comm_start_convoy(pl, wt, sched, cov_list, depot)
{
lin_flag = true
pl.create_line(wt)
// find the line - it is a line without schedule and convoys
local list = pl.get_line_list()
Expand Down Expand Up @@ -581,7 +580,7 @@ class basic_chapter

function is_waystop_correct(player,schedule,nr,load,wait,coord, c_all = false)
{
local result = null
local result = 0
// coord = x,y,z place to compare the waystop
// nr = number of schedule.entrie to compare
local nr2 = schedule.entries.len()-1
Expand All @@ -603,7 +602,12 @@ class basic_chapter

local halt = entrie.get_halt( player_x(player) )
local targ_t = this.my_tile(coord)
local target = targ_t.get_halt()

local target = square_x(coord.x,coord.y).get_halt()
local target_list = square_x(coord.x,coord.y).get_halt_list()



if (!halt) return translate("The schedule is not correct.")
local t_list = halt.get_tile_list()
local t2_list = targ_t.is_water() ? get_tiles_near_factory(t_list) : target.get_tile_list()
Expand All @@ -620,20 +624,19 @@ class basic_chapter
else if((c_buld1.x == c_buld2.x) && (c_buld1.y == c_buld2.y)) {
result = null
}
else{

if (result!=null){
local text = ttext("The waystop {nr} '{name}' isn't on place {pos}")
text.name = target.get_name()
text.name = target_list[0].get_name()
text.pos = pos_to_text(coord)
text.nr = (nr_st+1)
result = text.tostring()
return result
}
if (result!=null)
return result

if (entrie.load != load) {
local text = ttext("The load of waystop {nr} '{name}' isn't {load}% {pos}")
text.name = halt.get_name()
text.name = target_list[0].get_name()
text.pos = pos_to_text(coord)
text.load = load
text.nr = (nr+1)
Expand All @@ -644,7 +647,7 @@ class basic_chapter
//gui.add_message(""+entrie.wait+"")
local text = ttext("The waittime in waystop {nr} '{name}' isn't {wait} {pos}")
local txwait = get_wait_time_text(wait)
text.name = halt.get_name()
text.name = target_list[0].get_name()
text.pos = pos_to_text(coord)
text.wait = txwait
text.nr = (nr+1)
Expand Down Expand Up @@ -2424,34 +2427,15 @@ class basic_chapter
local x = c.x+dx
local y = c.y+dy

if (x>=0 && y>=0) area.append( (x << 16) + y );
}
}
}
return get_find_places(area)
}

function get_find_places(area)
{
local list = []
// check for flat and empty ground
for(local i = 0; i<area.len(); i++) {

local h = area[i]
if (i>0 && h == area[i-1]) continue;

local x = h >> 16
local y = h & 0xffff
if (x>=0 && y>=0 && world.is_coord_valid({x=x,y=y})){
local tile = square_x(x, y).get_ground_tile()
area.append( tile );

if (world.is_coord_valid({x=x,y=y})) {
local tile = square_x(x, y).get_ground_tile()


list.append(tile)

}
}
}
}
return list.len() > 0 ? list : []
return area.len() > 0 ? area : []
}

function check_water_tile(result, tile, pos, nr)
Expand Down
3 changes: 0 additions & 3 deletions class/class_chapter_02.nut
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,7 @@ class tutorial.chapter_02 extends basic_chapter
}

function is_schedule_allowed(pl, schedule) {
checks_current_line(pl, schedule)

local result=null // null is equivalent to 'allowed'

if ( (pl == 0) && (schedule.waytype != gl_wt) )
result = translate("Only road schedules allowed")
local nr = schedule.entries.len()
Expand Down
7 changes: 1 addition & 6 deletions class/class_chapter_03.nut
Original file line number Diff line number Diff line change
Expand Up @@ -1879,13 +1879,8 @@ class tutorial.chapter_03 extends basic_chapter
}

function is_schedule_allowed(pl, schedule) {
checks_current_line(pl, schedule)
if (!sch_flag)
reset_stop_flag()
sch_flag = false
local nr = schedule.entries.len()
local result=null // null is equivalent to 'allowed'

local nr = schedule.entries.len()
switch (this.step) {
case 5:
local selc = 0
Expand Down
2 changes: 0 additions & 2 deletions class/class_chapter_04.nut
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,6 @@ class tutorial.chapter_04 extends basic_chapter
}

function is_schedule_allowed(pl, schedule) {
checks_current_line(pl, schedule)

local result=null // null is equivalent to 'allowed'
local nr = schedule.entries.len()
switch (this.step) {
Expand Down
3 changes: 0 additions & 3 deletions class/class_chapter_05.nut
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,6 @@ class tutorial.chapter_05 extends basic_chapter
}

function is_schedule_allowed(pl, schedule) {

checks_current_line(pl, schedule)

local result=null // null is equivalent to 'allowed'
if ( (pl == 0) && (schedule.waytype != wt_road) )
result = translate("Only road schedules allowed")
Expand Down
1 change: 0 additions & 1 deletion class/class_chapter_06.nut
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ class tutorial.chapter_06 extends basic_chapter
function is_schedule_allowed(pl, schedule) {
local result=null // null is equivalent to 'allowed'
local nr = schedule.entries.len()
checks_current_line(pl, schedule)
switch (this.step) {
case 2:
reset_glsw()
Expand Down
69 changes: 1 addition & 68 deletions scenario.nut
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* Can NOT be used in network game !
*/
const version = 1600
const version = 1601
map.file = "tutorial.sve"
scenario_name <- "Tutorial Scenario"
scenario.short_description = scenario_name
Expand Down Expand Up @@ -75,7 +75,6 @@ correct_cov <- true
//----------------------------------------------------------------

sch_flag <- false //Bandera para schedule
lin_flag <- false //Bandera para line

tile_delay <- 2 //delay for mark tiles
tile_delay_list <- 2
Expand Down Expand Up @@ -509,72 +508,6 @@ function checks_all_convoys()
return cov_nr
}

function checks_current_line(pl, schedule)
{
local list = player_x(pl).get_line_list()
local l_nr = list.get_count()
local line = null
for(local j=0;j<l_nr;j++){
line = list[j]
if (line && line.is_valid()){
local sch = line.get_schedule()
local cov_list = line.get_convoy_list()

local cov_nr = 0
foreach(cov in cov_list) {
cov_nr++
}
if (sch && cov_nr==0){
local entrie = sch.entries
local sch1_nr = entrie.len()
local sch2_nr = schedule.entries.len()
local result = 0

if (sch1_nr>0 && sch1_nr==sch2_nr){
for(local i=0;i<sch1_nr;i++){
result = is_waystop_correct(pl, schedule, i, entrie[i].load, entrie[i].wait, coord(entrie[i].x, entrie[i].y))
if (result != null){
break
}
}
}
if (result != null)
continue
else {
sch_flag = true
return null
}
}
}
}
return null
}

function checks_all_line(pl)
{
local list = player_x(pl).get_line_list()
local l_nr = list.get_count()
local line = null
for(local j=0;j<l_nr;j++){
line = list[j]
if (line){
local cov_nr = 0
local cov_list = line.get_convoy_list()

if (cov_list.get_count()!=0)
continue

local sch = line.get_schedule()
local sch_nr = sch.entries.len()
if (sch && sch_nr==0){
line.destroy(player_x(pl))
}

}
}
return null
}

function get_line_name(halt)
{
local lin_list = halt.get_line_list()
Expand Down

0 comments on commit 75fd7a6

Please sign in to comment.