Trackmania 2, mazes and labyrinths

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

krial057
Posts: 57
Joined: 13 Nov 2010, 20:15

Re: Trackmania 2, mazes and labyrinths

Post by krial057 »

Nice screenshot :D
Yes, the maniaplanet scripteditor sucks some times... It would be nice if NADEO would release a standalone compiler to use with other scripting programs...

Btw, got a new best time: 00:33:08
(In the map of the copy-paste script)

If you don't get it, i'll post my replay ;)

regards Alain
User avatar
SurferIX
Posts: 79
Joined: 10 May 2011, 16:14
Contact:

Re: Trackmania 2, mazes and labyrinths

Post by SurferIX »

When I talked about ameliorations, some screenshots explain better than me:

Here's the "basic maze" which works but it's not really nice-looking:
Image

Now here's the revamped maze: the same but quit very nice-looking:
Image

You can see by yourself what it gives by night:
Image

In case you didn't notice, the ManiaScript re-vamp creates tunnels and nice corners:
Image


Here's the link to the night maze: 15x15x3.txt

Enjoy!
http://olivierpons.fr
Mon dernier framework hautes performances : http://www.papdevis.fr
User avatar
SurferIX
Posts: 79
Joined: 10 May 2011, 16:14
Contact:

Re: Trackmania 2, mazes and labyrinths

Post by SurferIX »

And finally here are 2 screenshots of a special tunnel (that is automagically generated, of course, nothing by hand):

Image

Image

Here's the link to this ManiaScript maze: 04x04x12.txt
http://olivierpons.fr
Mon dernier framework hautes performances : http://www.papdevis.fr
qllpBernD
Posts: 4
Joined: 03 Mar 2011, 18:17

Re: Trackmania 2, mazes and labyrinths

Post by qllpBernD »

i am getting an error when i try to lanch your script:

[66, 35] Uncontrolled access to parameter : BlockModels[##ArenaFloodLightBaseCeiling]
User avatar
SurferIX
Posts: 79
Joined: 10 May 2011, 16:14
Contact:

Re: Trackmania 2, mazes and labyrinths

Post by SurferIX »

Yep it seems they've renamed some blocs, and moreover the plugin "ExampleBlockModelInCursor", which gave the name of the current Bloc, doesn't work :roflol: So I don't know if the bloc still exists, and if so, what's its name :cry:

Anyway just comment out the line 112 (= add slash slash):

// TypeBloc = "ArenaFloodLightBaseCeiling";
http://olivierpons.fr
Mon dernier framework hautes performances : http://www.papdevis.fr
User avatar
SurferIX
Posts: 79
Joined: 10 May 2011, 16:14
Contact:

Re: Trackmania 2, mazes and labyrinths

Post by SurferIX »

It's done! :roflol:

I've made it! :yes:

I did it! 8-)

I've finished my new Maze Script generator.
I can say without shame that I can generate the biggest maze ever done in all TM versions.

I've just generated the smallest possible: 5 x 4... but it has 24 floors. Yes sir, 24 floors.
Just to test.
Here you go, a small splash then my script:

Image

To make it work here a the steps:
- go in the TM² user scripts folder. It's usually:

Code: Select all

C:/Users/NomUtilisateur/Documents/ManiaPlanet/Scripts/EditorPlugins/TrackMania
For example for me it's:

Code: Select all

C:/Users/Olivier/Documents/ManiaPlanet/Scripts/EditorPlugins/TrackMania
- create a new text document (right click => New => Text file);
- give it a simple name ending with "txt", for example: "Laby.txt";
- open it;
- come back here, copy-paste the code below into the file;
- save and close it;
- launch TM²;
- go into the editor (advanced mode (shall I precise?));
- choose plugin menu (bottom on the right) ;
- and now you should see the name of the file (for example "Laby");
- click on it, a menu appears, click on "calculer" and let the magic begin!
There's no start and end, it's up to you to put them wherever you want.

Here's my script for the "5x4" "x24 floors" :

Code: Select all

#RequireContext CGameCtnEditorPluginScriptHandler
#Include "MapUnits" as MapUnits
#Include "MathLib" as MathLib
#Const BIT_N        1
#Const BIT_E        2
#Const BIT_S        4
#Const BIT_O        8
#Const BIT_MONTEE_N 16
#Const BIT_MONTEE_E 32
#Const BIT_MONTEE_S 64
#Const BIT_MONTEE_O 128
#Const BIT_DESCENTE_N 256
#Const BIT_DESCENTE_E 512
#Const BIT_DESCENTE_S 1024
#Const BIT_DESCENTE_O 2048
#Const BIT_U  4096
#Const BIT_D  8192
Text CreateManialink()
{
  declare MLText =
  """
    <script><!--
      Void UpdateTxtDebug() {
        declare Text TxtDebug for Page;
        declare TxtDebugCtrl <=> (Page.GetFirstChild("TxtDebugPlacedValue") as CGameManialinkLabel);
        TxtDebugCtrl.SetText( TxtDebug );
      }
      Void OnPlaceBlocks()
      {
        declare Boolean StartPlacing for Page;
        if(!StartPlacing) {
          StartPlacing = True;
        }
      }
      main ()
      {
        while(True) {
          yield;
          UpdateTxtDebug();
          foreach(Event in PendingEvents) {
            if(Event.Type == CGameManialinkScriptEvent::Type::MouseClick) {
              if (Event.ControlId == "PlaceQuad") {
                OnPlaceBlocks();
              }
            }
          }
        }
      }
    --></script>
    <frame>
      <quad id="PluginTitleQuad" posn="-138 82 1" sizen="42 13"
        halign="center" valign="center" style="Bgs1InRace"
        substyle="BgTitle3_1"/>
      <label id="PluginTitleLabel" text="Labyz"
        posn="-138 82 1" halign="center" valign="center" style="TextTitle3"/>
      <quad id="PluginQuad" posn="-138 76 1" sizen="38 22"
        halign="center" valign="top" style="Bgs1"
        substyle="BgList" ScriptEvents="1"/>
      <!-- quad id="PluginQuad" posn="-156 76 1" sizen="200 28"
        halign="left" valign="top" style="Bgs1"
        substyle="BgList" ScriptEvents="1"/ -->
      <label id="LabySizeLabel"
        text="Size : 5 x 4 x 24"
        posn="-138 73 1" halign="center" valign="center"
        textsize="2"/>
      <label id="TxtDebugPlacedValue" text="0"
        posn="-152 68 2" sizen="200 5"
        halign="left" valign="center" textsize="2"/>
      <quad id="PlaceQuad" posn="-138 60 4" sizen="30 6"
        halign="center" valign="center" style="Bgs1InRace"
        substyle="BgCard" ScriptEvents="1"/>
      <label id="PlaceLabel" text="CALCULER" posn="-138 60 4"
        halign="center" valign="center" style="TextButtonSmall"
        textsize="2"/>
    </frame>
  """;
  return MLText;
}
Void PB(Text BlockName, Integer X, Integer Y,
        Integer Z,::CardinalDirections Dir)
{
    PlaceBlock(BlockModels[BlockName], <X, Y, Z >, Dir);
}
Void PlaceStart(Integer X, Integer Z, Integer Y,::CardinalDirections Dir,
                Integer CoordYBaseSol)
{
    PB("ArenaStart", 1 + (X * 2), CoordYBaseSol + (Y * 2), 1 + (Z * 2),
       Dir);
}
Void PlaceFinish(Integer X, Integer Z, Integer Y,::CardinalDirections Dir,
                 Integer CoordYBaseSol)
{
    PB("ArenaFinish", 1 + (X * 2), CoordYBaseSol + (Y * 2), 1 + (Z * 2),
       Dir);
}
Void PlaceUp(Integer X, Integer Z, Integer Y,::CardinalDirections Dir,
             Integer CoordYBaseSol)
{
    declare Integer Xl = X;
    declare Integer Yl = CoordYBaseSol + Y + 1;
    declare Integer Zl = Z;
    PB("RoadMainSlopeBase", Xl, Yl, Zl, Dir);
    yield;
}
Boolean BitSet(Integer Val, Integer Bit)
{
    return (((Val / Bit) % 2) > 0);
}
/////////////////////////////////////
// Draw the laby
Void DrawLaby(Integer[] Tab,
              Integer XSize, Integer ZSize, Integer YSize,
              Integer CoordYBaseSol)
{
    //log(CursorBlockModel.Id);
    //return;
    /* (!) Appel de Drawlaby avec les params XYZ de mon
     * laby c'est à dire XY = sol, Z = hauteur
     * => pour convertir en coord TM², on dit que les params
     *    de DrawLaby sont X, Z, Y
     */
    declare Text TxtDebug for ManialinkPage;
    declare Integer XMax = XSize
        -1;
    declare Integer ZMax = ZSize - 1;
    declare Integer YMax = YSize - 1;
    declare Boolean BitN;
    declare Boolean BitE;
    declare Boolean BitS;
    declare Boolean BitO;
    declare Integer Pos;
    declare Integer Val;
    declare Integer BaseY = CoordYBaseSol + 1;
    declare Integer Deb;
    declare Integer Fin;
    /* (!!) Bogue PlaceRoadBlocks() ignore le paramètre bloc,
     *      et ne se base que sur le bloc du curseur en cours,
     *      donc pour rester "propre" je force le bloc en cours,
     *      puis je ne me sers que de lui :
     */
    CursorBlockModel = BlockModels["RoadMain"];
    /* (!) Ici les coordonnées sont à la TM² (Y = hauteur) */
    for (Y, 0, YMax) {
        TxtDebug = "Computing (" ^ Y ^ "/" ^ (YMax*2) ^ ")";
        yield;
        for (Z, 0, ZMax) {
            Deb = -1;
            Fin = -1;
            for (X, 0, XMax) {
                Pos = X + (Z * XSize) + (Y * XSize * ZSize);
                if (BitSet( Tab[Pos], BIT_O )) {
                    if (Deb<0) {
                      Deb = X;
                    }
                    if (Fin<0) {
                      Fin = Deb + 1;
                    }
                    else {
                      Fin += 1;
                    }
                }
                else {
                    if (Deb>=0) {
                        log("O => X = " ^ X ^ ", Y = " ^ Y ^ ", Z = " ^ Z ^ ", Deb = " ^ Deb ^ ", Fin = " ^ Fin);
                        PlaceRoadBlocks(CursorBlockModel,
                          <Deb, Y+BaseY, Z>, <Fin, Y+BaseY, Z>);
                        Deb = -1;
                        Fin = -1;
                    }
                }
            }
            yield;
        }
        TxtDebug = "Computing (" ^ (Y+1) ^ "/" ^ (YMax*2) ^ ")";
        yield;
        for (X, 0, XMax) {
            Deb = -1;
            Fin = -1;
            for (Z, 0, ZMax) {
                Pos = X + (Z * XSize) + (Y * XSize * ZSize);
                if (BitSet( Tab[Pos], BIT_N )) {
                    if (Deb<0) {
                      Deb = Z;
                    }
                    if (Fin<0) {
                      Fin = Deb + 1;
                    }
                    else {
                      Fin += 1;
                    }
                }
                else {
                    if (Deb>=0) {
                        log("N => X = " ^ X ^ ", Y = " ^ Y ^ ", Z = " ^ Z ^ ", Deb = " ^ Deb ^ ", Fin = " ^ Fin);
                        PlaceRoadBlocks(CursorBlockModel,
                          <X, Y+BaseY, Deb>, <X, Y+BaseY, Fin>);
                        Deb = -1;
                        Fin = -1;
                    }
                }
            }
            yield;
        }
    }
}
/////////////////////////////////////
// Vérifie si un bloc est totalement vide
// ou le bloc est vide au sol = "Dirt"
Boolean EstVideOuDirt(Integer X, Integer Y, Integer Z)
{
    declare CGameCtnBlock B = GetBlock(<X, Y, Z >);
    if (B == Null) {
        return True;
    }
    return (B.BlockModel.Id == "Dirt");
}
/////////////////////////////////////
// Vérifie si un bloc est totalement vide
Boolean EstVide(Integer X, Integer Y, Integer Z)
{
    declare CGameCtnBlock B = GetBlock(<X, Y, Z >);
    return (B == Null);
}
/////////////////////////////////////
// Return ValRetour if Block is of known type
Integer ValIf(Integer X, Integer Y, Integer Z,
              Integer ValRetour, Text[]ListBlocsAcceptables)
{
    declare CGameCtnBlock B = GetBlock(<X, Y, Z >);
    if (B != Null) {
        if (ListBlocsAcceptables.exists(B.BlockModel.Id)) {
            return ValRetour;
        }
    }
    return 0;
}
/////////////////////////////////////
// Place all blocks
Void PlaceBlocks()
{
    declare Text TxtDebug for ManialinkPage;
    declare CBlockModel BMArenaSimpleBase;
    BMArenaSimpleBase
        <=>BlockModels["ArenaSimpleBase"];
    RemoveAllBlocksAndTerrain();
    ComputeShadows();
    yield;
    // Calculer la hauteur du sol = la hauteur minimale pour
    // poser le bloc :
    declare CoordYBaseSol = GetBlockGroundHeight(BMArenaSimpleBase, 19,
                                                 19,::
                                                 CardinalDirections::East);
    DrawLaby([
     // Etage 0
          1,     1,     1,     9,     3,
          5,    13,     6,    20,     5,
          5,     5,     1,     1,     5,
         12,    14,    14,    14,     6,

     // Etage 1
          1,     1,     1,     8,     3,
         13,    15,     6,     0,     5,
          5,    20,     1,   257,     5,
         12,    10,    14,    14,     6,

     // Etage 2
          1,     1,     1,     8,     3,
         13,    14,     6,    65,     5,
          5,     0,     9,     7,     5,
         12,   266,     6,    12,     6,

     // Etage 3
          1,     1,     9,  1026,     1,
         13,    14,     6,     0,     5,
          5,    65,     1,     1,     5,
         12,    14,    14,    14,     6,

     // Etage 4
          1,     1,     1,     8,     3,
          5,  1036,     7,    65,     5,
          5,     0,     5,     5,     5,
         12,    10,    14,    14,     6,

     // Etage 5
          1,     1,     1,  1032,     3,
         13,    14,     6,     0,     5,
         13,   130,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 6
          1,     1,     1,     8,     3,
         13,    14,     6,    65,     5,
          5,     0,   521,     7,     5,
         12,    10,     6,    12,     6,

     // Etage 7
          1,     1,     1,  1032,     3,
         13,    15,     6,     0,     5,
          5,    20,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 8
          1,     1,     1,     8,     3,
         13,    14,     6,    65,     5,
          5,     0,     9,     7,     5,
         12,   266,     6,    12,     6,

     // Etage 9
          1,     1,     1,  1032,     3,
         13,    15,     6,     0,     5,
          5,    20,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 10
          1,     1,     1,     8,     3,
         13,    14,     6,    65,     5,
          5,     0,     9,     7,     5,
         12,   266,     6,    12,     6,

     // Etage 11
          1,     1,     9,  1026,     1,
         13,    14,     6,     0,     5,
          5,    40,     3,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 12
          1,     1,     9,    10,     3,
         13,    14,    14,   130,     5,
       2053,     0,     1,     1,     5,
          4,     8,    14,    14,     6,

     // Etage 13
          1,     1,     1,     8,     3,
         13,    14,     6,     0,   517,
         13,   130,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 14
          1,     1,     9,     3,     1,
         13,    14,     6,    20,     5,
          5,     0,   513,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 15
          1,     1,     9,    10,     3,
         13,    14,     6,     0,     5,
          5,    65,     1,   257,     5,
         12,    14,     6,    12,     6,

     // Etage 16
          1,     1,     9,    11,     3,
          5,  1036,     6,    20,     5,
          5,     0,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 17
          1,     1,     1,     8,     3,
         13,    15,     6,     0,     5,
          5,    20,     1,   257,     5,
         12,    10,    14,    14,     6,

     // Etage 18
          1,     1,     1,     8,     3,
         13,    14,    14,   130,     5,
          5,     0,     1,     1,     5,
         12,   266,    14,    14,     6,

     // Etage 19
          1,     1,     9,    10,     3,
         13,    14,     6,     0,   516,
          5,    65,     1,     1,     1,
         12,    14,    14,    14,     6,

     // Etage 20
          1,     1,     9,    10,     3,
          5,  1036,    14,   130,     5,
          5,     0,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 21
          1,     1,     1,     8,     3,
         13,    14,     6,     0,   517,
         13,   130,     1,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 22
          1,     1,     1,     8,     3,
         13,    14,     6,    40,     7,
          5,     0,   513,     1,     5,
         12,    10,    14,    14,     6,

     // Etage 23
          1,     1,     9,    10,     3,
          5,     5,  2052,     0,     5,
          5,     5,     1,     1,     5,
         12,    14,    14,    14,     6

    ],
    5,4,24,
    CoordYBaseSol);


  // Up <=> Down slopes :
    PlaceUp( 3, 1, 0, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 1, 2, 1, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 3, 1, 2, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 1, 2, 3, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 3, 1, 4, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 1, 2, 5, ::CardinalDirections::West, CoordYBaseSol);

    PlaceUp( 3, 1, 6, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 1, 2, 7, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 3, 1, 8, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 1, 2, 9, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 3, 1, 10, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 1, 2, 11, ::CardinalDirections::East, CoordYBaseSol);

    PlaceUp( 3, 1, 12, ::CardinalDirections::West, CoordYBaseSol);

    PlaceUp( 1, 2, 13, ::CardinalDirections::West, CoordYBaseSol);

    PlaceUp( 3, 1, 14, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 1, 2, 15, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 3, 1, 16, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 1, 2, 17, ::CardinalDirections::North, CoordYBaseSol);

    PlaceUp( 3, 1, 18, ::CardinalDirections::West, CoordYBaseSol);

    PlaceUp( 1, 2, 19, ::CardinalDirections::South, CoordYBaseSol);

    PlaceUp( 3, 1, 20, ::CardinalDirections::West, CoordYBaseSol);

    PlaceUp( 1, 2, 21, ::CardinalDirections::West, CoordYBaseSol);

    PlaceUp( 3, 1, 22, ::CardinalDirections::East, CoordYBaseSol);


    log("Done !");
    TxtDebug = "Done !";
}
/////////////////////////////////////
// Main
main()
{
    declare Integer NbBlocks for ManialinkPage;
    declare Boolean StartPlacing for ManialinkPage;
    ManialinkText
        = CreateManialink();
    while (True) {
        yield;
        if (StartPlacing) {
            PlaceBlocks();
            StartPlacing = False;
        }
    }
}
/////////////////////////////////////
http://olivierpons.fr
Mon dernier framework hautes performances : http://www.papdevis.fr
User avatar
SurferIX
Posts: 79
Joined: 10 May 2011, 16:14
Contact:

Re: Trackmania 2, mazes and labyrinths

Post by SurferIX »

I'm sorry to multi-post here, but here's the biggest maze you can create in TM² with "progressive" screenshots.

Image

Image

And the final one:
Image

You can copy paste the huge script to test the render on your own PC from here:

http://olivierpons.fr/download/trackmania2/32x32x24.txt

Enjoy!

This map is worth 156 216 coppers :roflol:
http://olivierpons.fr
Mon dernier framework hautes performances : http://www.papdevis.fr
Frank87
Posts: 28
Joined: 05 Sep 2011, 16:10

Re: Trackmania 2, mazes and labyrinths

Post by Frank87 »

Oh holy mother fucking god :shock:
Edit: The big maze did not generate finish line or start. It's no problem adding them myself but maybe you could edit it? =)
User avatar
SurferIX
Posts: 79
Joined: 10 May 2011, 16:14
Contact:

Re: Trackmania 2, mazes and labyrinths

Post by SurferIX »

You're right I wanted to develop a function that looks for a dead end at the bottom and puts the start, then same for up and put the finish. This is the missing part ;)
http://olivierpons.fr
Mon dernier framework hautes performances : http://www.papdevis.fr
EntropicLqd
Posts: 16
Joined: 16 Jun 2010, 16:47

Re: Trackmania 2, mazes and labyrinths

Post by EntropicLqd »

Impressive.

As someone who has written labyrinth* generators in all sorts of languages (C, Javascript, C++, Java, C#, 6502 assembler, plus others) I can appreciate the effort that went into that although I've not looked deeply at the algorythm you've used.

When I eventually get around to getting TM2 (holding off buying it because I know it'll suck all my life away) I'll totally have to write a maze generator in Maniascript just to see how it compares with the others.

* For the uninitiated, a labyrinth may only have a single path between any two points in the map. A maze may have multiple paths between any two points. So for the mathematicians; labyrinths are a sub-set of mazes.
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 1 guest