 |
Server Help Community forums for Subgame, ASSS, and bots
|
Author |
Message |
Animate Dreams Gotta buy them all! (Consumer whore)

Age:37 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Mon Apr 09, 2007 12:05 pm Post subject: Changing LinkedList to a Target |
 |
|
|
|
At one point in my module, I want to warp an entire freq to one place and another freq to another place. There are only two freqs. I built two LinkedLists for each freq. That part was easy, and goes like this:
pd->Lock();
FOR_EACH_PLAYER_P(temp, zData, playerKey)
{
if (temp->p_freq == 0)
LLAdd(&humanList, temp);
if (temp->p_freq == 1)
LLAdd(&zombieList, temp);
}
pd->Unlock(); |
The next part, I just use WarpTo to send the players where I want them. The only part I'm missing is to change the lists to Targets. I found a TargetToSet function, but no SetToTarget function, or anything along that line. I'm guessing there probably is already an existing way to do this, can anyone tell me what it is?
Also, bonus if you can figure out what this module is for. |
|
Back to top |
|
 |
Samapico No, these DO NOT look like penises, ok?

Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Mon Apr 09, 2007 12:13 pm Post subject: |
 |
|
|
|
It,s probably for something really weird... like... I dunno... anything... except a zombie game, it just can't be anything involving humans and zombies, it wouldn't make any sense. So it's probably something else. _________________ (Insert a bunch of dead links here) |
|
Back to top |
|
 |
Animate Dreams Gotta buy them all! (Consumer whore)

Age:37 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Mon Apr 09, 2007 12:14 pm Post subject: |
 |
|
|
|
Lol, yes, I was being facetious. :D |
|
Back to top |
|
 |
D1st0rt Miss Directed Wannabe

Age:37 Gender: Joined: Aug 31 2003 Posts: 2247 Location: Blacksburg, VA Offline
|
|
Back to top |
|
 |
Animate Dreams Gotta buy them all! (Consumer whore)

Age:37 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Mon Apr 09, 2007 1:15 pm Post subject: |
 |
|
|
|
Looks nice, but what's the u in t.u.p? I guess I just don't know enough about targets. |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Mon Apr 09, 2007 5:44 pm Post subject: |
 |
|
|
|
U is union, a kind of ugly C hack to save memory, but it does come in handy in cases like these. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Mon Apr 09, 2007 8:10 pm Post subject: |
 |
|
|
|
If you look in defs.h you can see Target is much more flexible.
Target tgt;
tgt.type = T_FREQ;
tgt.u.freq.arena = arena;
tgt.u.freq = 0;
game->WarpTo(&tgt, x, y);
tgt.u.freq = 1;
game->WarpTo(&tgt, x, y); |
Also if you still want to use a LinkedList (can be useful in some cases) Target accepts that too:
Target human_tgt, zombie_tgt;
human_tgt.type = T_LIST;
zombie_tgt.type = T_LIST;
// bad/lazy way
memcpy(&human_tgt.u.list, &humanList, sizeof(LinkedList));
memcpy(&zombie_tgt.u.list, &zombieList, sizeof(LinkedList));
...
// better way
LLInit(&human_tgt.u.list);
LLInit(&zombie_tgt.u.list);
pd->Lock();
FOR_EACH_PLAYER_P(temp, zData, playerKey)
{
if (temp->p_freq == 0)
LLAdd(&human_tgt.u.list, temp);
if (temp->p_freq == 1)
LLAdd(&zombie_tgt.u.list, temp);
}
pd->Unlock(); |
_________________ ss news  |
|
Back to top |
|
 |
Animate Dreams Gotta buy them all! (Consumer whore)

Age:37 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Mon Apr 09, 2007 8:49 pm Post subject: |
 |
|
|
|
I decided to do it D1's way because, even though I thought using LinkedLists would be neat, it probably wouldn't be as efficient and wouldn't be as easy to read, either. I still need go back and add comments, but here's how I have it now:
Player *tempPlayer;
Link *link;
Target t;
t.type = T_PLAYER;
pd->Lock();
FOR_EACH_PLAYER_P(tempPlayer, zData, playerKey)
{
zData->died = FALSE;
if (tempPlayer->p_freq == 0)
{
t.u.p = tempPlayer;
game->WarpTo (&t, eData->humanSpawnX, eData->humanSpawnY);
}
else if (tempPlayer->p_freq == 1)
{
t.u.p = tempPlayer;
game->WarpTo (&t, eData->zombieSpawnX, eData->zombieSpawnY);
}
}
pd->Unlock(); |
If there's something I'm still doing wrong, or could do better, just tell me. |
|
Back to top |
|
 |
Smong Server Help Squatter

Joined: 1043048991 Posts: 0x91E Offline
|
Posted: Mon Apr 09, 2007 9:12 pm Post subject: |
 |
|
|
|
I noticed you are setting zData->died = FALSE; I don't what it's for, but if you are using this to see if people are still in the game or not you might want to consider renaming/inverting the variable.
It is better to have a "isingame = TRUE" variable because entering players automatically get their player data zeroed out, which would prevent them from participating in any currently running game.
Additionally you might want to check the freq and ship, so any speccers can't join the game half way through. |
|
Back to top |
|
 |
Animate Dreams Gotta buy them all! (Consumer whore)

Age:37 Gender: Joined: May 01 2004 Posts: 821 Location: Middle Tennessee Offline
|
Posted: Tue Apr 10, 2007 11:25 am Post subject: |
 |
|
|
|
People entering arena aren't meant to participate in the currently running game, so I don't bother handling their playerdata at all. This is a zombie module. Also, the arena is going to be locked. At least, that's what I have in the hosting instructions(comment at top of module that I didn't bother to copy/paste in). Also, if the player isn't in game, I don't care about their playerdata, either. Although, in TW, people frequently get added after the zombie game has already started, so I suppose it would be best to handle something like that after all. Since they'll probably be ?setshipped to either human or zombie, maybe I'll just handle that in a shipchange callback, and depending on which ship they switch to, set their freq and playerdata accordingly(for example, a player coming in as a zombie should have died set to true). |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
Software by php BB © php BB Group Server Load: 62 page(s) served in previous 5 minutes.
|