Skip to main content
gamedev.net
🔒 Locked

array sorting algoritm, help please!!!!

Started by The Alchemist 0 replies 450+ views
Original Post
The Alchemist
The Alchemist
hehehe is weird. me talking about programing... well i got this problem:
    
Battle::addToInOrder(Fighter *fighter)
{
	if(inOrderInit == true)
	{
		if(inOrderIndex > 0)
		{
			int count;
			for(count = 0; fighter->actualStats[AGI] <= inOrder[count]->actualStats[AGI] && count < inOrderIndex;count++);
			int regCount;
			for(regCount = inOrderIndex; regCount >= count; regCount--)
			{
				inOrder[regCount + 1] = inOrder[regCount];
			}
			inOrder[count] = fighter;
			inOrderIndex++;							
		}
		else
		{
			if(fighter->actualStats[AGI] > inOrder[0]->actualStats[AGI])
			{
				inOrder[1] = inOrder[0];
				inOrder[0] = fighter;
			}
			else
			{
				inOrder[1] = fighter;
			}
			inOrderIndex++;
		}
	}
	else
	{
		inOrderInit = true;
		inOrder[0] = fighter;
		inOrderIndex = 0;
	}
	return;
}
    
see? this is my problem. i use in my rpg battle demo a system similar of the Xenogears fight. when the bar get full the caracter MUST make a action. the problem is, what happens when two or more caracters have their bar full at same time? so to avoid this i come with this ideia. a array of pointers to the Fighter class(the caracters base class) that is sorted by their agility whic this disaster algoritm in a way that i can make their actions happen just making a for loop. the problem is. it doesn´t work!!! so guys i ask( no, i beg) to you take a look this code upon here, so you can tell me if there any big logical erros on it. please!!! just to help you guys to help me. inOrder: is a pointer to the Fighter array. inOrderInit: a bool that indicates that there already a fighter in the array. inOrderIndex: is a int that have the number of the last element on the array. ex: if the array is loaded until [3] is value should be 3. actualStats[AGI]: a menber of the Fighter class tha have the agilily of the caracter. if you guys need any other infomation just call me. another thing, if you have a code that do something similar and works you can show me? So. i was there in the middle of a lot of witches and mages, when she come to me: -You are too young to be a mage. -No, i´m not a mage, i´m a programmer. -How! Sorry... what a bad luck. -Yeah... Don´t even talk about it...
"Everything works out in the end, if it doesn't then it is not the end"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.