ID:149321
 
How can you set up a way for multiple players to run into random battles and fight in there own seperate battle field regaurdless how many are using the same field map.
Exp.
Your playing and walking around and boom a battle starts. Your moved the the battle field to fight an enemy. Ok now how to keep each persons battles seperate from others .
Dekuh wrote:
How can you set up a way for multiple players to run into random battles and fight in there own seperate battle field regaurdless how many are using the same field map.
Exp.
Your playing and walking around and boom a battle starts. Your moved the the battle field to fight an enemy. Ok now how to keep each persons battles seperate from others .

Nova's idea is a good start: Basically the idea is to have a battle map divided into "rooms", with utterly impassible, opaque black turfs surrounding each one; you'd need to keep track of who's in which room, and move new battles to empty ones.

Now, the trick comes in figuring out when you've run out of space. It may happen that you'll get enough players in a game that you'll need a second battle map. If this happens, you'll need to create a new z-level and build new battle rooms there. In fact it might be sensible to build the original map at runtime anyway.

Let's start simple: Creating the map level.
var/list/battlemaps  // this is a list of z-levels
var/list/battlemap_roomsinuse
var/battlemap_width
var/battlemap_height
var/const/battlemap_room_width=9
var/const/battlemap_room_height=9

proc/AllocateBattleMapRoom(turf/where)
if(!battlemaps)
battlemap_width=round((world.maxx+1)/(battlemap_room_width+1))
battlemap_height=round((world.maxy+1)/(battlemap_room_height+1))
var/roomx
var/roomy
var/roomz
if(!battlemap_roomsinuse)
battlemap_roomsinuse=list()
var/zindex
for(zindex=1,zindex<=battlemaps.len,++zindex)
roomz=battlemaps[zindex]
for(roomy=1,roomy<=battlemap_height,++roomy)
for(roomx=1,roomx<=battlemap_width,++roomx)
if(!("[roomx],[roomy],[roomz]" in battlemap_roomsinuse)) break // this room is free
if(!zindex)
CreateBattleMap(++world.maxz)
roomz=world.maxz
roomx=1
roomy=1
// use turf/where's type to fill in scenery
var/cornerx=(roomx-1)*battlemap_room_width+1
var/cornery=(roomy-1)*battlemap_room_height+1
for(var/turf/T in block(\
locate(cornerx,cornery,roomz),
locate(roomx*battlemap_room_width,roomy*battlemap_room_height,roomz)))
new where.type(T)
if(hascall(where,"Decorate")) // to decorate a battle map
// this is one of the few really valid uses of :
where:Decorate(locate(cornerx,cornery,roomz))
// return SW corner of room
var/turf/swcorner=locate(cornerx,cornery,roomz)
battlemap_roomsinuse["[roomx],[roomy],[roomz]"]=swcorner
return swcorner

proc/LeaveBattleMapRoom(turf/T) // T is a turf in the room
var/roomx=round(T.x/(battlemap_room_width+1))+1
var/roomy=round(T.y/(battlemap_room_height+1))+1
battlemap_roomsinuse-="[roomx],[roomy],[T.z]"
// save memory by deleting maps when demand is low
if(T.z==world.maxz && \
battlemap_roomsinuse.len<=battlemap_width*battlemap_height*(battlemaps.len-3/2))
--world.maxz
battlemaps.Cut(battlemaps.len) // delete the last map

proc/CreateBattleMap(zlevel)
var/i
var/j
var/k
var/turf/T
// draw horizontal walls
for(i=1,i<=battlemap_height,++i)
j=i*battlemap_room_height
k=battlemap_room_width*battlemap_width
for(T in block(locate(1,j,zlevel),locate(k,j,zlevel)))
new /turf/battlemap_wall(T)
// draw vertical walls
for(i=1,i<=battlemap_width,++i)
j=i*battlemap_room_width
k=battlemap_room_height*battlemap_height-1
for(T in block(locate(j,1,zlevel),locate(j,k,zlevel)))
new /turf/battlemap_wall(T)

turf/battlemap_wall
opacity=1
icon='black.dmi' // make this icon a solid black square

Enter() return 0 // none shall pass

This system looks a bit complex, but basically what it's doing is creating battle maps for you on the fly, then finding free ones for you to use.

Whenever you start a battle, call AllocateBattleMapRoom() and it will return an unused room for you, and mark it as used. (If the turf type where the battle was initiated has a Decorate() proc, that's used to spruce up the room. You'll have to write this one yourself.) You can move your combatants there to do battle. Then when the battle is over (one way or the other), after you've moved the survivors (if any) back to their starting location, call LeaveBattleMapRoom() with one of the turfs in that room to free it up for someone else. The CreateBattleMap() proc is used internally to make new maps. You never have to make a single .dmp file for your battle rooms because they'll be made for you by this proc.

Lummox JR
In response to Lummox JR
Your way is all good and fine, Lummox, but there is another way that is much simpler in that you never really run out of room. What you do is that you have only one battle room. When something enters the battle room, it's icon and icon state are set to null and a new image() is created that follows the object around the battle room. All needed objects are created in this way, so that the player only sees the objects that he or she needs to. Then, you work out an /area system that acts like density except that it only applies to objects that can see each other. I had a nice library for this on my old computer. If only BYOND had a print butten for its code files I could just port the code over and release it!

-Lord of Water
In response to Lord of Water
Lord of Water wrote:
Your way is all good and fine, Lummox, but there is another way that is much simpler in that you never really run out of room. What you do is that you have only one battle room. When something enters the battle room, it's icon and icon state are set to null and a new image() is created that follows the object around the battle room. All needed objects are created in this way, so that the player only sees the objects that he or she needs to. Then, you work out an /area system that acts like density except that it only applies to objects that can see each other. I had a nice library for this on my old computer. If only BYOND had a print butten for its code files I could just port the code over and release it!

-Lord of Water

That's not a bad idea. I like that. Of course there is one caveat: You can't decorate the map differently for different areas. For that you still need another room.

I still like my solution, on coolness points. :)

Lummox JR
In response to Lummox JR
Just to further extenuate my circumstances (dun dun dun,) I'll argue that you CAN decorate it! In fact, I had a decoratoin system for one of my projects that is now in the scrap bin (but its legacy lives on, thank goodness.) The area that you are transported into is completely black, and can be set to anything from 5x5 to 20x20 in size. First, the battle terrain scenery is generated. Then, obstacles and straticig points are placed. After that, other fritzies and mobs and objects are placed on the map. In all, it is totally decorated and randomly generated. The system eventually even catored to my party formation system, picking a probably party formation for your foes and placing your own party in the proper positions, moving the position accordingly when there is an obstical in the path and auto-deploying to a strategic position if one is very neaby. When and if I make this open-ended and object-oriented (both of which concepts had no importance in my eyes at the time I made the engine,) I'll likely release it as a library!

-Lord of Water
In response to Lummox JR
i see both your ideas and both seem good but lummox sees do able but long yours seems alot more complex but its seems be theory. Ok lummox if i go your path there is like 9 maps so far i have and more coming your multiple thing seems unexceptable at that point. The map generation coding is appreciated.

Lord Water Your Idea factual or not is flaud in some ways. Ok you said one battle field but the players are invisable to the others and there surroundings. Does this also aply to the mob detection of the attacks. Second all chars in battle would be located in the same area only able to see thier battle map and enemy ok that sounds great. Here comes the problem though say this works(You seem to be far more experience than i but your proposal leves me sceptacle at its posability)ok how is it done. I have seen only words. I mean if I was on the level to create code for what you are speaking of it would be no problem please place an example.
In response to Dekuh
Well, Lummox JR posted a whole lot of code, but that's because I'm many times lazier then he is (see: I created TextMUD, and he created Incursion in half the time.) I told you the theory, now it's your job to code it into reality. :-P

-Lord of Water
In response to Lummox JR
[snip]
Let's start simple: Creating the map level. [snip]
This system looks a bit complex, [snip]

Heh. No comment. =)