Can map size be calculated by a script?

Discussions about Coding and Scripting
Post Reply
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Can map size be calculated by a script?

Post by MrLoathsome »

Got a question.

Is there an efficient way to calculate the size of the widest point on a map in Uscript?
Perhaps this value is already available and I just don't know where to look for it. :noidea

Figured out a way to get the distance between the flagbases on most CTF maps like this:

Code: Select all

	if (TeamCnt != 0) SpBaseDist = VSize(TeamBases[0] - TeamBases[1]) * 0.5;
That bit calculates the distance then divides it by 2 for use in keeping spawns on the correct side.

Some CTF maps, are not mirror images of each other, and the above method has a few issues depending
upon the map layout.

If I was able to get the VSize value for the widest point on the map, it might help with that, and would also
be useful for optimizing some other bits of this project.

Only thing I can think of is a giant radius search on all actors in the map, then somehow filtering out the 2 locations that are
the farthest apart, but the thought of that code makes me feel like this: :omfg: :nonono: :barf:

There has to be a better way.....
blarg
User avatar
Feralidragon
Godlike
Posts: 5493
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Can map size be calculated by a script?

Post by Feralidragon »

I did something like that for my mod: since it supports replacement filters by map size (so nukes don't spawn in small maps for example), I managed to calculate it like this:

Code: Select all

local Actor A;
local vector v1, v2;
local float XMax, XMin, YMax, YMin;

	ForEach AllActors(Class'Actor', A)
	{
		if (PlayerStart(A) != None || Inventory(A) != None)
		{
			//Get max size (step 1/2)
			XMax = FMax(XMax, A.Location.X);
			XMin = FMin(XMin, A.Location.X);
			YMax = FMax(YMax, A.Location.Y);
			YMin = FMin(YMin, A.Location.Y);
		}
	}

	//Get max size (step 2/2)
	v1.X = XMax;
	v1.Y = YMax;
	v2.X = XMin;
	v2.Y = YMin;
	maxMapSize = VSize(v1 - v2);
maxMapSize is a global var, so I only run this code only once as the map won't change its size over time lol
And I only consider playerstarts and inventory points, since those are the ones supposed to be reachable by the player.

The final v1 and v2 vectors do not give exact reachable points of the map, but mostly the farthest place the "bounding box" vertexes go, like:

Code: Select all

v2--------- .
|    Map    |
._________ v1
But you can use those to make your checks.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Can map size be calculated by a script?

Post by MrLoathsome »

Well then, it seems that idea is the best way to accomplish this.

Your bit of code there is almost exactly the way I had it pictured in my head last night.
That makes me feel less dumb for not finding another way. :loool:

I should of known you would be the one to answer this. :gj:
Thanks again for the code snippet. It will probably get dropped into
my PostBeginPlay function as it is.

**Edit - dropped it in there and tested it out a bit.

Works perfect. Clean compile on 1st try.
(Why am I not surprised?)
blarg
User avatar
Wises
Godlike
Posts: 1089
Joined: Sun Sep 07, 2008 10:59 am
Personal rank: ...

Re: Can map size be calculated by a script?

Post by Wises »

ahaha because its grandmaster Ferali's code bro..

I assume that this is fot the random spawn mod upgrade?

btw.. had an odd occurance other day.. not sure what caused it.. but a had the tele.. and i think i died.. and respawned with it or something.. anyway i was just looking at the screen and it began teleportinging me all ober the map.. weird. was kinda cool though.. but weird.

now theres an idea for a weapons mod.. the 'get me outta here teleporter' lol.. press the button and instantly teleported to another location.. only works once per life cycle lmao.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Can map size be calculated by a script?

Post by MrLoathsome »

Wises wrote:ahaha because its grandmaster Ferali's code bro..

I assume that this is fot the random spawn mod upgrade?

btw.. had an odd occurance other day.. not sure what caused it.. but a had the tele.. and i think i died.. and respawned with it or something.. anyway i was just looking at the screen and it began teleportinging me all ober the map.. weird. was kinda cool though.. but weird.

now theres an idea for a weapons mod.. the 'get me outta here teleporter' lol.. press the button and instantly teleported to another location.. only works once per life cycle lmao.
Yes indeed, this is for the Random Spawn Locations thingy.

Question, this weird teleporting bug. Were you using RSL_RC4 when that happened? (Which is obsolete already, or will be in a few days when I post RC5)

I haven't seen that happen in testing yet, but your description of it interested me as that is exactly the sort of endcam effect I have been planing
to use in cases when the MonsterTeam wins for the next update to my UTSPFix gametypes mod.
(In the current beta of that, players endcam view just sorta drops out of the map and fades to black as you see the map disappear in the distance above....)
blarg
Post Reply