Skip to content

Commit

Permalink
Restructure in convoy analyzer removed
Browse files Browse the repository at this point in the history
  • Loading branch information
simustyt committed Jun 2, 2024
1 parent 1a12882 commit 0e78414
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 35 deletions.
44 changes: 35 additions & 9 deletions pak128.prototype/scenario/tutorial/class/class_basic_chapter.nut
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,38 @@ class basic_chapter

function update_convoy_removed(convoy, pl)
{
cov_save[current_cov]=convoy
id_save[current_cov]=convoy.id
if(correct_cov){
gcov_nr++
persistent.gcov_nr = gcov_nr
//gui.add_message("update_convoy_removed: "+convoy + " Correct "+correct_cov)
if(cov_save.len() <= current_cov) {
cov_save.push(convoy)
if(correct_cov){
gcov_nr++
persistent.gcov_nr = gcov_nr
current_cov = gcov_nr
persistent.current_cov = gcov_nr
}
}
else{
cov_save[current_cov]=convoy
if(correct_cov){
gcov_nr++
persistent.gcov_nr = gcov_nr
current_cov = gcov_nr
persistent.current_cov = gcov_nr
}
}
}

function is_cov_valid(cnv){
local result = true
// cnv - convoy_x instance saved somewhat earlier
try {
cnv.get_pos() // will fail if cnv is no longer existent
// do your checks
}
catch(ev) {
result = false
}
return result
}

function cov_pax(c, wt, good){
Expand Down Expand Up @@ -943,8 +969,8 @@ class basic_chapter
if (cov_dep.x == c_dep.x && cov_dep.y == c_dep.y){
//gui.add_message("("+cov.is_in_depot()+" .. "+cov.id+") .. ??"+id_end+"")
if(!cov.is_in_depot()){
for (local j =id_start ;j<id_end;j++){
if(cov.id == id_save[j]){
for (local j =id_start ;j<cov_save.len();j++){
if(cov.id == cov_save[j].id){
cov_nr++
break
}
Expand All @@ -962,8 +988,8 @@ class basic_chapter
if (cov_dep.x == c_dep.x && cov_dep.y == c_dep.y){
//gui.add_message("("+cov.is_in_depot()+" .. "+cov.id+") .. ??"+id_end+"")
if(!cov.is_in_depot()){
for (local j =id_start ;j<id_end;j++){
if(cov.id == id_save[j]){
for (local j =id_start ;j<cov_save.len();j++){
if(cov.id == cov_save[j].id){
cov_nr++
break
}
Expand Down
21 changes: 15 additions & 6 deletions pak128.prototype/scenario/tutorial/class/class_basic_convoys.nut
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,27 @@ class basic_convoys
if (id>gcov_id)
gcov_id = id

if (!cov.is_in_depot() && !ignore_save[id])
if (!cov.is_in_depot() && convoy_ignore(ignore_save, id))
cov_nr++
}
return cov_nr
}

function convoy_ignore(list, id)
{
for(local j = 0; j<list.len(); j++) {
if(list[j].id == id)
return false
}
return true
}

function checks_convoy_removed(pl)
{
local j = 0
local sw = true
for(j;j<gcov_nr;j++){
for(j;j<cov_save.len();j++){
//gui.add_message("checks_convoy_removed --- j "+ j)
local result = true
// cnv - convoy_x instance saved somewhat earlier
try {
Expand All @@ -81,12 +91,11 @@ class basic_convoys
persistent.current_cov = j
}
sw = false
break
}
if (result){
//gui.add_message(""+convoy_x(id_save[j]).is_in_depot()+"")
if (convoy_x(id_save[j]).is_in_depot()){
cov_save[j] = null

if (cov_save[j].is_in_depot()){
cov_save[j] = null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class tutorial.chapter_07 extends basic_chapter
return translate("The bus must be [Passengers].")
}
if (result == null){
ignore_save[convoy.id] = true //Ingnora el vehiculo
ignore_save.push({id = convoy.id, ig = true}) //Ingnora el vehiculo
return null
}
return result = translate("It is not allowed to start vehicles.")
Expand Down
43 changes: 24 additions & 19 deletions pak128.prototype/scenario/tutorial/scenario.nut
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ persistent.r_way_list <- {} //Save way list in fullway

//----------------------------------------------------------------

cov_save <- array(100) //Guarda los convoys en lista
id_save <- array(100) //Guarda id de los convoys en lista
ignore_save <- array(600) //Marca convoys ingnorados
cov_save <- [convoy_x(0)] //Guarda los convoys en lista
ignore_save <- [{id = -1, ig = true}] //Marca convoys ingnorados

persistent.ignore_save <- array(600)
persistent.id_save <- array(100)
persistent.ignore_save <- []

//-------------Guarda el estado del script------------------------
persistent.pot <- [0,0,0,0,0,0,0,0,0,0,0]
Expand Down Expand Up @@ -265,7 +263,8 @@ chapter <- tutorial.chapter_02 // must be placed here !!!

function script_text()
{

local pause = debug.is_paused()
if (pause) return gui.add_message(translate("Advance is not allowed with the game paused."))
if(!correct_cov){
gui.add_message(""+translate("Advance not allowed"))
return null
Expand Down Expand Up @@ -369,11 +368,11 @@ function get_info_text(pl)

function get_rule_text(pl)
{
//-------Debug ====================================
/*
local cov_nr_debug = "All convoys-> "+gall_cov+":: Convoys count-> "+gcov_nr+":: current covoy-> "+current_cov+":: Correct cov-> "+correct_cov+":: Convoy id-> "+gcov_id+"<br><br>"
local tx = ""
local j=0
for(j;j<gcov_nr;j++){
for(j;j<cov_save.len();j++){
local result = true
// cnv - convoy_x instance saved somewhat earlier
try {
Expand All @@ -390,13 +389,15 @@ function get_rule_text(pl)
}
if (result) {
tx += "<em>["+j+"]</em> id cov save: "+id_save[j]+" :: id conv: "+cov_save[j].id+" <a href=\"("+cov_save[j].get_pos().tostring()+")\"> ("+cov_save[j].get_pos().tostring()+")</a> "+cov_save[j].get_name()+"<br>"
tx += "<em>["+j+"]</em> "+cov_save[j].id+"::"+cov_save[j].id+" <a href=\"("+cov_save[j].get_pos().tostring()+")\"> ("+cov_save[j].get_pos().tostring()+")</a> "+cov_save[j].get_name()+" :: "+cov_save[j].id+"<br>"
}
else
tx += "<st>["+j+"]</st> "+id_save[j]+"::"+cov_save[j]+"<br>"
tx += "<st>["+j+"]</st> "+cov_save[j].id+"::"+cov_save[j]+"<br>"
}
return cov_nr_debug + tx
return tx
*/
//------------------------------------------------------------------------------------------------------------------------------------------------------------------
return chapter.give_title() + chapter.get_rule_text( pl, my_chapter() )
}

Expand Down Expand Up @@ -486,9 +487,10 @@ function labels_text_debug()

function is_scenario_completed(pl)
{
//labels_text_debug()
//-------Debug ====================================
//gui.add_message(""+glsw[0]+"")
//gui.add_message("!!!!!"+persistent.step+" ch a "+st_nr[0]+" !!!!! "+persistent.status.step+" -- "+chapter.step+"")
//gui.add_message("!!!!!"+persistent.step+" ch a "+st_nr[0]+" !!!!! "+persistent.status.step+" -- "+chapter.step+"")
//------------------------------------------------------------------------------------------------------------------------------
if (pl != 0) return 0 // other player get only 0%

if (currt_pos){
Expand All @@ -515,8 +517,9 @@ function is_scenario_completed(pl)
gui.open_info_win_at("goal")
gui_delay = false
}

//-------Debug ====================================
//gui.add_message(""+current_cov+" "+gall_cov+"")
//------------------------------------------------------------------------------------------------------------------------------
//Para los convoys ---------------------
if (gall_cov != current_cov){
basic_convoys().checks_convoy_removed(pl)
Expand All @@ -529,7 +532,10 @@ function is_scenario_completed(pl)
correct_cov = basic_convoys().correct_cov_list()
persistent.gall_cov = gall_cov

//gui.add_message("gall_cov-> "+gall_cov+":: gcov_nr-> "+gcov_nr+":: current_cov-> "+current_cov+":: Step-> "+chapter.step+":: PersisStep-> "+persistent.step+":: Status->"+persistent.status.step+"")
//-------Debug ====================================
//gui.add_message("gall_cov-> "+gall_cov+":: gcov_nr-> "+gcov_nr+":: current_cov-> "+current_cov+":: Step-> "+chapter.step+":: PersisStep-> "+persistent.step+":: Status->"+persistent.status.step+"")
//-------Debug ====================================
//------------------------------------------------------------------------------------------------------------------------------

if(!correct_cov) {
if (!resul_version.pak || !resul_version.st)
Expand Down Expand Up @@ -574,7 +580,7 @@ function is_scenario_completed(pl)
function is_work_allowed_here(pl, tool_id, pos)
{
local pause = debug.is_paused()
if (pause) return translate("Advance is not allowed with the game paused.")
//if (pause) return translate("Advance is not allowed with the game paused.")

//return tile_x(pos.x,pos.y,pos.z).find_object(mo_way).get_dirs()
if (pl != 0) return null
Expand Down Expand Up @@ -616,7 +622,7 @@ function fail_count_message(result, tool_id)
function is_schedule_allowed(pl, schedule)
{
local pause = debug.is_paused()
if (pause) return translate("Advance is not allowed with the game paused.")
//if (pause) return translate("Advance is not allowed with the game paused.")

local result = null

Expand All @@ -633,7 +639,7 @@ function is_schedule_allowed(pl, schedule)
function is_convoy_allowed(pl, convoy, depot)
{
local pause = debug.is_paused()
if (pause) return translate("Advance is not allowed with the game paused.")
//if (pause) return translate("Advance is not allowed with the game paused.")

local result = null
basic_convoys().checks_convoy_removed(pl)
Expand Down Expand Up @@ -707,7 +713,6 @@ function resume_game()
current_cov = persistent.current_cov
gcov_id = persistent.gcov_id
sigcoord = persistent.sigcoord
id_save = persistent.id_save
ignore_save = persistent.ignore_save

pot0=persistent.pot[0]
Expand Down

0 comments on commit 0e78414

Please sign in to comment.