src/game/Tactical/Soldier_Init_List.cc
static void SortSoldierInitList(void)
{
	SOLDIERINITNODE *temp, *curr;

	if( !gSoldierInitHead )
		return;

	//1st priority sort
	curr = gSoldierInitTail;
	while( curr )
	{
		if( curr->pSoldier && curr != gSoldierInitTail )
		{
			//This node has an existing soldier, so move to end of list.
			//copy node
			temp = curr;
			if( temp == gSoldierInitHead )
			{
				//If we dealing with the head, we need to move it now.
				gSoldierInitHead = gSoldierInitHead->next;
				if( gfOriginalList )
					gOriginalSoldierInitListHead = gSoldierInitHead;
				else
					gAlternateSoldierInitListHead = gSoldierInitHead;
				gSoldierInitHead->prev = NULL;
				temp->next = NULL;
			}
			curr = curr->prev;
			//detach node from list
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			//add node to end of list
			temp->prev = gSoldierInitTail;
			temp->next = NULL;
			gSoldierInitTail->next = temp;
			gSoldierInitTail = temp;
		}
		else
		{
			curr = curr->prev;
		}
	}
	//4th -- put to start
	curr = gSoldierInitHead;
	while( curr )
	{
		if( !curr->pSoldier && !curr->pBasicPlacement->fPriorityExistance && curr->pDetailedPlacement && curr != gSoldierInitHead )
		{
			//Priority existance nodes without detailed placement info are moved to beginning of list
			//copy node
			temp = curr;
			if( temp == gSoldierInitTail )
			{
				//If we dealing with the tail, we need to move it now.
				gSoldierInitTail = gSoldierInitTail->prev;
				gSoldierInitTail->next = NULL;
				temp->prev = NULL;
			}
			curr = curr->next;
			//detach node from list
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			//add node to beginning of list
			temp->prev = NULL;
			temp->next = gSoldierInitHead;
			gSoldierInitHead->prev = temp;
			gSoldierInitHead = temp;
			if( gfOriginalList )
				gOriginalSoldierInitListHead = gSoldierInitHead;
			else
				gAlternateSoldierInitListHead = gSoldierInitHead;
		}
		else
		{
			curr = curr->next;
		}
	}
	//3rd priority sort (see below for reason why we do 2nd after 3rd)
	curr = gSoldierInitHead;
	while( curr )
	{
		if( !curr->pSoldier && curr->pBasicPlacement->fPriorityExistance && !curr->pDetailedPlacement && curr != gSoldierInitHead )
		{
			//Priority existance nodes without detailed placement info are moved
			//to beginning of list copy node
			temp = curr;
			if( temp == gSoldierInitTail )
			{
				//If we dealing with the tail, we need to move it now.
				gSoldierInitTail = gSoldierInitTail->prev;
				gSoldierInitTail->next = NULL;
				temp->prev = NULL;
			}
			curr = curr->next;
			//detach node from list
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			//add node to beginning of list
			temp->prev = NULL;
			temp->next = gSoldierInitHead;
			gSoldierInitHead->prev = temp;
			gSoldierInitHead = temp;
			if( gfOriginalList )
				gOriginalSoldierInitListHead = gSoldierInitHead;
			else
				gAlternateSoldierInitListHead = gSoldierInitHead;
		}
		else
		{
			curr = curr->next;
		}
	}
	//2nd priority sort (by adding these to the front, it'll be before the
	//3rd priority sort.  This is why we do it after.
	curr = gSoldierInitHead;
	while( curr )
	{
		if( !curr->pSoldier && curr->pBasicPlacement->fPriorityExistance && curr->pDetailedPlacement && curr != gSoldierInitHead )
		{	//Priority existance nodes are moved to beginning of list
			//copy node
			temp = curr;
			if( temp == gSoldierInitTail )
			{
				//If we dealing with the tail, we need to move it now.
				gSoldierInitTail = gSoldierInitTail->prev;
				gSoldierInitTail->next = NULL;
				temp->prev = NULL;
			}
			curr = curr->next;
			//detach node from list
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			//add node to beginning of list
			temp->prev = NULL;
			temp->next = gSoldierInitHead;
			gSoldierInitHead->prev = temp;
			gSoldierInitHead = temp;
			if( gfOriginalList )
				gOriginalSoldierInitListHead = gSoldierInitHead;
			else
				gAlternateSoldierInitListHead = gSoldierInitHead;
		}
		else
		{
			curr = curr->next;
		}
	}
	//4th priority sort
	//Done!  If the soldier existing slots are at the end of the list and the
	//       priority placements are at the beginning of the list, then the
	//       basic placements are in the middle.
}
//Because soldiers, creatures, etc., maybe added to the game at anytime theoretically, the
//list will need to be sorted to reflect this.  It is quite likely that this won't be needed,
//but the flexibility is there just incase.  Now the list is sorted in the following manner:
//-1st priority:  Any nodes containing valid pointers to soldiers are moved to the end of the list.
//                We don't ever want to use two identical placements.
//-2nd priority:  Any nodes that have priority existance and detailed placement information are
//                put first in the list.
//-3rd priority:  Any nodes that have priority existance and no detailed placement information are used next.
//-4th priority:  Any nodes that have detailed placement and no priority existance information are used next.
//-5th priority:  The rest of the nodes are basic placements and are placed in the center of the list.  Of
//                these, they are randomly filled based on the number needed.
//NOTE:  This function is called by AddSoldierInitListTeamToWorld().  There is no other place it needs to
//       be called.
Because soldiers, creatures, etc., maybe added to the game at anytime theoretically, the
list will need to be sorted to reflect this.  It is quite likely that this won't be needed,
but the flexibility is there just incase.  Now the list is sorted in the following manner:
1st priority:  Any nodes containing valid pointers to soldiers are moved to the end of the list.
We don't ever want to use two identical placements.
2nd priority:  Any nodes that have priority existance and detailed placement information are
put first in the list.
3rd priority:  Any nodes that have priority existance and no detailed placement information are used next.
4th priority:  Any nodes that have detailed placement and no priority existance information are used next.
5th priority:  The rest of the nodes are basic placements and are placed in the center of the list.  Of
these, they are randomly filled based on the number needed.
NOTE:  This function is called by AddSoldierInitListTeamToWorld().  There is no other place it needs to
be called.
Because soldiers creatures etc . maybe added to the game at anytime theoretically the list will need to be sorted to reflect this . It is quite likely that this won ' t be needed but the flexibility is there just incase . Now the list is sorted in the following manner : 1st priority : Any nodes containing valid pointers to soldiers are moved to the end of the list . We don ' t ever want to use two identical placements . 2nd priority : Any nodes that have priority existance and detailed placement information are put first in the list . 3rd priority : Any nodes that have priority existance and no detailed placement information are used next . 4th priority : Any nodes that have detailed placement and no priority existance information are used next . 5th priority : The rest of the nodes are basic placements and are placed in the center of the list . Of these they are randomly filled based on the number needed . NOTE : This function is called by AddSoldierInitListTeamToWorld () . There is no other place it needs to be called .
static void SortSoldierInitList(void)
{
	SOLDIERINITNODE *temp, *curr;
	if( !gSoldierInitHead )
		return;
	curr = gSoldierInitTail;
	while( curr )
	{
		if( curr->pSoldier && curr != gSoldierInitTail )
		{
			temp = curr;
			if( temp == gSoldierInitHead )
			{
				gSoldierInitHead = gSoldierInitHead->next;
				if( gfOriginalList )
					gOriginalSoldierInitListHead = gSoldierInitHead;
				else
					gAlternateSoldierInitListHead = gSoldierInitHead;
				gSoldierInitHead->prev = NULL;
				temp->next = NULL;
			}
			curr = curr->prev;
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			temp->prev = gSoldierInitTail;
			temp->next = NULL;
			gSoldierInitTail->next = temp;
			gSoldierInitTail = temp;
		}
		else
		{
			curr = curr->prev;
		}
	}
	curr = gSoldierInitHead;
	while( curr )
	{
		if( !curr->pSoldier && !curr->pBasicPlacement->fPriorityExistance && curr->pDetailedPlacement && curr != gSoldierInitHead )
		{
			temp = curr;
			if( temp == gSoldierInitTail )
			{
				gSoldierInitTail = gSoldierInitTail->prev;
				gSoldierInitTail->next = NULL;
				temp->prev = NULL;
			}
			curr = curr->next;
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			temp->prev = NULL;
			temp->next = gSoldierInitHead;
			gSoldierInitHead->prev = temp;
			gSoldierInitHead = temp;
			if( gfOriginalList )
				gOriginalSoldierInitListHead = gSoldierInitHead;
			else
				gAlternateSoldierInitListHead = gSoldierInitHead;
		}
		else
		{
			curr = curr->next;
		}
	}
	curr = gSoldierInitHead;
	while( curr )
	{
		if( !curr->pSoldier && curr->pBasicPlacement->fPriorityExistance && !curr->pDetailedPlacement && curr != gSoldierInitHead )
		{
			temp = curr;
			if( temp == gSoldierInitTail )
			{
				gSoldierInitTail = gSoldierInitTail->prev;
				gSoldierInitTail->next = NULL;
				temp->prev = NULL;
			}
			curr = curr->next;
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			temp->prev = NULL;
			temp->next = gSoldierInitHead;
			gSoldierInitHead->prev = temp;
			gSoldierInitHead = temp;
			if( gfOriginalList )
				gOriginalSoldierInitListHead = gSoldierInitHead;
			else
				gAlternateSoldierInitListHead = gSoldierInitHead;
		}
		else
		{
			curr = curr->next;
		}
	}
	curr = gSoldierInitHead;
	while( curr )
	{
		if( !curr->pSoldier && curr->pBasicPlacement->fPriorityExistance && curr->pDetailedPlacement && curr != gSoldierInitHead )
		{	
			temp = curr;
			if( temp == gSoldierInitTail )
			{
				gSoldierInitTail = gSoldierInitTail->prev;
				gSoldierInitTail->next = NULL;
				temp->prev = NULL;
			}
			curr = curr->next;
			if( temp->prev )
				temp->prev->next = temp->next;
			if( temp->next )
				temp->next->prev = temp->prev;
			temp->prev = NULL;
			temp->next = gSoldierInitHead;
			gSoldierInitHead->prev = temp;
			gSoldierInitHead = temp;
			if( gfOriginalList )
				gOriginalSoldierInitListHead = gSoldierInitHead;
			else
				gAlternateSoldierInitListHead = gSoldierInitHead;
		}
		else
		{
			curr = curr->next;
		}
	}
}
static void SortSoldierInitList ( void ) { SOLDIERINITNODE * temp , * curr ; if ( ! gSoldierInitHead ) return ; curr = gSoldierInitTail ; while ( curr ) { if ( curr -> pSoldier && curr != gSoldierInitTail ) { temp = curr ; if ( temp == gSoldierInitHead ) { gSoldierInitHead = gSoldierInitHead -> next ; if ( gfOriginalList ) gOriginalSoldierInitListHead = gSoldierInitHead ; else gAlternateSoldierInitListHead = gSoldierInitHead ; gSoldierInitHead -> prev = NULL ; temp -> next = NULL ; } curr = curr -> prev ; if ( temp -> prev ) temp -> prev -> next = temp -> next ; if ( temp -> next ) temp -> next -> prev = temp -> prev ; temp -> prev = gSoldierInitTail ; temp -> next = NULL ; gSoldierInitTail -> next = temp ; gSoldierInitTail = temp ; } else { curr = curr -> prev ; } } curr = gSoldierInitHead ; while ( curr ) { if ( ! curr -> pSoldier && ! curr -> pBasicPlacement -> fPriorityExistance && curr -> pDetailedPlacement && curr != gSoldierInitHead ) { temp = curr ; if ( temp == gSoldierInitTail ) { gSoldierInitTail = gSoldierInitTail -> prev ; gSoldierInitTail -> next = NULL ; temp -> prev = NULL ; } curr = curr -> next ; if ( temp -> prev ) temp -> prev -> next = temp -> next ; if ( temp -> next ) temp -> next -> prev = temp -> prev ; temp -> prev = NULL ; temp -> next = gSoldierInitHead ; gSoldierInitHead -> prev = temp ; gSoldierInitHead = temp ; if ( gfOriginalList ) gOriginalSoldierInitListHead = gSoldierInitHead ; else gAlternateSoldierInitListHead = gSoldierInitHead ; } else { curr = curr -> next ; } } curr = gSoldierInitHead ; while ( curr ) { if ( ! curr -> pSoldier && curr -> pBasicPlacement -> fPriorityExistance && ! curr -> pDetailedPlacement && curr != gSoldierInitHead ) { temp = curr ; if ( temp == gSoldierInitTail ) { gSoldierInitTail = gSoldierInitTail -> prev ; gSoldierInitTail -> next = NULL ; temp -> prev = NULL ; } curr = curr -> next ; if ( temp -> prev ) temp -> prev -> next = temp -> next ; if ( temp -> next ) temp -> next -> prev = temp -> prev ; temp -> prev = NULL ; temp -> next = gSoldierInitHead ; gSoldierInitHead -> prev = temp ; gSoldierInitHead = temp ; if ( gfOriginalList ) gOriginalSoldierInitListHead = gSoldierInitHead ; else gAlternateSoldierInitListHead = gSoldierInitHead ; } else { curr = curr -> next ; } } curr = gSoldierInitHead ; while ( curr ) { if ( ! curr -> pSoldier && curr -> pBasicPlacement -> fPriorityExistance && curr -> pDetailedPlacement && curr != gSoldierInitHead ) { temp = curr ; if ( temp == gSoldierInitTail ) { gSoldierInitTail = gSoldierInitTail -> prev ; gSoldierInitTail -> next = NULL ; temp -> prev = NULL ; } curr = curr -> next ; if ( temp -> prev ) temp -> prev -> next = temp -> next ; if ( temp -> next ) temp -> next -> prev = temp -> prev ; temp -> prev = NULL ; temp -> next = gSoldierInitHead ; gSoldierInitHead -> prev = temp ; gSoldierInitHead = temp ; if ( gfOriginalList ) gOriginalSoldierInitListHead = gSoldierInitHead ; else gAlternateSoldierInitListHead = gSoldierInitHead ; } else { curr = curr -> next ; } } }
Because soldiers, creatures, etc., maybe added to the game at anytime theoretically, the
list will need to be sorted to reflect this.
Because soldiers creatures etc . maybe added to the game at anytime theoretically the list will need to be sorted to reflect this .
//1st priority sort //This node has an existing soldier, so move to end of list. //copy node //If we dealing with the head, we need to move it now. //detach node from list //add node to end of list //4th -- put to start //Priority existance nodes without detailed placement info are moved to beginning of list //copy node //If we dealing with the tail, we need to move it now. //detach node from list //add node to beginning of list //3rd priority sort (see below for reason why we do 2nd after 3rd) //Priority existance nodes without detailed placement info are moved //to beginning of list copy node //If we dealing with the tail, we need to move it now. //detach node from list //add node to beginning of list //2nd priority sort (by adding these to the front, it'll be before the //3rd priority sort.  This is why we do it after. //Priority existance nodes are moved to beginning of list //copy node //If we dealing with the tail, we need to move it now. //detach node from list //add node to beginning of list //4th priority sort //Done!  If the soldier existing slots are at the end of the list and the //       priority placements are at the beginning of the list, then the //       basic placements are in the middle.