Server Help

ASSS Questions - Changing LinkedList to a Target

Animate Dreams - 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:
Code: Show/Hide
    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.
Samapico - 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.
Animate Dreams - Mon Apr 09, 2007 12:14 pm
Post subject:
Lol, yes, I was being facetious. :D
D1st0rt - Mon Apr 09, 2007 1:11 pm
Post subject:
Code: Show/Hide
Player *p;
Link *link;
Target t;
t.type = T_PLAYER;

pd->Lock();
FOR_EACH_PLAYER(p)
{
    t.u.p = p;
    game->WarpTo(&t,512,512);
}
pd->Unlock();


is how I do it
Animate Dreams - 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.
Dr Brain - 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.
Smong - Mon Apr 09, 2007 8:10 pm
Post subject:
If you look in defs.h you can see Target is much more flexible.
Code: Show/Hide
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:
Code: Show/Hide
   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();

Animate Dreams - 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:

Code: Show/Hide
    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.
Smong - 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.
Animate Dreams - 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).
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group