/*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList genderList;
      Node gender;
      EntityReference entRef;
      Element entElement;
      Node entNode;
      Node appendedChild;
      doc = (Document) baseT::load("staff", true);
      genderList = doc.getElementsByTagName(SA::construct_from_utf8("gender"));
      gender = genderList.item(2);
      entRef = doc.createEntityReference(SA::construct_from_utf8("ent4"));
      baseT::assertNotNull(entRef, __LINE__, __FILE__);
      appendedChild = gender.appendChild(entRef);
      entNode = entRef.getFirstChild();
      baseT::template skipIfNot<Element>(entNode);
     entElement = (Element) entRef.getFirstChild();
      baseT::assertNotNull(entElement, __LINE__, __FILE__);
      
      {
         boolean success = false;
         try {
            entElement.removeAttribute(SA::construct_from_utf8("domestic"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR);
         }
         assertTrue(success);
      }

   }
void GameManager::build(SDL_Event & event, WidgetReference widget)
{
	std::cout << "GameManager::build(" << widget->id << ")" << std::endl;
	if(self)
	{
		Faction faction = F_PLAYER_1;
		EntityType type = (EntityType) widget->id;
		VillageReference village = villageManager.getVillage(faction);
		EntityReference townCenter = village->getTownCenter();

		if(!townCenter)
			std::cerr << "No town center." << std::endl;
		else
		{
			Position origin = townCenter->getPosition();
			Position position = self->obstructionMap->findOpenPosition(origin);

			EntityReference entity = new Entity(type, 1, position, faction);
			entityManager.createRecord(entity);

			self->obstructionMap->set(position, OT_OBSTRUCTED);

			//std::cout << (*(self->obstructionMap)) << std::endl;
		}

		//self->villageManager.buildHouse();
	}
	else
		std::cerr << "GameManager not initialized." << std::endl;
}
static duk_ret_t EntityReference_IsEmpty(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    bool ret = thisObj->IsEmpty();
    duk_push_boolean(ctx, ret);
    return 1;
}
static duk_ret_t EntityReference_Set_Entity(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Entity* entity = GetWeakObject<Entity>(ctx, 0);
    thisObj->Set(entity);
    return 0;
}
void GameManager::miracle(SDL_Event & event, WidgetReference widget)
{
	std::cout << "GameManager::miracle(" << widget->id << ")" << std::endl;
	if(self)
	{
		//  NOTE: widget->id is the MiracleType (needs to be cast).
		Faction faction = F_PLAYER_1;
		EntityType type = (EntityType) widget->id;
		VillageReference village = villageManager.getVillage(faction);
		EntityReference townCenter = village->getTownCenter();

		if(!townCenter)
			std::cout << "No town center." << std::endl;
		else if(!type)
			std::cout << "No type." << std::endl;
		else if(0)
		{
			Position origin = townCenter->getPosition();
			Position position = origin;

			EntityReference entity = new MiracleEntity(type, 1, position, faction);
			#pragma unused (entity)
			//self->createRecord(entity);
		}
		else
			std::cout << "Type: " << type << ", but not implemented." << std::endl;

	}
	else
		std::cerr << "GameManager not initialized." << std::endl;
}
static duk_ret_t EntityReference_LookupParent_Entity(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Entity* entity = GetWeakObject<Entity>(ctx, 0);
    EntityPtr ret = thisObj->LookupParent(entity);
    PushWeakObject(ctx, ret.Get());
    return 1;
}
static duk_ret_t EntityReference_Lookup_Scene(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Scene* scene = GetWeakObject<Scene>(ctx, 0);
    EntityPtr ret = thisObj->Lookup(scene);
    PushWeakObject(ctx, ret.Get());
    return 1;
}
static duk_ret_t EntityReference_Matches_Entity(duk_context* ctx)
{
    EntityReference* thisObj = GetThisValueObject<EntityReference>(ctx, EntityReference_ID);
    Entity* entity = GetWeakObject<Entity>(ctx, 0);
    bool ret = thisObj->Matches(entity);
    duk_push_boolean(ctx, ret);
    return 1;
}
void fromScriptValueEntityReference(const QScriptValue &obj, EntityReference &s)
{
    if (obj.isString())
        s.ref = obj.toString();
    else
    {
        if (!obj.property("ref").isValid())
            LogError("Can't convert QScriptValue to EntityReference! QScriptValue does not contain ref attribute!");
        else
        {
            QScriptValue ref = obj.property("ref");
            if (ref.isNull())
                s.ref = ""; // Empty the reference
            else if (ref.isString())
                s.ref = ref.toString();
            else if (ref.isQObject())
            {
                // If the object is an Entity, call EntityReference::Set() with it
                Entity* entity = dynamic_cast<Entity*>(ref.toQObject());
                s.Set(entity);
            }
            else if (ref.isNumber() || ref.isVariant())
                s.ref = QString::number(ref.toInt32());
            else
                LogError("Can't convert QScriptValue to EntityReference! Ref attribute is not null, string, a number, or an entity");
        }
    }
}
void Village::import(EntityReference entity)
{
	Faction faction = entity->getFaction();
	EntityGroup group = entity->getGroup();
	EntityType type = entity->getEntityType();

	if(faction == this->faction)
	{
		switch(group)
		{
		case EG_VILLAGER:
			villagerList.push_back((MobileEntityReference)entity);

			availableHousing --;
			break;

		case EG_DOMESTIC:
			domesticList.push_back((MobileEntityReference)entity);
			break;

		case EG_BUILDING:
			buildingList.push_back(entity);

			switch(type)
			{
				case ET_TOWN_CENTER:
					if(townCenter)
						std::cerr << "A second town center? How fancy!" << std::endl;
					townCenter = entity;
				break;

				case ET_HOUSE:
					availableHousing += POP_PER_HOUSE;
					break;

				case ET_TEMPLE:
					break;

				default:
					break;
			}
			break;

		default: break;
		}
	}
}
Exemple #11
0
QScriptValue EntityReference_prototype_Lookup(QScriptContext *ctx, QScriptEngine *engine)
{
    int argCount = ctx->argumentCount();
    if (argCount != 1)
        return ctx->throwError(QScriptContext::TypeError, "EntityReference Lookup(): Invalid number of arguments.");
    
    if (!ctx->argument(0).isQObject())
        return ctx->throwError(QScriptContext::TypeError, "EntityReference Lookup(): Argument is not a QObject");
    
    Scene* scene = dynamic_cast<Scene*>(ctx->argument(0).toQObject());
    
    EntityReference s;
    fromScriptValueEntityReference(ctx->thisObject(), s);
    
    EntityPtr entity = s.Lookup(scene);
    return engine->newQObject(entity.get());
}
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     EntityReference newEntRefNode;
     String entRefValue;
     String entRefName;
     int entRefType;
     doc = (Document) baseT::load("staff", true);
     newEntRefNode = doc.createEntityReference(SA::construct_from_utf8("ent1"));
     baseT::assertNotNull(newEntRefNode, __LINE__, __FILE__);
     entRefValue = newEntRefNode.getNodeValue();
     baseT::assertNull(entRefValue, __LINE__, __FILE__);
     entRefName = newEntRefNode.getNodeName();
     baseT::assertEquals("ent1", entRefName, __LINE__, __FILE__);
 entRefType = (int) newEntRefNode.getNodeType();
     baseT::assertEquals(5, entRefType, __LINE__, __FILE__);
 
  }
void GameManager::setup()
{
	WorldGeneration world;
	worldSize = world.getWorldSize();

	initializeCallbackMap();
	buttonContainer = new SdlWidgetContainer(callbackMap, "res/sidebar-files.cfg");

	mapView = new SdlMapView();
	mapView->hide();

	SdlEntity::mapView = mapView;
	SdlEntity::worldSize = worldSize;

	//  Village Manager
	villageManager.show();
	villageManager.addVillage(F_PLAYER_1);
	villageManager.addVillage(F_PLAYER_2);
	hide();

	obstructionMap = new ObstructionMap(worldSize);


	EntityReference tempEntity = world.getNextEntity();
	EntityReference storedEntity;
	int count = 0;
	while (tempEntity && tempEntity->getType() != ET_NONE)
	{
		storedEntity = entityManager.createRecord(tempEntity);
		villageManager.import(storedEntity);
		creatureManager.import(storedEntity);
		if (tempEntity->getGroup() >= EG_MOBILE)
			obstructionMap->set(tempEntity->getPosition(), OT_CONSIDERED);
		else
			obstructionMap->set(tempEntity->getPosition(), OT_OBSTRUCTED);

		// Get next entity for next loop iteration.
		delete tempEntity;
		tempEntity = world.getNextEntity();
		count++;
	}
	std::cout << count << std::endl;
}
  /*
   * Runs the test case.
   */
  void runTest()
  {
     Document doc;
     EntityReference newEntRefNode;
     NodeList newEntRefList;
     Node child;
     String name;
     String value;
     doc = (Document) baseT::load("staff", true);
     newEntRefNode = doc.createEntityReference(SA::construct_from_utf8("ent3"));
     baseT::assertNotNull(newEntRefNode, __LINE__, __FILE__);
     newEntRefList = newEntRefNode.getChildNodes();
     baseT::assertSize(1, newEntRefList, __LINE__, __FILE__);
     child = newEntRefNode.getFirstChild();
     name = child.getNodeName();
     baseT::assertEquals("#text", name, __LINE__, __FILE__);
 value = child.getNodeValue();
     baseT::assertEquals("Texas", value, __LINE__, __FILE__);
 
  }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      EntityReference entRef;
      CharacterData entText;
      doc = (Document) baseT::load("staff", true);
      entRef = doc.createEntityReference(SA::construct_from_utf8("ent3"));
      baseT::assertNotNull(entRef, __LINE__, __FILE__);
      entText = (CharacterData) entRef.getFirstChild();
      baseT::assertNotNull(entText, __LINE__, __FILE__);
      
      {
         boolean success = false;
         try {
            entText.setNodeValue(SA::construct_from_utf8("newValue"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR);
         }
         assertTrue(success);
      }

   }
   /*
    * Runs the test case.
    */
   void runTest()
   {
      Document doc;
      NodeList genderList;
      Node genderNode;
      EntityReference entRef;
      Node entNode;
      Element entElement;
      CharacterData entElementText;
      int nodeType;
      doc = (Document) baseT::load("staff", true);
      genderList = doc.getElementsByTagName(SA::construct_from_utf8("gender"));
      genderNode = genderList.item(2);
      entNode = genderNode.getFirstChild();
      baseT::template skipIfNot<EntityReference>(entNode);
     entRef = (EntityReference) genderNode.getFirstChild();
      baseT::assertNotNull(entRef, __LINE__, __FILE__);
      nodeType = (int) entRef.getNodeType();
      
      if (baseT::equals(1, nodeType)) {
          entRef = doc.createEntityReference(SA::construct_from_utf8("ent4"));
      baseT::assertNotNull(entRef, __LINE__, __FILE__);
      }
    entElement = (Element) entRef.getFirstChild();
      baseT::assertNotNull(entElement, __LINE__, __FILE__);
      entElementText = (CharacterData) entElement.getFirstChild();
      baseT::assertNotNull(entElementText, __LINE__, __FILE__);
      
      {
         boolean success = false;
         try {
            entElementText.setNodeValue(SA::construct_from_utf8("newValue"));
          } catch (const DOMException& ex) {
            success = (ex.code() == DOMException::NO_MODIFICATION_ALLOWED_ERR);
         }
         assertTrue(success);
      }

   }
Exemple #17
0
bool UniPAX::EntityReference::merge(EntityReference& object)
{
	{
		std::set<UniPAX::EntityReferencePtr> tmp(getMemberEntityReferences().begin(), getMemberEntityReferences().end());
		for (std::vector<UniPAX::EntityReferencePtr>::iterator it = object.getMemberEntityReferences().begin(); it != object.getMemberEntityReferences().end(); it++)
		{
			if (*it)
			{
				tmp.insert(*it);
			}
		}
		getMemberEntityReferences().assign(tmp.begin(), tmp.end());
	}
	{
		std::set<UniPAX::EvidencePtr> tmp(getEvidences().begin(), getEvidences().end());
		for (std::vector<UniPAX::EvidencePtr>::iterator it = object.getEvidences().begin(); it != object.getEvidences().end(); it++)
		{
			if (*it)
			{
				tmp.insert(*it);
			}
		}
		getEvidences().assign(tmp.begin(), tmp.end());
	}
	if (entityReferenceType)
	{
		if (entityReferenceType->getUnipaxId() != object.getEntityReferenceType()->getUnipaxId())
		{
			std::cerr << "Error during merging: UniPAX::EntityReference::entityReferenceType not equal ..."
					<< entityReferenceType->getUnipaxId() << " != " << object.getEntityReferenceType()->getUnipaxId() << std::endl;
			return false;
		}

	}
	else
	{
		setEntityReferenceType(object.getEntityReferenceType());
	}

	if (entityFeature)
	{
		if (entityFeature->getUnipaxId() != object.getEntityFeature()->getUnipaxId())
		{
			std::cerr << "Error during merging: UniPAX::EntityReference::entityFeature not equal ..."
					<< entityFeature->getUnipaxId() << " != " << object.getEntityFeature()->getUnipaxId() << std::endl;
			return false;
		}
	}
	else
	{
		setEntityFeature(object.getEntityFeature());
	}
	{
		std::set<UniPAX::XrefPtr> tmp(xref.begin(), xref.end());
		for (std::vector<UniPAX::XrefPtr>::iterator it = object.getXrefs().begin(); it != object.getXrefs().end(); it++)
		{
			if (*it)
			{
				tmp.insert(*it);
			}
		}
		xref.assign(tmp.begin(), tmp.end());
	}
	{
		std::set<std::string> tmp(name.begin(), name.end());
		for (std::vector<std::string>::iterator it = object.getNames().begin(); it != object.getNames().end(); it++)
		{
			tmp.insert(*it);
		}
		if (!object.getStandardName().empty())
			tmp.insert(object.getStandardName());
		if (!object.getDisplayName().empty())
			tmp.insert(object.getDisplayName());
		name.assign(tmp.begin(), tmp.end());
	}

	return UniPAX::UtilityClass::merge(object);
}