Posted to tcl by hypnotoad at Mon Dec 08 22:41:47 GMT 2014view pretty

/*
** The step counter has just changed.  Initialize the Crew structure
** accordingly.
** 
** pCrew has finished with its current path step.  Advance it to the
** next step.  Or if it has reached its final destination, halt it.
*/
static  inline void gotoNextStep(Crew *pCrew){
  Waypoint *pW, *pWPrev=NULL;
  int i;
  pCrew->iStep++;
  if( pCrew->iStep>=pCrew->nStep ){
    Crew_Halt(pCrew,CREW_OPERATION_ARRIVED);
    return;
  }  

  /* Waypoint we are approaching */
  pW = &pCrew->aStep[pCrew->iStep];
  if( pCrew->iStep>0 ){
    /* Waypoint we are leaving */
    pWPrev = &pCrew->aStep[pCrew->iStep-1];
    pCrew->public_compartment = pWPrev->cid;
  }
  if(pW->cid != pCrew->public_compartment) {
    pCrew->public_compartment_entering = pW->cid;
  } else {
    pCrew->public_compartment_entering = 0;
  }
  insertIntoCidList(pCrew);

  pCrew->nextPid = 0;

  pCrew->public_operation = CREW_OPERATION_MOVE;
  pCrew->fx = pCrew->tx;
  pCrew->tx = pW->x;
  pCrew->fy = pCrew->ty;
  pCrew->ty = pW->y;
  
  /* Calculate our next portal */
  for(i=pCrew->iStep;i<pCrew->nStep;i++) {
    Waypoint *pWNext=&pCrew->aStep[i];
    if(pWNext->pid) {
      pCrew->nextPid=pWNext->pid;
    }
  }
}