Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Changing LinkedList to a Target

 
Post new topic   Reply to topic Printable version
 View previous topic  Recommended Database? Post :: Post Game Timers  View next topic  
Author Message
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:37
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon Apr 09, 2007 12:05 pm    Post subject: Changing LinkedList to a Target Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Mon Apr 09, 2007 12:13 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:37
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon Apr 09, 2007 12:14 pm    Post subject: Reply to topic Reply with quote

Lol, yes, I was being facetious. :D
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Mon Apr 09, 2007 1:11 pm    Post subject: Reply to topic Reply with quote

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
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:37
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon Apr 09, 2007 1:15 pm    Post subject: Reply to topic Reply with quote

Looks nice, but what's the u in t.u.p? I guess I just don't know enough about targets.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Apr 09, 2007 5:44 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Mon Apr 09, 2007 8:10 pm    Post subject: Reply to topic Reply with quote

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();

_________________
ss news
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:37
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Mon Apr 09, 2007 8:49 pm    Post subject: Reply to topic Reply with quote

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.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Mon Apr 09, 2007 9:12 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Animate Dreams
Gotta buy them all!
(Consumer whore)


Age:37
Gender:Gender:Male
Joined: May 01 2004
Posts: 821
Location: Middle Tennessee
Offline

PostPosted: Tue Apr 10, 2007 11:25 am    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email Visit posters website AIM Address MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 138 page(s) served in previous 5 minutes.

phpBB Created this page in 0.520959 seconds : 35 queries executed (82.3%): GZIP compression disabled