Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
ent_next problem #389962
12/20/11 14:58
12/20/11 14:58
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
I have another little question.
I notice that "ent_next" uses all entities.
Which means, that in the example below, every entity with "entity_typ = 3" becomes invisible.
But I want that only the nearest entity with "entity_typ = 3" becomes invisible.
Also the entity should become visible again, if it is not the nearest entity with "entity_typ = 3" anymore.


example:
Quote:
for (you = ent_next(NULL); you != NULL; you = ent_next(you))
{
if ((you != my) && (you.entity_typ == 3))
{
set(you,INVISIBLE);
}
else
{
reset(my,INVISIBLE);
}
}



Does anyone know how to do that?



Re: ent_next problem [Re: Random] #389963
12/20/11 14:58
12/20/11 14:58
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
So this is my biggest problem, right now.
Really...



Re: ent_next problem [Re: Random] #389969
12/20/11 16:35
12/20/11 16:35
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline
Member
krial057  Offline
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Here is a nice snipped. You can simply modify the condition:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=389503#Post389503

change
if(vec_dist(you.x, e_center.x)<lv_dist && you!= e_center)
into
if(vec_dist(you.x, e_center.x)<lv_dist && you!= e_center&&you.entity_typ == 3)

Re: ent_next problem [Re: krial057] #389970
12/20/11 17:34
12/20/11 17:34
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I assume you are talking about the entity nearest to ME, so here goes.
Code:
ENTITY* nearest=NULL;   //GLOBAL entity pointer, or just OUTSIDE do-while loop

...
if(nearest!=NULL)   {   reset(nearest, INVISIBLE);   }
for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
{
    if ((you != my) && (you.entity_typ == 3))
    {	
        if(nearest==NULL)
        {   nearest = you;   set(you,INVISIBLE);   }
        else
        {
            if(vec_dist(you.x,me.x)<vec_dist(nearest.x,me.x))	
            {   nearest = you;   set(you,INVISIBLE);   }
        }
    }
}
...


I think that should do the trick...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: ent_next problem [Re: EvilSOB] #390023
12/21/11 15:26
12/21/11 15:26
Joined: Feb 2010
Posts: 886
Random Offline OP
User
Random  Offline OP
User

Joined: Feb 2010
Posts: 886
Works perfectly!
Yes, that does more then the trick ^^



Re: ent_next problem [Re: Random] #390025
12/21/11 15:43
12/21/11 15:43
Joined: Jul 2008
Posts: 894
T
TechMuc Offline
User
TechMuc  Offline
User
T

Joined: Jul 2008
Posts: 894
please do not recalculate the distance of the nearest pointer on an on, but store the distance in a temporary variable and compare the distance of the next entity against it.

e.g. if(nearest == null) {
nearest = you;
nearest_temp = vec_dist(you.x,me.x);
}
else if(vec_dist(you.x,me.x) < nearest_temp) {
nearest_temp = vec_dist(you.x,me.x);
//..

never forget the performance laugh

Re: ent_next problem [Re: TechMuc] #390075
12/22/11 08:17
12/22/11 08:17
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I do agree with TechMuc.
My code is not very efficient, but it WAS only written to explain a point...

A MORE efficient method, in line with TechMuc is as follows...

Code:
ENTITY* nearest=NULL;   //GLOBAL entity pointer, or just OUTSIDE do-while loop

...
var nearest_dist;
if(nearest!=NULL)   {   reset(nearest, INVISIBLE);   }
for(you=ent_next(NULL); you!=NULL; you=ent_next(you))
{
    if ((you != my) && (you.entity_typ == 3))
    {	
        if(nearest==NULL)
        {   nearest = you;   set(you,INVISIBLE);
            nearest_dist = vec_dist(you.x, me.x);   }
        else
        {
            if(vec_dist(you.x, me.x) < nearest_dist)	
            {   nearest = you;   set(you,INVISIBLE);
                nearest_dist = vec_dist(you.x, me.x);   }
        }
    }
}
...



By the way ... where did you get the idea for the
"for(you=ent_next(NULL); you!=NULL; you=ent_next(you))" from?
Excellent way of handling ??_next searching...
Much more efficient than my usual way with "while(1)"'s.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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