So basically i have a struct TEntity
where
struct TEntity
{
int PID;
TEntity * next;
TEntity()
{
PID = 0;
next = NULL;
}
};
now when i add object i try to find last object in the linked list then, with that last object i set its next to the object that waits to be added +
new object PID is last_object PID + 1, but somehow i am unable to set that integer at all.
12-08 21:45:35.410: V/WNB_LOG(8285): INSERTING: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec
12-08 21:45:35.410: V/WNB_LOG(8285): LOADING OBJECT: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:45:35.410: V/WNB_LOG(8285): LOADING OBJECT: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:45:35.420: V/WNB_LOG(8285): Loading model: /mnt/sdcard/com.example.wirednavalbattle/files/objects/buildings/docks/dock_wood_long.tachogl12-08 21:45:35.430: V/WNB_LOG(8285): THIS IS FIRST_ENTITY pid: 012-08 21:45:36.670: V/WNB_LOG(8285): ------------------------------------------------------12-08 21:45:39.130: V/WNB_LOG(8285): INSERTING: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:45:39.130: V/WNB_LOG(8285): LOADING OBJECT: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:45:39.130: V/WNB_LOG(8285): LAST OBJECT PID: 012-08 21:45:39.130: V/WNB_LOG(8285): NOT FIRST ENTITY: lastpid: 1 mypid: 112-08 21:45:40.680: V/WNB_LOG(8285): ------------------------------------------------------12-08 21:45:43.420: V/WNB_LOG(8285): INSERTING: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:45:43.420: V/WNB_LOG(8285): LOADING OBJECT: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:45:43.420: V/WNB_LOG(8285): LAST OBJECT PID: 112-08 21:45:43.420: V/WNB_LOG(8285): NOT FIRST ENTITY: lastpid: 1 mypid: 112-08 21:51:29.080: V/WNB_LOG(8285): ------------------------------------------------------12-08 21:51:31.420: V/WNB_LOG(8285): INSERTING: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:51:31.420: V/WNB_LOG(8285): LOADING OBJECT: /mnt/sdcard/com.example.wirednavalbattle/files/objects/dock_wood_long.objspec12-08 21:51:31.420: V/WNB_LOG(8285): LAST OBJECT PID: 112-08 21:51:31.420: V/WNB_LOG(8285): NOT FIRST ENTITY: lastpid: 1 mypid: 1
now:
theres a struct calleld TMission where i store TEntity * object; <- the first object in linked list
this finds last object in linked list.
TEntity * FindLastObject()
{
if (object == NULL) return NULL;
TEntity * p = object;
while (p->next != NULL)
p = p->next;
return p;
}
and this is the code responsible for adding new object
void AddObject(TEntity * p)
{
TEntity * last = FindLastObject();
if (last != NULL)
{
last->next = p;
p->next = NULL;
p->PID = last->PID + 1;
ALOG("NOT FIRST ENTITY: lastpid: "+IntToStr(last->PID) + " mypid: "+IntToStr(p->PID));
object_len = object_len + 1;
} else //if we add first object
{
ALOG("THIS IS FIRST_ENTITY pid: 0");
object = p;
object->PID = 0;
object_len = 1;
}
}
now why the heck p->PID = last->PID + 1; ain't working?