Global tweaponlist:TList=New TList
Type tweapon
Field originX#, originY#, power, h:Iscenenode
Field dir:Byte,style:Byte,friendly:Byte
Method updatebullets()
dg_Movenode h,1,0,0
If DG_NodeX(h)>680 drop();Return
If DG_NodeX(h)<-20 drop();Return
If DG_NodeY(h)>500 drop();Return
If DG_NodeY(h)<-20 drop();Return
End Method
Method drop()
h.remove()
tweaponlist.remove(Self)
End Method
End Type
Function UpdateAllWeapons()
bulletcount=0
For Local w:tweapon=EachIn tweaponlist
bulletcount :+ 1
Select w.style
Case WEP_BULLET
w.updatebullets()
End Select
Next
End Function
Global tweaponlist:TList=New TList
For w : tweapon=EachIn tweaponlist
tweaponlist.remove(Self)
I have been looking through the API and have stumbled across core::list which seems to be similar. Is this what im looking for and is there any decent c++ examples anywhere showing this in use?
typedef struct QuickList
{
CBeing* data;
// Pointers
struct QuickList *pPrev;
struct QuickList *pNext;
} QuickList;
// Pointers to First and Last items
QuickList *g_pFirstItem = NULL;
QuickList *g_pLastItem = NULL;
// Add List Item
void AddListItem(CBeing* b)
{
// Create a new list item
QuickList *pItem = new QuickList;
// Set Integer value
pItem->data = b;
// Add to list
// If this is the first item added
if (g_pFirstItem == NULL)
{
g_pFirstItem = g_pLastItem = pItem;
pItem->pNext = pItem->pPrev = NULL;
}
else
{
// Add item to the end of the list
g_pLastItem->pNext = pItem;
pItem->pPrev = g_pLastItem;
g_pLastItem = pItem;
pItem->pNext = NULL;
}
}
// Remove all items
void RemoveAllItems()
{
QuickList *pDelItem, *pItem = g_pFirstItem;
// Loop while there are items
while (pItem != NULL)
{
// Set the delete item
pDelItem = pItem;
// Move to the next item
pItem = pItem->pNext;
// Delete the item
delete pDelItem;
}
// Set global pointers to NULL
g_pFirstItem = g_pLastItem = NULL;
}
// Print List
void PrintList()
{
QuickList *pItem = g_pFirstItem;
// Loop while there are items
while (pItem != NULL)
{
// Print this item
printf("%d %d %d\n", pItem->data->getID(), pItem->data->getX(), pItem->data->getY());
// Move to the next item
pItem = pItem->pNext;
}
}
// Quick Sort List
void QuickSortList(QuickList *pLeft, QuickList *pRight)
{
QuickList *pStart;
QuickList *pCurrent;
CBeing* copyBeing;
// If the left and right pointers are the same, then return
if (pLeft == pRight) return;
// Set the Start and the Current item pointers
pStart = pLeft;
pCurrent = pStart->pNext;
// Loop forever (well until we get to the right)
while (1)
{
// If the start item is less then the right
if (pStart->data->getX() < pCurrent->data->getX())
{
// Swap the items
copyBeing = pCurrent->data;
pCurrent->data = pStart->data;
pStart->data = copyBeing;
}
// Check if we have reached the right end
if (pCurrent == pRight) break;
// Move to the next item in the list
pCurrent = pCurrent->pNext;
}
// Set the Start and the Current item pointers
pStart = pLeft;
pCurrent = pStart->pNext;
// Loop forever (well until we get to the right)
while (1)
{
// If the start item is less then the right
if (pStart->data->getY() < pCurrent->data->getY())
{
// Swap the items
copyBeing = pCurrent->data;
pCurrent->data = pStart->data;
pStart->data = copyBeing;
}
// Check if we have reached the right end
if (pCurrent == pRight) break;
// Move to the next item in the list
pCurrent = pCurrent->pNext;
}
// Swap the First and Current items
copyBeing = pLeft->data;
pLeft->data = pCurrent->data;
pCurrent->data = copyBeing;
// Save this Current item
QuickList *pOldCurrent = pCurrent;
// Check if we need to sort the left hand size of the Current point
pCurrent = pCurrent->pPrev;
if (pCurrent != NULL)
{
if ((pLeft->pPrev != pCurrent) && (pCurrent->pNext != pLeft))
QuickSortList(pLeft, pCurrent);
}
// Check if we need to sort the right hand size of the Current point
pCurrent = pOldCurrent;
pCurrent = pCurrent->pNext;
if (pCurrent != NULL)
{
if ((pCurrent->pPrev != pRight) && (pRight->pNext != pCurrent))
QuickSortList(pCurrent, pRight);
}
}
// Quick Sort List
void QuickSortList2(QuickList *pLeft, QuickList *pRight)
{
QuickList *pStart;
QuickList *pCurrent;
CBeing* copyBeing;
// If the left and right pointers are the same, then return
if (pLeft == pRight) return;
// Set the Start and the Current item pointers
pStart = pLeft;
pCurrent = pStart->pNext;
// Loop forever (well until we get to the right)
while (1)
{
// If the start item is less then the right
if (pStart->data->getY() < pCurrent->data->getY())
{
// Swap the items
copyBeing = pCurrent->data;
pCurrent->data = pStart->data;
pStart->data = copyBeing;
}
// Check if we have reached the right end
if (pCurrent == pRight) break;
// Move to the next item in the list
pCurrent = pCurrent->pNext;
}
// Swap the First and Current items
copyBeing = pLeft->data;
pLeft->data = pCurrent->data;
pCurrent->data = copyBeing;
// Save this Current item
QuickList *pOldCurrent = pCurrent;
// Check if we need to sort the left hand size of the Current point
pCurrent = pCurrent->pPrev;
if (pCurrent != NULL)
{
if ((pLeft->pPrev != pCurrent) && (pCurrent->pNext != pLeft))
QuickSortList(pLeft, pCurrent);
}
// Check if we need to sort the right hand size of the Current point
pCurrent = pOldCurrent;
pCurrent = pCurrent->pNext;
if (pCurrent != NULL)
{
if ((pCurrent->pPrev != pRight) && (pRight->pNext != pCurrent))
QuickSortList(pCurrent, pRight);
}
}