Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AemStones, AndrewAMD, gamers, Kingware), 1,590 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Enemy Cover #352425
01/03/11 16:27
01/03/11 16:27
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

Joined: Dec 2010
Posts: 87
Hello,
I want my enemies to be able to find covers. As a starter in 3dgs i did this.
I put dummy entities in cover positions in my level and set there enable scan on and made the enemy to scan for the covers using scan_entity.
for the trial the enemy successfully scanned the dummy entity on the cover position and i confirmed it by displaying result variable from scan_entity on screen. but when i try to point the enmy to you pointer returned by scan_entity the engine gives the empty pointer error. Also if i try to make the enemy turn to found object it doesn't turn. here is my code.

Code:
var detected;
font swc_font = <font.pcx>, , 24, 23; // sword combat font
panel found_entity // displays the result of scan_entity
{
	pos_x = 0;
	pos_y = 0;
	digits = 120, 575, 4, swc_font, 1, detected;
	flags = refresh, visible;
}

action dummy //set the enable_scan on for dummy objects at cover.
{
	my.enable_scan=on;
}


action enemy_fight // attached to the enemy
{
	enemy = me; // I'm the enemy
	while(player == null){wait(1);}
	while (1) 
	{
        if (vec_dist (my.x, player.x) < 800) // the player approaches the enemy
		{
                        temp.pan=360;
			temp.tilt=360;
			temp.z=1000;
			scan_entity(my.x,temp);
			detected=result; //show the result on screen
                        //you.skill1=50; //if uncommented gives empty pointer error.

                        //doesn't work
			vec_set(temp, you.x); 
			vec_sub(temp, my.x);
			vec_to_angle(my.pan, temp);

                  }
          wait (1);
	}
}



though it shows the result by scan_entity (i displayed on the screen using digits) that means that it successfully scans the entity but why it gives empty pointer error and why it doesn't turn to cover i don't know?

A few questions as a new starter.
Is my aproach for the cover is good or is there any better way?
which one is better suited for this task scan_entity, trace or c_scan? Does it slows down the game or is there any alternative?

Thank You!

Re: Enemy Cover [Re: romin2011] #352440
01/03/11 17:54
01/03/11 17:54
Joined: Sep 2003
Posts: 648
Switzerland
snake67 Offline
User
snake67  Offline
User

Joined: Sep 2003
Posts: 648
Switzerland
In my ai system i used an other approach. After the level is loaded all cover point entities are detected and stored in an array. At runtime if taking cover is required, they are checked (player non visible and shortest distance to actor). Then pathfinding leads the actor to the cover point.

I would suggest to code this as a finite state machine, so you are able to react very differentiated. The gameplay looks much more realistic then.

Re: Enemy Cover [Re: snake67] #352443
01/03/11 18:00
01/03/11 18:00
Joined: Nov 2008
Posts: 946
T
the_clown Offline
User
the_clown  Offline
User
T

Joined: Nov 2008
Posts: 946
Well, the c_scan function DOES set the "you" pointer to the closest entity found; However, the reason for the crash is propably that the scan did not find anything, so the "you" pointer remains empty.
You need to check if "you" is empty before you use it:

if(you != NULL)
... // go on here

BUT, snake's solution is much simpler and better either way, so I don't see why you should use c_scan. Do it like snake proposed, that's pretty certainly working.

Re: Enemy Cover [Re: the_clown] #352445
01/03/11 18:05
01/03/11 18:05
Joined: Sep 2003
Posts: 648
Switzerland
snake67 Offline
User
snake67  Offline
User

Joined: Sep 2003
Posts: 648
Switzerland
Yes, i was wrong... Maybe this helps:

// store the cover point entities:

void ai_init_cover_points()
{
ENTITY* ent;

for(ent=ent_next(NULL), n_cover_points=0; ent!=NULL, n_cover_points<100; ent=ent_next(ent))
{
str_for_entfile(ai_filename, ent);
if(str_cmpni("coverpoint", ai_filename))
{
cover_point[n_cover_points]=ent;
n_cover_points++;
}
}
}

// get a cover point

ENTITY* ai_get_cover_point(ENTITY* actor)
{
ENTITY* cp;
var ad;
var i;

ad=10000;
cp=NULL;
for(i=0; i<n_cover_points; i++)
{
cover_point[i].skill1=vec_dist(cover_point[i].x, player.x);
cover_point[i].skill2=vec_dist(cover_point[i].x, actor.x);
if(cover_point[i].skill1>cover_point[i].skill2)
{
you=NULL;
c_trace(cover_point[i].x, player.x, IGNORE_PASSABLE|IGNORE_PASSENTS);
if(you!=player)
{
if(cover_point[i].skill2<ad)
{
cp=cover_point[i];
ad=cover_point[i].skill2;
}
}
}
}
return(cp);
}



Re: Enemy Cover [Re: snake67] #352557
01/04/11 13:10
01/04/11 13:10
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

Joined: Dec 2010
Posts: 87
Snake thank you very much for your time. Your idea seems very interesting let me understand and try your code then i will be back with the results.

Re: Enemy Cover [Re: romin2011] #352569
01/04/11 14:10
01/04/11 14:10
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

Joined: Dec 2010
Posts: 87
Snake thanks for the cooperation your idea is great i will difinately try this idea in my next advanced projects. but for this i will go for the entity_scan bytheway i have uploaded my test level with my code which gives error please check it and diagnose the problem. I will be very thanks full.

[Note] all the codes are template based or copy paste from the aum projects because i wanted to quickly find a solution later i will improve code.

Cover.zip [345 kb]

everybody is welcome to check my code and provide solution thank you.

Last edited by romin2011; 01/04/11 14:12.
Re: Enemy Cover [Re: romin2011] #352600
01/04/11 17:25
01/04/11 17:25
Joined: Sep 2003
Posts: 648
Switzerland
snake67 Offline
User
snake67  Offline
User

Joined: Sep 2003
Posts: 648
Switzerland
Ok. Will download and have a look...

Re: Enemy Cover [Re: snake67] #352623
01/04/11 21:28
01/04/11 21:28
Joined: Dec 2010
Posts: 87
R
romin2011 Offline OP
Junior Member
romin2011  Offline OP
Junior Member
R

Joined: Dec 2010
Posts: 87
Thanks once again i wil be waiting.


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1