Home   Help Search Login Register  

Author Topic: Line Of Sight Checking Script!!!  (Read 6407 times)

0 Members and 2 Guests are viewing this topic.

Chad

  • Guest
Re:Line Of Sight Checking Script!!!
« Reply #15 on: 02 Jun 2005, 13:54:09 »
Cc i am holding off abit on the compiler side of thing because posting code it emits is asking for all the guys here to jump onto it like a pack of starving dogs.

In regards i actualy coverted the above scripts to see the performance gain or decrease in the compiler. From my observation Grendel's code actualy ran faster in the compiler than my original version that i did about a week ago. So congrats to grendel for his help there. I have mainly underlined the bottleneck with the system, its in regards how the compiler treats variables. I will do some higher language examples here and some code that is emited from the compiler that you can see how things are done.

Remember its an OOC it not a precedual language. I have thought about it long and hard, and any such tasks that i find that require a large amout of proccessing i can actualy convert into libaray files eg.. the compiler enables you to also write in higher language to built your function files, such i have tended to mostly keep the whole compiler in the script language department to test performance hit it would cause.

I am finding out con-currently the performance hit i am getting using the techniquie i do in the compiler is "lets just say, a hit in the nutts when doing jobs that require down to the micro second to execute".

Anyway onto some examples.

<!-- Last chance to turn back -->

Code: [Select]
/**
 * Author Chad Lion
 * Version: 1.00
 * Date: Thursday, June 02, 2005
 *
 * This document is for demonstration purposes.
 * Its to reflect a ongoing development of two current projects
 * One the object orientated compiler and the next is the
 * A.I. Heuristic
 */
 
/**
 * Okay lets start with the basics and move up from there
 * this is a class type, a class is a blue print to building
 * an object. What is an object, well an object is a instance
 * of a class. With a copy of all its variables and methods
 * such try not to confuse a ofp game object with higher
 * language object.
 */
public class Example{
   
   /**
    * This is the location that ofp will jump to when the file
    * is executed. But for this demostration its to show how
    * methods and variables are handeled within the compiler
    */
   public static void main(){
      /**
       * We want to declare some variables for some calculations
       * you have the following types
       * boolean   <- Boolean
       * int       <- Number
       * string    <- String
       * unitside  <- side
       * mygroup   <- group
       * object    <- game object
       * The above are all your primitive data types.
       *
       * Higher language data types
       * Class     <- Blue print for a object
       * array     <- Can be any of the primitive data types and also class data type
       */            
       int a1 = 2;
       int a2 = 3;
       int a3 = 4;
       int a4 = 5;
       
       a1 = (a1 * a2)/2*a4-a3;
       
       print( a1 );
   }
 
}

This is the emited code

Code: [Select]
MA=0
heapsearch = preprocessFile "heapsearch.sqf"
_heap=[]
_stack=[]
_reg2=0
_stack = _stack + [0]
_stack = _stack + [0]
goto "5"
#5
_stack set [ (count _stack), _reg2]
_reg2 = (count _stack)
_stack set [ (count _stack), [0,0,0,0]] [b]REFERNCE ONE[/b]
_reg1 = (_stack select _reg2)
_reg4=2.0
_reg1 set [0,_reg4] [b]REFERNCE TWO[/b]
_reg4=3.0
_reg1 set [1,_reg4] [b]REFERNCE THREE[/b]
_reg4=4.0
_reg1 set [2,_reg4] [b]REFERNCE FOUR[/b]
_reg4=5.0
_reg1 set [3,_reg4] [b]REFERNCE FIVE[/b]
_reg4= (_reg1 select 0)
_reg5= (_reg1 select 1)
_reg4=_reg4*_reg5
_reg5=2.0
_reg6=_reg4/_reg5
_reg4= (_reg1 select 3)
_reg6=_reg6*_reg4
_reg4= (_reg1 select 2)
_reg5=_reg6-_reg4
_reg1 set [0,_reg5]
_reg4= (_reg1 select 0)
hint format[ "%1",_reg4]

exit

Okay lets start from the top down what the compiler does. Because ofp has no actualy memory address range that you will have within a normal machine language for example x86. This has to be emulated some how, this emulation is done via an array, using it as a stack to allocate and de-allocate memory on the fly via the programs execution.

In reference 1 you will see that the compiler via its second pass will count all the variables within the higher language. Then will create a make frame ( Make Frame being memory space for the method to store its local variables ). This is the memory space that the variables are stored in, so each time you assign a = b. b is retreaved from the stack yes, each time. And then assigned to the array at position a.

Though this is mostly the bottleneck within the system. That because of variables not actualy being stored in an memory address range, they have to be stored within an array that holds those locations.

You will see the same keep occuring in reference to 2,3,4 in the emited code from the compiler.

But!

Not all is lost, because of the nature and how i have designed the system. It emits assembly instructions out into an interface that converts those assembly instructions into ofp game script language code. Such the result is what you see above.

Objects and other things are handeled ore or less in regards the same way, but with key differences that i wont go into in this dicussion. But, what i am thinking lately is actualy creating a faster emited code by simply declaring the whole stack within functions that would greatly speed up the proccessing time of the script lagnuage completly abstracted from the higher language.

So, even though at this point in time. I have found issues arrising within the system. Its not the end of the world. I can simply re-modifiy the emited game script language to take into account doing things differently.

But right now i have to head off to sleep, its getting late and i need the rest for a full days work tommoro.

Grendel

  • Guest
Re:Line Of Sight Checking Script!!!
« Reply #16 on: 03 Jun 2005, 02:39:58 »
@Chad,

Quote
Grendal do you have msn or icq i would like to talk to you about acouple of things. Do you use team speak?

Unfortunately I have never set up any of these yet...feel free to e-mail or pm me untill I do get one of those up and running...

Another unfortunate thing is how little I understand about compilers and higher language coding...That last post might as well be in that african 'clicking' language for as much as I understood!

I'm just a self taught/trial and error scripter with a big imagination and too much ambition for my own good I guess LOL.  

@Fragorl,

I would be quite interested in checking out your script using the bullet, since if it does what the one I'm working on will do, then I can spare everyone the redundancy.

-GrendEl  ;)

DBR_ONIX

  • Guest
Re:Line Of Sight Checking Script!!!
« Reply #17 on: 03 Jun 2005, 15:51:24 »
The easiest way I can think of is getting the height of the two units above sea height
Getting the angle from one to the other (both up/down and 0-360).
Then, using this data, use the drop command on an object with a geo lod.
if the droped thing comes withing < 0.5m of the second person, it's almost certainly got LOS with the other person :)
If the drop partical colides with something, it's killed.

If the drop partical fails, you can use the exact same idea, with a bullet, but this requires a config/pbo

I'm not too good with trig and stuff like that in OFP, so someone else could try this if the other methods are unreliable.
- Ben

Grendel

  • Guest
Re:Line Of Sight Checking Script!!!
« Reply #18 on: 03 Jun 2005, 18:34:29 »
@Ben

Quote
If the drop partical fails, you can use the exact same idea, with a bullet, but this requires a config/pbo

This is pretty much the method I am working right now, if you (or anyone) could please explain the geo lod drop particle, I would appreciate it! This sounds very promising.

The only drop particles I've worked with are the basic, fire, and fired ones.  So what do I put in the drop array to use a geo lod and do they otherwise obey the same properties of particles such as staying put?

-Grendel

DBR_ONIX

  • Guest
Re:Line Of Sight Checking Script!!!
« Reply #19 on: 03 Jun 2005, 22:24:55 »
That idea came from manticore (for a different project, though). I think it is just a spaceobject thing you drop, as these can be objects, which can have lods.
I think a good starting point for "different" drop stuff would be the script in editors depot (Or was it beta testing?) that could drop a partical with a JPG picture on it.
I'll ask manticore next time I talk to her about the droping objects with GeoLods

Just a random guess, try changing the cl_fire thing to an object classname? it works in dialouge drop with the crater classname, seems logical enough

This could make a leap in OFP AI, nomore AI seeing you though everything! ;D
- Ben

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #20 on: 04 Jun 2005, 01:48:24 »
@DBR_Onix

Then, using this data, use the drop command on an object with a geo lod.
In my experience, you can walk right through spaceObjects, even for example a 'dropped' m113? If not, I don't think that it will work. As always, I could be wrong.

if the droped thing comes withing < 0.5m of the second person, it's almost certainly got LOS with the other person :)

I disagree - for example the walls of a house are << 0.5 metres thick. Also types of concealment that could be used, e.g. cars, trucks, barrels etc fall within the error range of this function. It's one of the problems I ran into. Also, the more traces going on at once, the less accurate each individual one becomes. This is, of course, for physical ammo.

If the drop partical colides with something, it's killed.
I've never heard of a way of killing/deleting a drop particle? That's not to say there isn't a way. I've just never had any success affecting a drop particle in any way before, be it setting its position, velocity, or deleting it.

If the drop partical fails, you can use the exact same idea, with a bullet, but this requires a config/pbo
Actually, I forgot to say, I ended up using a smokeshell not a bullet, because it doesn't disappear when killed, it stays so there's no problem getting it's position once it's collided. Also it doesn't deal any damage. Also, if the trace is fast enough it doesnt put out any smoke. So, no configging is actually necessary.

But yes, if a reliable raytrace method (that's not resource-intensive) is developed, then it will open new doors for ai. Just believe me when I say I have been working on this for a (relatively) long time now.

@Grendel

I will try to get that script for you as soon as possible, however upon looking at my old version, I saw numerous ways of improving on it's clarity and effectiveness- I couldn't help but tidy it up a little bit, seeming as other people will now be using looing at it ;D

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #21 on: 04 Jun 2005, 03:06:40 »
Here is the script, within a demo mission. There are still one or two minor improvements to be made, and i need to write an explanation of how to use the trace script within another script, but the general idea is there.

Feel free to muck around with the demo mission, substitute a tank for another object, etc. Note the script can be quite accurate sometimes, and out by quite a lot others.
« Last Edit: 04 Jun 2005, 03:07:00 by Fragorl »

UNN

  • Guest
Re:Line Of Sight Checking Script!!!
« Reply #22 on: 04 Jun 2005, 09:10:37 »
I have an addon based LOS idea, that allows you to detect if one map positions is visible from another. It takes about three seconds to return a result, but that should be constant. It will work with anything that blocks the AI's line of sight in the game.

I'ts a pain being addon based, but in conjunction with your scripts it would cover all the bases. Either way it would be great if you do come up with a script based solution, I can think of a few uses off hand. Mainly a far more flexible alternative to the Laser Designator.

P.S I also did something similar with Vektorbosons Height Above Sea Level function, to get a cross section of the terrain for an approach path. If your looking at different methods it might be worth checking it out.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #23 on: 03 Sep 2005, 04:34:59 »
Just having a look at some old topics and I came across this... I never saw your post UNN, which is a shame. I'm very interested in this method of yours; can you tell me about it?

Offline Blanco

  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #24 on: 03 Sep 2005, 07:10:07 »
Have you tried Mapfact SKY AI addon? Very very good.
It's a bunch of AI scripts (no addons) and there's a LOS script included for the body discovering part.  (much better then snypir's isbodyhidden script)
In fact, it's not a 100% LOSscript but it's effective most of the time, actually I never saw it fail.
There's also a very good tutorial mission where they show you the FOV, it even works on vehicles
You really have to try it, it's awesome stuff.
 
« Last Edit: 03 Sep 2005, 07:14:31 by Blanco »
Search or search or search before you ask.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #25 on: 03 Sep 2005, 09:06:32 »
cheers blanco ;) I'll definitely have a look at that.

Still interested in yor method, UNN

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #26 on: 03 Sep 2005, 10:08:02 »
I've taken a look at that addon thing blanco. I ran the tutorial mission (The scripting is done in german, but the english instructions are very clear and concise, so i was able to find my way around easy enough).

After taking a look at the scripts, I think I'd have to conclude that there is no line of sight checking being run, lathough the AI scripting in itself is something special. The picture you posted (and the one they use on the website) is just an outline of the unit's field of view, with drop particles dropped depending on the unit's direction, and are dropped at ground level. The relevant lines from the script (for the tutorial, anyway) are:

Code: [Select]
[(_Units select 0),Sichtfeld,Sichtweite] exec "KI_Addon1.8\blick.sqs"
(_Units select 0) move getpos (_Units select 1)
@ (_Units select 0) distance (_Units select 1) < 6 or not alive (_Units select 0) or Alert

Units select 0 is the guy who finds the body, and units select 1 is the body. 'blick.sqs' is just the script that outlines the FOV in dopr particles. There is no LOS check there (you can tell by how quickly the drops go that nothing very intensive is happening ;)). Obviously there is a distance trigger, although this is a minimum cutoff point.

The tute states something like 'hills and rises will affect the unit's view', but they say 'the script relies on the knowsabout value of the unit with respedct to the body'. So i think what they do is use the game engine to judge line of sight for itself, knowing that the LOS will be taken into account in the knowsabout value.

Offline Blanco

  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #27 on: 03 Sep 2005, 17:28:13 »
Yeah, I know it's not a real LOS script, it just simulates it.
But I've used it in a few missions and it never let me down so far, even in dense areas like bases.

But I'm always open for other methods offcourse. 8)



« Last Edit: 03 Sep 2005, 17:30:25 by Blanco »
Search or search or search before you ask.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Line Of Sight Checking Script!!!
« Reply #28 on: 04 Sep 2005, 03:19:41 »
Yes, i entirely agree. In this case, not only is it not broke, it works very well indeed. Certianly doesn't need fixing :) I'm all for using the engine to its full before other methods are explored. Certainly, in my experience, the best a scripted alternative can be is almost as good.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Line Of Sight Checking Script!!!
« Reply #29 on: 04 Sep 2005, 05:50:51 »
Quote
Mainly a far more flexible alternative to the Laser Designator.
not quite
we can't tell if the persion is looking or not, only if they could see if they happen to be looking the right way