ID:180843
 
Okay, i have a map of 100 little battle areas. Now, whenever a person gets sucked into a battle (be it a random enemy or another player) i want the person to go to one of these battle areas, one that isn't already inhabited, that is. So, like i said, i'm sure its easy to do, but i just can't figure it out... Please help!
On 1/31/01 3:35 pm Cinnom wrote:
Okay, i have a map of 100 little battle areas. Now, whenever a person gets sucked into a battle (be it a random enemy or another player) i want the person to go to one of these battle areas, one that isn't already inhabited, that is. So, like i said, i'm sure its easy to do, but i just can't figure it out... Please help!


I'm sure it's doable, but to give you some ideas it would be helpful to know a little bit more about what you are planning.

I assume what you mean is that you have a map with 100 turfs, and a battle could occur on one of those turfs, at which time you want the player to go to an expanded map showing the battle area represented by the turf.

Is that correct?
In response to Deadron
I'm sure it's doable, but to give you some ideas it would be helpful to know a little bit more about what you are planning.

I assume what you mean is that you have a map with 100 turfs, and a battle could occur on one of those turfs, at which time you want the player to go to an expanded map showing the battle area represented by the turf.

Is that correct?

Okay, i don't think you have the idea. Here's the map of 100 battle areas. Whenever a person gets attacked, i want them to go to any one of these battle areas (one that is not already inhabited). Got it?

(erf, you're going to have to right click that link and choose to save target, clicking on it won't work)
On 1/31/01 3:35 pm Cinnom wrote:
Okay, i have a map of 100 little battle areas. Now, whenever a person gets sucked into a battle (be it a random enemy or another player) i want the person to go to one of these battle areas, one that isn't already inhabited, that is. So, like i said, i'm sure its easy to do, but i just can't figure it out... Please help!

It isn't all that easy... well, it is, but it's very hard to explain.

Essentially, the way I do it, I have /Game datums (not objs, or mobs, but top level).

Game
var
x
y
z
occupied = 0
New(x,y,z)
src.x = x
src.y = y
src.z = z

var/games[0]

world/New()
..()
games += new /Game(1,1,1)
games += new /Game(12,1,1)
games += new /Game(23,1,1) //and so on for each area you have

Then whenever a player tries to fight, do this:

proc/Battle(mob/M)
var/Game/game
for(game in global.games)
if(!game.occupied)
game.occupied = 1
M.loc = locate(game.x,game.y,game.z)

//behind the scenes battle stuff

break

Once they're done fighting, reset game.occupied to zero.

It works! =)


You can also do the same with areas... just add an x, y, z, and occupied var to each area, and then loop through all of the areas of the battle_area superclass (or whatever you use; I didn't check) when looking for a game.

Eg.

proc/Battle(mob/M)
var/area/battle_area/area
for(area) //short for 'for(area in world)'
if(!area.occupied)
area.occupied = 1
M.loc = locate(area.x,area.y,area.z)

//behind the scenes battle stuff

break
In response to Cinnom
On 1/31/01 4:53 pm Cinnom wrote:
Okay, i don't think you have the idea. Here's the map of 100 battle areas. Whenever a person gets attacked, i want them to go to any one of these battle areas (one that is not already inhabited). Got it?

(erf, you're going to have to right click that link and choose to save target, clicking on it won't work)

Unfortunately it's not possible to read the map without having the entire project...if you want to email me the project I can take a look at it.
In response to Deadron
On 1/31/01 11:51 pm Deadron wrote:
Unfortunately it's not possible to read the map without having the entire project...if you want to email me the project I can take a look at it.

ugh, i can't believe i did that. Just use the same link as before, i re-uploaded it...

[edit] Just so you don't think i'm an idiot for uploading it, thats a very very very very edited version of my code :) (i took out everything that wasn't needed to run the map)
In response to Cinnom
On 1/31/01 4:53 pm Cinnom wrote:
Okay, i don't think you have the idea. Here's the map of 100 battle areas. Whenever a person gets attacked, i want them to go to any one of these battle areas (one that is not already inhabited). Got it?

I see what you want to do (nice map by the way).

As with so many things in BYOND there are many ways to do it, and you just have to choose the one that works for you.

Spuzzum suggested one way. You could also define 100 different area types, and draw an area around each battle area, and keep data in the area.

Personally, my approach would probably be this:

Create a battle area object type that is invisible and not dense (so it can exist in the world but players won't see it or bump into it), then in the mapper place one of these objects in the middle of each battle area. It would be defined something like this:

obj/battle_area
visibility = 0
density = 0
var/tmp/battle_in_progress = 0

When the game starts up, you can get a list of the battle_objects that exist this way:

game_data
var/list/battle_areas

New()
var/obj/battle_area/battle
for (battle in world)
battle_areas += battle


This provides several advantages:

- you don't have a zillion extra types in your code
- it's easy to place them
- you can move people to the battle area by using get_step_rand(battle_area)

When you need a battle to happen, loop through the battle_objects to find one not in use:

var/obj/battle_area/battle
for (battle in battle_areas)
if (!battle.battle_in_progress)
// Get locations to move the players to.
var/first_loc = get_step_rand(battle)
var/second_loc
do
second_loc = get_step_rand(battle)
while(second_loc != first_loc)

// Now move the players to those locs...
// (your code here)

// Make a note that a battle is in progress.
battle.battle_in_progress = 1
return

A little extra tip for when you are placing invisible objects on the map...obviously it can be a pain to have objects on the map that you can't see while editing your map.

How I get around this is I define a .dmi file for the object that has a default image like a big X, and has an icon_state called "blank".

Now in the mapper you will see the big X wherever you've put one of the objects. But so that that doesn't show in the game, you add this code to the battle_area object:

obj/battle_area
New()
icon_state = "blank"
return ..()

And now it's invisible when the game runs.
In response to Deadron
On 2/1/01 6:08 pm Deadron wrote:
On 1/31/01 4:53 pm Cinnom wrote:
Okay, i don't think you have the idea. Here's the map of 100 battle areas. Whenever a person gets attacked, i want them to go to any one of these battle areas (one that is not already inhabited). Got it?

I see what you want to do (nice map by the way).

As with so many things in BYOND there are many ways to do it, and you just have to choose the one that works for you.

Spuzzum suggested one way. You could also define 100 different area types, and draw an area around each battle area, and keep data in the area.

Personally, my approach would probably be this:

Create a battle area object type that is invisible and not dense (so it can exist in the world but players won't see it or bump into it), then in the mapper place one of these objects in the middle of each battle area. It would be defined something like this:

obj/battle_area
visibility = 0
density = 0
var/tmp/battle_in_progress = 0

When the game starts up, you can get a list of the battle_objects that exist this way:

game_data
var/list/battle_areas

New()
var/obj/battle_area/battle
for (battle in world)
battle_areas += battle

Okay, i got around to looking at this code, and i have a question: Where do i put this code and how do i use it?
In response to Cinnom
Personally, my approach would probably be this:

Create a battle area object type that is invisible and not dense (so it can exist in the world but players won't see it or bump into it), then in the mapper place one of these objects in the middle of each battle area. It would be defined something like this:

obj/battle_area
visibility = 0
density = 0
var/tmp/battle_in_progress = 0

When the game starts up, you can get a list of the battle_objects that exist this way:

game_data
var/list/battle_areas

New()
var/obj/battle_area/battle
for (battle in world)
battle_areas += battle

Okay, i got around to looking at this code, and i have a question: Where do i put this code and how do i use it?

You would use this code to replace whatever you're currently using to implement battle areas. When you draw your map, you'd put on of these objects in the center of each battle area, then draw a wall/border/moat/whatever around each area to keep players confined.

In the game, when you want to move someone to a battle area, you'd just look through world.contents for battle area objects until you find one that isn't in use. Then teleport them somewhere near the object.

Also, a tip for drawing invisible things on the map: I usually give them an icon so I can keep track of where they are in the map editor, then redefine New() so that when the game starts, each object's icon is set to null, making it invisible. Very handy!