J'ai terminé mon nouveau "générateur" de Script.
Je peux dire sans honte et sans éxagérer que je peux générer le plus grand labyrinthe jamais crée de tous les TM existants.
J'ai généré le plus petit possible : 5 x 4... mais sur 24 étages. OUI OUI môsieur, 24 étages.
Juste pour tester.
- allez dans le répertoire de script de TM². En général c'est :
- faites un nouveau document "texte" (bouton droit => Nouveau => document texte) ;
- cliquez dessus, et une boite va s'ouvrir, cliquez sur calcul et laissez la magie opérer !
Il manque juste un départ et une arrivée, à vous de la mettre où vous voulez.
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;
}
}
}
/////////////////////////////////////