News:

Simutrans.com Portal
Our Simutrans site. You can find everything about Simutrans from here.

[Patch] Get version of simutrans

Started by Yona-TYT, August 07, 2021, 07:12:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


Dwachs

Parsley, sage, rosemary, and maggikraut.

Yona-TYT

Thank you very much for the implementation.  8) 
This is the experiment I wanted to do:  :P

function string_analyzer()
{
    local result = {pak= false , st = false}

    //Check version and pakset name
    current_pak = get_pakset_name()
    current_st = get_version_number()

    local p_siz = {a = current_pak.len(), b = pak_name.len()}


    //Pak name analyzer
    local siz_a = max(p_siz.a, p_siz.a)
    local count_a = 0
    local tx_a = ""
    for(local j=0;j<siz_a;j++){
        try {
            pak_name[count_a]
        }
        catch(ev) {
            break
        }
        if(count_a>0 && current_pak[j]!=pak_name[count_a]){
            break
        }
        if(current_pak[j]==pak_name[count_a]){
            tx_a += format("%c",current_pak[j])
            count_a++
            continue
        }
    }
    if(pak_name == tx_a) result.pak = true
    //gui.add_message("Current: "+current_pak+"  Tx: "+tx_a+"  Pak: "+pak_name+" result: "+result.pak)

    local s_siz = {a = current_st.len(), b = simu_version.len()}
    local siz_b = max(s_siz.a, s_siz.a)

    local nr_a = 0
    local nr_b = 0

    while(nr_a<s_siz.a || nr_b<s_siz.b){
        local value_a = ""
        for(local j=nr_a;j<s_siz.a;j++){
            local tx = format("%c",current_st[j])
            try {
                tx.tointeger()
            }
            catch(ev) {
                if(tx=="."){
                    nr_a = j+1
                    break
                }
                nr_a++
                continue
            }
            value_a+=tx
        }

        local value_b = ""
        for(local j=nr_b;j<s_siz.b;j++){
            local tx = format("%c",simu_version[j])
            if(tx=="."){
                nr_b = j+1
                break
            }
            value_b+=tx
            if(j == s_siz.b-1)nr_b = s_siz.b
        }
        try {
            value_a.tointeger()
            value_b.tointeger()
        }
        catch(ev) {
            continue
        }
        //gui.add_message("value_a "+value_a.tointeger()+"  value_b "+value_b.tointeger()+"")
        if(value_a.tointeger()<value_b.tointeger()){
            result.st = false
            break
        }
        result.st = true
    }
    //gui.add_message("result st: "+result.st+"  result pak:" +result.pak)
    return result
}