Author Topic: Rail engine (complex)  (Read 1840 times)

0 Members and 1 Guest are viewing this topic.

Offline b@nditoTopic starter

  • Jr. Member
  • **
  • Posts: 48
  • Activity:
    0%
  • Reputation Power: 0
  • b@ndito has no influence.
  • Respect: +5
  • Referrals: 0
    • View Profile
Rail engine (complex)
« on: March 12, 2010, 01:46:12 AM »
0
i made a new rail writer based on persistent variables, it works just like others that saves variables in a file but is quicker (needs about 1-2 seconds to write a 15 steps rail againts the 35 of CEO's), it also offer the possibility to change to or from a part of the rail and more, i think it's a great script but i'm not really satisfied of the reading/running subs i made up.
an axample of a variable written is:

<AlganderPersistentRail>TS:11Facet:1|X:5484Y:567|X:5484Y:573|X:5484Y:577|X:5484Y:583|X:5481Y:589|X:5474Y:594|X:5468Y:597|X:5467Y:603|X:5464Y:609|X:5458Y:615|X:5451Y:616|

the engine subs i put up

Code: [Select]
set %numberofplaces 3


gosub check_existing_rails
for %n 1 %numberofplaces
    {
    if %esiste_rail . %n = #false
       goto skip_rail
    set %string * . rail . %n
    str del %string 1 23
    set %string #strres
    gosub pickvalue TS: f
    set %tot_steps #result
    set %ts_ . rail , %n %tot_steps
    gosub pickvalue facet: |
    set %facet #result
    for %i 1 %tot_steps
        {
        gosub pickvalue |x: y
        set %x . %i , rail , %n #result
        gosub pickvalue y: |
        set %y . %i , rail , %n #result
        }
    skip_rail:
    }

display caricate tutte le rail
;halt
for %f 1 %numberofplaces
if %esiste_rail . %nruneatt = #true
   {
   for %i 1 %TS_ . rail , %nruneatt
   event pathfind %x . %i , rail , %n %y . %i , rail , %n
   }


sub pickvalue
;|^|%1 etichetta del valore %2 delimitatore |^|
;|^|cancella etichetta e valore |^|
;|^|ritorna il valore trovato |^|
;|^|false se non viene trovato niente |^|
set %currpos 0
str len %1
str del %string 1 #strres
set %string #strres
str len %string
set %fine #strres
str left %string 1
while %2 notin #strres
{
set %currpos %currpos + 1
str left %string %currpos
if %2 in #strres
      {
        set %currpos %currpos - 1
str left %string %currpos
set %fndval #strres
str del %string 1 %currpos
set %string #strres
return %fndval
}
if %currpos = %fine
break
}
return error

sub check_existing_rails

for %r 1 %numberofplaces
    {
    set %prova_string * . rail . %r
    if <AlganderPermanentRail> notin %prova_string
       set %esiste_rail . %r #false
    else
       set %esiste_rail . %r #true
    }
return

sorry for italian naming  but i did not thought of publishing it... if someone could read it and help me making it more efficient i would be really grateful.
i have mainly problems of pathfinding (doesn't arrive at the spot, has problem with stairs, skips spots)...
         

Tags: