Xonotic
rubble.qc
Go to the documentation of this file.
1 #include "rubble.qh"
2 
3 #ifdef GAMEQC
4 
5 void LimitedChildrenRubble(IntrusiveList list, string cname, int limit, void(entity) deleteproc, entity parent){
6  // remove rubble of the same type if it's at the limit
7  // remove multiple rubble if the limit has been decreased
8  while (1)
9  {
10  // walk the list and count the entities, find the oldest
11  // initialize our search with the first entity
12  int c = 0;
13  entity oldest = NULL;
14  float oldesttime = 0;
15  // compare to all other matching entities
16  IL_EACH(list, it.classname == cname,
17  {
18  if(!parent || parent == it.owner){
19  ++c;
20  if(!oldest || oldesttime > it.creationtime)
21  {
22  oldest = it;
23  oldesttime = it.creationtime;
24  }
25  }
26  });
27 
28  // stop if there are less than the limit already
29  if (c <= limit) break;
30 
31  // delete this oldest one and search again
32  deleteproc(oldest);
33  }
34 }
35 
36 
37 // This function doesn't preserve linked list order but it is not needed as creationtime is used instead of list position for comparing ages.
38 // IL_Replace or similiar order preserving function did not exist at the time of creating this.
39 entity ReplaceOldListedChildRubble(IntrusiveList list, entity child, entity oldChild){
40  child.creationtime = oldChild.creationtime;
41  IL_REMOVE(list, oldChild);
42  IL_PUSH(list, child);
43  return child;
44 }
45 
46 entity ListNewChildRubble(IntrusiveList list, entity child){
47  child.creationtime = time;
48  IL_PUSH(list, child);
49  return child;
50 }
51 
52 #endif
ERASEABLE void IL_REMOVE(IntrusiveList this, entity it)
Remove any element, anywhere in the list.
#define IL_EACH(this, cond, body)
entity parent
Definition: animhost.qc:7
entity() spawn
limitations: NULL cannot be present elements can only be present once a maximum of IL_MAX lists can e...
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
#define NULL
Definition: post.qh:17
float time
Definition: csprogsdefs.qc:16