Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → I think I've got it!
I think I've got it!
2003-09-12, 4:15 AM #1
The first ever, completely fool proof sector checker.
Code:
insector = 0;
pos = GetThingPos(player);
For(i=0; !insector; i=i+1)
{
   For(j=0; j<GetNumSectorVertices(i); j=j+1)
   {
      dot = VectorDot(VectorNorm(VectorSub(GetSectorCenter(i), pos)), VectorNorm(VectorSub(GetSectorVertexPos(i, j), pos)));
      If(dot <= 0) insector = i;
   }
   If(i > GetSectorCount()) insector = -1;
}
The way it works is that it checks to see if the cosine of the angle == 0, then you're on the wall of the sector, and thereby inside. If the cosine is < 0, then you are inside the sector because at least one vertex is behind you and you can't be outside a sector for that to happen. *bows* Have fun.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!

edit - the final, and working [http://forums.massassi.net/html/biggrin.gif], version

[This message has been edited by Descent_pilot (edited September 18, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-09-12, 2:23 PM #2
Just thought I'd have a quick check of the forums before I went to bed and spotted this post [http://forums.massassi.net/html/wink.gif]

Although I'm too tired to test it now (long day [http://forums.massassi.net/html/wink.gif] ), if it works then this would be an exceptionally useful piece of code for both editors and coggers alike [http://forums.massassi.net/html/wink.gif]

I'm impressed - well done DP [http://forums.massassi.net/html/biggrin.gif]

-Jackpot

------------------
Are you feeling lucky, cuz if you are, get your hands off me... ;)

"Life is mostly froth and bubble,
But two things stand in stone,
Kindness in another's trouble,
Courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||
2003-09-14, 9:47 AM #3
So you're looking at the angle between two vectors: one going from the ghost's pos to the sector's center, and the other going from the ghost to the vertex's pos. And you're testing to make sure this angle is less than 90 degrees.

This is not going to guarantee that the position is in that sector. You could be looking at another sector far away - and the angle would much less than 90 degrees...

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-09-14, 11:07 AM #4
Yea, but if its greater then 90, then its inside the sector. But alas, it does not work. [http://forums.massassi.net/html/frown.gif]

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!

[This message has been edited by Descent_pilot (edited September 14, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-09-14, 12:35 PM #5
Ok, greater than 90 degrees... It still won't work - remember that not all sectors are rectangular.

And this line:
Code:
If(i<GetSectorCount()) insector = -1;

looks like it's not supposed to be there.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-09-17, 4:47 AM #6
That was stupid. [http://forums.massassi.net/html/redface.gif] If(i >= GetSectorCount()) [http://forums.massassi.net/html/tongue.gif] I feel really stupid now.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-09-18, 2:58 PM #7
Okay, that code that is posted is a code that is completely tested and will work. Am I really good now or what? [http://forums.massassi.net/html/tongue.gif] *uber l33t crappy dance* [http://forums.massassi.net/html/biggrin.gif]

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-09-18, 4:57 PM #8
hey am i testing this right?
Code:
##########################################################
# Jedi Knight Cog Script  (JK)
#---------------------------------------------------------
# 00_SMOKETRAIL.COG
# Leave a smoke trail behind a moving object
#---------------------------------------------------------
##########################################################
flags=0x240
symbols
#=========================================================
message     created
message     pulse

template    smoke_tpl=+smoke                         local
thing       dummy=-1                                 local

int         insector=0                               local
vector      pos                                      local
int         a=0                                      local
int         b=0                                      local
flex        dot=0.0                                  local
int         c=0                                      local
#---------------------------------------------------------
end
#=========================================================
code
#---------------------------------------------------------
created:
	//-Set 50 msec timer for smoke release
	SetThingPulse(GetSenderRef(), 0.125);
return;
#---------------------------------------------------------
pulse:
	dummy = GetSenderRef();
	//-Create smoke at our current location
	CreateThing(smoke_tpl, dummy);
	insector = 0;
	pos = GetThingPos(dummy);
	for(a=0; !insector; a=a+1)
		{
		for(b=0; b<GetNumSectorVerticies(a); b=b+1)
			{
			dot = VectorDot(VectorNorm(VectorSub(GetSectorCenter(a), pos)), VectorNorm(VectorSub(GetSectorVertexPos(a, b), pos)));
			if(dot <= 0)
				{
				insector = a;
				PrintInt(insector);
				c = GetThingSector(dummy);
				PrintInt(c);
				}
			}
		if(a > GetSectorCount())
			insector = -1;
		}

return;
#=========================================================
end

i worked it into the railsmoke cog.
when i fire it across CO it doesnt always print the same number.
how are you testing it?

------------------
Famous last words - "It seemed like a good idea at the time."

[This message has been edited by DSLS_DeathSythe (edited September 18, 2003).]
Famous last words - "It seemed like a good idea at the time."
2003-09-19, 4:21 AM #9
Display Stats in a batch file. Looking at the sector number in the stats, and run through a pulse in kyle.cog.

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack

↑ Up to the top!