Joined: Wed Oct 03, 2007 9:05 pm Posts: 18 Location: New Hampshire or Rhode Island
Posted: Tue Oct 20, 2009 1:27 pm Post subject: How to make a randomly generated maze
Code:
// Yup, it's this simple. -perrinoia function makeWall(%mkr) { %obj = newObject(Object::getName(%mkr), InteriorShape, "W64corner.dis"); // Create Wall %rnd = floor(getrandom() * 4); // Pick a #, 0-3 %p[0] = "16 0 0"; %r[0] = "0 0 0"; // If %rnd=0, Use these offsets %p[1] = "0 16 0"; %r[1] = "0 0 1.57079"; // If %rnd=1, Use these offsets %p[2] = "-16 0 0"; %r[2] = "0 0 3.14159"; // If %rnd=2, Use these offsets %p[3] = "0 -16 0"; %r[3] = "0 0 -1.57079"; // If %rnd=3, Use these offsets addToSet(nameToId("MissionCleanup/Labyrinth"), %obj); // Assign Wall to Group GameBase::setPosition(%obj, Vector::add(GameBase::getPosition(%mkr), %p[%rnd])); // Offset Positions GameBase::setRotation(%obj, Vector::add(GameBase::getRotation(%mkr), %r[%rnd])); // Offset Rotations GameBase::setTeam(%obj, %rnd % (getNumTeams() - 1)); // Set initial team based on Rotation }
addToSet("MissionCleanup", newObject("Labyrinth", SimGroup)); Group::iterateRecursive(nameToId("MissionGroup/Grid"), makeWall); // for each grid marker, make a wall.
First, you'll need a grid of Markers, 32 meters apart. All assigned to the group "MissionGroup/Grid". Then insert this code into your .mis file and the walls should appear the next time you load the mission. You may continue to edit the mission even after the walls have been created, when you hit save the walls will not be saved in that position. They will be forgotten, and the next time the mission is loaded, they will be recreated randomly again. (Note: If you use this mission as the default mission when you start your server, the maze will be identical everytime you start the server, however, if it is not the first mission loaded by the server, it will be truly random)
You can remove markers from the grid in the editor, and when you reload the mission, the wall that had spawned over that grid marker will not respawn. Thus you can then add a base for each team in the holes you created in the grid, or shape the grid to fit your arena, or add an objective surrounded by walls that aren't randomly rotated.
The maze does not change mid game, only when the mission is loaded.
Joined: Wed Oct 03, 2007 9:05 pm Posts: 18 Location: New Hampshire or Rhode Island
Posted: Tue Oct 20, 2009 1:36 pm Post subject: Re: How to make a randomly generated maze
Oh, your also welcome to download the whole map (using that link at the bottom of my post) and edit it to your liking, use different bases, what ever floats your minotaur.
Joined: Wed Oct 03, 2007 9:05 pm Posts: 18 Location: New Hampshire or Rhode Island
Posted: Tue Oct 20, 2009 6:03 pm Post subject: Re: How to make a randomly generated maze
Yeah, if you look at the last 2 pictures which were taken from an Observers point of view, you'll see the float base from Roller Coaster that houses the flags in the middle of the maze, although, in this case it houses a tower switch, which when claimed will change the team of all of the walls and the arena itself to match the colliding player's team, which means that the other team can no longer deploy turrets on any of those surfaces, makes it pretty difficult to defend your base. You may also notice in the middle and ontop of the newDam object which makes each team's base, that there is a flag stand, with a flag ontop.
I think I made it 8 team points to win, towerswitch = 1, which means you can either hold the objective and capture the enemy's flag 7 times, or capture the enemy's flag 8 times to win.
I'm gonna edit the map and add some bots... There will be one fat bot named Minotaur which will vigorously defend the objective, and one meak little bot per team, named MickyMouse and MiniMouse which will spawn near the flag and navigate the maze randomly in search for stray noobies. There may also be some cheese at the end of the maze.
I'll share the mice navigation code when I create it, but off the top of my head, I'm thinking it will probably use if(!GameBase::getLOSInfo(%mouse, 32, "0 0 "@ %r[%rnd])) to determine that there is no wall blocking that random direction, then set a waypoint at $LOS::Position, and the function will be called each time the mouse reaches it's waypoint that was randomly choosen the last time it reached a waypoint. Should be rather simple.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum