Ah, more asteroids.

Posted by Nick Cash on Fri 07 May 2004 12:00 AM — 5 posts, 12,082 views.

USA #0
Ok, well, first off I'm having some linking issues. I'll not ask you all to fix these for me (yet :P). But I am having trouble. It appears that the following code is hanging the entire mud up, making me have to restart:

          for ( asteroid = ship->starsystem->first_asteroid; asteroid; asteroid = asteroid->next_in_system)
          {
                if (abs(ship->vx - asteroid->x) < 1 &&
                    abs(ship->vy - asteroid->y) < 1 &&
                    abs(ship->vz - asteroid->z) < 1 )
                {
                    ship->collision = asteroid->maxhp;
                    asteroid->collision = ship->maxhull;
                }
          }


The only conclusions I've come by is that the asteroid doesnt have an x/y/z. Anyways, I'd ask that you look over http://ew.xidus.net/code/3.0a.c and http://ew.xidus.net/code/asteroids.h for the actual asteroid code. Perhaps you could find any errors in the linking I've got.
USA #1
By the way, this only happens after an asteroid has been destroy and put back in the system. The linking errors are within starsystems because if I go to my Terra star system EVERY asteroid is in the list and display on look and radar. However, you cannot target or fire at them.
USA #2
Something tells me its extract_asteroid. I don't think the unlink is needed.
USA #3
Hmm, perhaps you all can spot something wrong with this function.

/*
 * Extract the asteroid from a starsystem
 */
bool extract_asteroid( ASTEROID_DATA *asteroid )
{
     SPACE_DATA *starsystem;

     starsystem = asteroid->starsystem;

     if ( asteroid == NULL || starsystem == NULL )
        return FALSE;

     if ( starsystem != NULL )
     {
     
      if ( starsystem->last_asteroid == asteroid )
        starsystem->last_asteroid = asteroid->prev_in_system;
        
      if ( starsystem->first_asteroid == asteroid )
        starsystem->first_asteroid = asteroid->next_in_system;
        
      if ( asteroid->prev_in_system )
        asteroid->prev_in_system->next_in_system = asteroid->next_in_system;
     
      if ( asteroid->next_in_system)
        asteroid->next_in_system->prev_in_system = asteroid->prev_in_system;
        
     }

    UNLINK( asteroid, starsystem->first_asteroid, starsystem->last_asteroid, next_in_system, prev_in_system );   
    asteroid->starsystem = NULL;

    return TRUE;
}

Thanks, hopefully we'll find something. I think it has to do with the UNLINK. Perhaps some of what it does is already taken care of above?
USA #4
::sigh:: Posting before I mess with it myself sure makes me look stupid. It appears I had my loop wrong, and was referencing to the master asteroid list (asteroid->next) rather than the individual list of each starystem (asteroid->next_in_system) and I am actually having no linking issues. However, I would still like to know about extract_asteroid. I'll go conjure some other problem for oyu all to solve.