Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (TipmyPip, 1 invisible), 18,758 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Dynamically create special entities? [Re: MrCode] #178992
02/03/08 16:58
02/03/08 16:58
Joined: Jan 2008
Posts: 49
Sweden
K
Kenchu Offline
Newbie
Kenchu  Offline
Newbie
K

Joined: Jan 2008
Posts: 49
Sweden
Quote:

Alright. I believe the time has come to start assigning behavior to these "magnets". I was thinking of using a spherical c_scan to detect nearby entities, and if it detects one or more, it will attract to it (or repel it), and the same goes for the others (because they also have their own c_scan).

I know the attraction/repulsion thing is going to involve a bit of trigonometry, and I've got that part worked out (mostly), but how can I use c_scan to detect whether the magnet is POSITIVE or NEGATIVE, if I can at all?

Are the me and you pointers universal, or can they only be used with entities?




Im not sure if you can use c_scan for that. It wouldve worked, as you say, if you somehow could access the pole member, but I dont see how to do that in a fancy way. One solution could be to store the entity pointer of MAGNET (ENTITY* entity) in an array, and the actual MAGENT pointer in another one, and keep these two coherent.



Then you could in the event handler find the ENTITY in the first array, and use that index to get the pole from the second array.

kinda like:

for each entity in array
check if current entity == me
if so, then the use this index
else continue until

then you could use array2[index] to get an MAGENT*, and just do array2[index].pole.

Though I dont think this is a good solution. It takes time to search the array for each entity all the time.

Another solution could be to implement your own distance measuering function for MAGNETs instead. Then youd have to have an array with your magnets, and then go through it and calculate the distance to the others and take action from that. I think theres more work for that though.

These are the two solutions I can come to think of right now...

Re: Dynamically create special entities? [Re: Kenchu] #178993
02/03/08 19:21
02/03/08 19:21
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
Ok, then how about a modified vec_dist? I was thinking i could write some kind of equivalent to c_scan using vec_dist, and then checking to see if the MAGNET*(s) within the vec_dist region are POSITIVE or NEGATIVE.

I don't know, this may end up being a bigger bite than I can chew, and I may just have to ditch the whole plan. (I hope I don't have to, though.)

I could swear there's a method in gravball (that little 2D orbit simulator) that keeps track of all the PANEL*s that are around each other. There must be some way I can do this with my MAGNET*s...

Last edited by MrCode; 02/03/08 19:25.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Re: Dynamically create special entities? [Re: MrCode] #178994
02/04/08 19:02
02/04/08 19:02
Joined: Jan 2008
Posts: 49
Sweden
K
Kenchu Offline
Newbie
Kenchu  Offline
Newbie
K

Joined: Jan 2008
Posts: 49
Sweden
I dont see why you would have to modify vec_dist. But yeah, making a modified c_scan using vec_dist is a way to go.

Re: Dynamically create special entities? [Re: Kenchu] #178995
02/26/08 05:44
02/26/08 05:44
Joined: Mar 2007
Posts: 677
0x00000USA
M
MrCode Offline OP
User
MrCode  Offline OP
User
M

Joined: Mar 2007
Posts: 677
0x00000USA
(Sorry this thread got so old, I was busy doing other things...)

So, I've been thinking (just recently) about how to implement this "mag_scan()" function, and I'm kind of at a loss. I don't know what my "you" pointer would be (the entity that the code would work with, along with the one that the function is being executed from, "me"). Do I just create a dummy pointer and set it to the address of (&) the last MAGNET* created? That would kinda screw things up, because then I would have to make the "tmp" MAGNET* that my mag_create() function allocates into memory a global struct. Would this affect the way mag_create() works?

Or perhaps I could create "mee" and "yoo" pointers of type void

EDIT: Ok, I've come up with a solution akin to Kenchu's Idea of using arrays. I figure that since in my mag_create() function, I'm allocating a memory block to each new MAGNET* entity that is created, I would compare the distance values of the entities (tmp->entity->x/y/z via vec_dist()), and compare the "pole" members of the MAGNET* struct. The thing is, how do I access these parts of a struct array, if it's an array at all? (I figure it is, because the malloc() macro is just like new in C++, which can create dynamic arrays.)

Some pseudo-code to show what I'm attempting to do here:

Code:

void mag_scan(MAGNET* srcent,float dist)
{
int pole;
while(srcent)
{
for(int i= 0; i < tmp[i]; i++)
{
if(vec_dist(vector(insert pointer to tmp's entity coords here),vector(tmp->entity->x/y/z) <= 40)
{
switch(pole)
{
case POSITIVE:
//behavior (trig,other math nonsense)
case NEGATIVE:
//ditto
}
}
}
wait(1);
}
}



I've made the "tmp" pointer global, so this pseudo-code would work, if it were real, and if I knew how to access the array index of my MAGNET*s.

Last edited by MrCode; 02/26/08 23:57.

Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}
Page 2 of 2 1 2

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

Gamestudio download | 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