Пример #1
0
C4ValueArray *C4FindObject::FindMany(const C4ObjectList &Objs,
                                     const C4LSectors &Sct) {
  // Trivial case
  if (IsImpossible()) return new C4ValueArray();
  C4Rect *pBounds = GetBounds();
  if (!pBounds) return FindMany(Objs);
  // Prepare for array that may be generated
  C4ValueArray *pArray;
  int32_t iSize;
  // Check shape lists?
  if (UseShapes()) {
    // Get area
    C4LArea Area(&Game.Objects.Sectors, *pBounds);
    C4LSector *pSct;
    C4ObjectList *pLst = Area.FirstObjectShapes(&pSct);
    // Check if a single-sector check is enough
    if (!Area.Next(pSct)) return FindMany(pSct->ObjectShapes);
    // Set up array
    pArray = new C4ValueArray(32);
    iSize = 0;
    // Create marker, search all areas
    uint32_t iMarker = ::Game.Objects.GetNextMarker();
    for (; pLst; pLst = Area.NextObjectShapes(pLst, &pSct))
      for (C4ObjectLink *pLnk = pLst->First; pLnk; pLnk = pLnk->Next)
        if (pLnk->Obj->Status)
          if (pLnk->Obj->Marker != iMarker) {
            pLnk->Obj->Marker = iMarker;
            if (Check(pLnk->Obj)) {
              // Grow the array, if neccessary
              if (iSize >= pArray->GetSize()) pArray->SetSize(iSize * 2);
              // Add object
              (*pArray)[iSize++] = C4VObj(pLnk->Obj);
            }
          }
  } else {
    // Set up array
    pArray = new C4ValueArray(32);
    iSize = 0;
    // Search
    C4LArea Area(&Game.Objects.Sectors, *pBounds);
    C4LSector *pSct;
    for (C4ObjectList *pLst = Area.FirstObjects(&pSct); pLst;
         pLst = Area.NextObjects(pLst, &pSct))
      for (C4ObjectLink *pLnk = pLst->First; pLnk; pLnk = pLnk->Next)
        if (pLnk->Obj->Status)
          if (Check(pLnk->Obj)) {
            // Grow the array, if neccessary
            if (iSize >= pArray->GetSize()) pArray->SetSize(iSize * 2);
            // Add object
            (*pArray)[iSize++] = C4VObj(pLnk->Obj);
          }
  }
  // Shrink array
  pArray->SetSize(iSize);
  // Recheck object status (may shrink array again)
  CheckObjectStatus(pArray);
  // Apply sorting
  if (pSort) pSort->SortObjects(pArray);
  return pArray;
}
Пример #2
0
// return is to be freed by the caller
C4ValueArray *C4FindObject::FindMany(const C4ObjectList &Objs)
{
	// Trivial case
	if (IsImpossible())
		return new C4ValueArray();
	// Set up array
	C4ValueArray *pArray = new C4ValueArray(32);
	int32_t iSize = 0;
	// Search
	for (C4Object *obj : Objs)
		if (obj->Status)
			if (Check(obj))
			{
				// Grow the array, if neccessary
				if (iSize >= pArray->GetSize())
					pArray->SetSize(iSize * 2);
				// Add object
				(*pArray)[iSize++] = C4VObj(obj);
			}
	// Shrink array
	pArray->SetSize(iSize);
	// Recheck object status (may shrink array again)
	CheckObjectStatus(pArray);
	// Apply sorting
	if (pSort) pSort->SortObjects(pArray);
	return pArray;
}
Пример #3
0
C4ValueArray * C4PropList::GetProperties() const
{
	C4ValueArray * a;
	int i;
	if (GetPrototype())
	{
		a = GetPrototype()->GetProperties();
		i = a->GetSize();
		a->SetSize(i + Properties.GetSize());
	}
	else
	{
		a = new C4ValueArray(Properties.GetSize());
		i = 0;
	}
	const C4Property * p = Properties.First();
	while (p)
	{
		assert(p->Key != nullptr && "Proplist key is nullpointer");
		(*a)[i++] = C4VString(p->Key);
		assert(((*a)[i - 1].GetType() == C4V_String) && "Proplist key is non-string");
		p = Properties.Next(p);
	}
	return a;
}
Пример #4
0
C4ValueArray * C4Effect::GetProperties() const
{
	C4ValueArray * a = C4PropList::GetProperties();
	int i;
	i = a->GetSize();
	a->SetSize(i + 5);
	(*a)[i++] = C4VString(&::Strings.P[P_Name]);
	(*a)[i++] = C4VString(&::Strings.P[P_Priority]);
	(*a)[i++] = C4VString(&::Strings.P[P_Interval]);
	(*a)[i++] = C4VString(&::Strings.P[P_CommandTarget]);
	(*a)[i++] = C4VString(&::Strings.P[P_Time]);
	return a;
}