Example #1
0
int Tool::use(Level* level, Point position)
{
	if (tool == TOOL_LOCKPICK)
	{
		Object* obj = level->objectAt(position);
		if (obj != NULL && obj->getType() == OBJ_DOOR_LOCKED)
		{
			world.addMessage("You unlock the door.");
			obj->onUse(level, position);
			int dex = world.player->getAttribute(ATTR_DEX);
			return rng->getInt(50 - 2*dex, 200 - 4*dex);
		}
		else if (obj != NULL && obj->getType() == OBJ_DOOR_CLOSED)
		{
			world.addMessage("The door doesn't appear to be locked.");
		}
		else if (obj != NULL && obj->getType() == OBJ_DOOR_OPEN)
		{
			world.addMessage("This door is already open.");
		}
		else
		{
			world.addMessage("You see no door there.");
		}
	}
	return 0;
}
Example #2
0
void  Session::move_missile()
{
  Command       cmd(_game_n);
  Object	*obj;
  Object	*obj2;
  std::list<Object *>::iterator it;
  std::list<Object *>::iterator it2;

  it = _listObj.begin();
  while (it != _listObj.end())
    {
      obj = *it;
      if (obj->getType() == 5 || obj->getType() == 6)
	{
	  obj->move(); //Mouvement des missiles
	  cmd.sendObjMove(obj, _p);
	  if (obj->getX() > 50) //Missile depassant la fenetre
	    {
	      cmd.sendDestroy(obj->getId() , 0, _p);
	      _listObj.erase(it);
	      it = _listObj.begin();
	    }
	}
      it++;
    }
}
void SpatialIndexManager::initObjectsInRange(PlayerObject* player) {
    uint64_t player_id = player->getParentId();
    if (player_id == 0) {
        return;
    }

    Object* tmp = gWorldManager->getObjectById(player_id);
    if (tmp->getType() != ObjType_Cell) {
        return;
    }

    CellObject* cell = static_cast<CellObject*>(tmp);

    tmp = gWorldManager->getObjectById(cell->getParentId());
    if (tmp->getType() != ObjType_Building) {
        return;
    }

    BuildingObject* building = static_cast<BuildingObject*>(tmp);

    ObjectList children = building->getAllCellChilds();

    std::for_each(children.begin(), children.end(), [this, player] (Object* cell_child) {
        if (cell_child->getType() != ObjType_Tangible) {
            return;
        }

        sendCreateObject(cell_child, player, true);
    });
}
Example #4
0
void DebugRenderer::unloadSceneArray(Scene* scene)
{
	logInfo("unload scene \"", scene->getName(), "\"");

	// Get some pointers and values
	ArrayElementContainer* elements = (ArrayElementContainer*)(scene->getElements());
	Object** objects = elements->getObjects();
	uint nb_objects = elements->getNbObjects();

	// For each mesh object:
	for(uint i=0 ; i < nb_objects ; i++)
	{
		Object* obj = objects[i];

		if(obj->getType() != Object::MESH)
			continue;

		MeshObject* mesh_obj = (MeshObject*)obj;
		Geometry* geo = mesh_obj->getGeometry();

		// Unload the material
		GeneralProfile* profile = (GeneralProfile*)(mesh_obj->getMaterial()->getProfile(GENERAL_PROFILE));

		// Unload the material
		profile->unloadTextures();
		profile->unloadProgram();

		// Delete the VAO;
		geo->deleteVAO(VAO_INDEX_RASTER);
	}
}
Example #5
0
bool Magic3D::ResourcesFont::remove(std::string name)
{
    bool result = false;
    Font* font = Resources<Font>::get(name);
    Resources<Font>::resources.erase(name);
    if (font)
    {
        std::map<std::string, Object*>::const_iterator it_o = ResourceManager::getObjects()->begin();

        while (it_o != ResourceManager::getObjects()->end())
        {
            Object* child = (*it_o++).second;

            if (child->getType() == eOBJECT_GUI_LABEL)
            {
                //static_cast<GUILabel*>(child)->setfont(NULL);
            }
        }

        delete font;

        result = true;
    }

    return result;
}
 //-----------------------------------------------------------------------
 ObjectPtr ObjectFactoryManager::createInstance(const Ogre::String& type) const
 {
     Factory<Object>* factory = findFactory(type);
     Object* object = factory->createInstance();
     assert(object->getType() == type);
     return ObjectPtr(object, Factory<Object>::Deleter(factory));
 }
Example #7
0
void Player::checkLoot()
{
	// Calculate loot area
	Rect lootArea = getRect();
	if(getWeapon() != NULL)	{
		// Add weapons width to loot area :NOTE: :TODO: Gives wrong result when the weapon is centered on the player etc...
		if(mFaceDirection == RIGHT)
			lootArea.right += getWeapon()->getWidth();
		else if(mFaceDirection == LEFT)
			lootArea.left -= getWeapon()->getWidth();
	}

	// Add some extra area
	lootArea.bottom += 20;
	lootArea.top -= 20;
	lootArea.left -= 20;
	lootArea.right += 20;

	// Find loot inside loot area
	Object* lootObject = getLevel()->findCollision(lootArea, getId(), LOOT);

	// If an object is found
	if(lootObject != NULL)
	{
		// If the object is loot
		if(lootObject->getType() == LOOT)	{
			// Cast and call equip()
			Loot* loot = dynamic_cast<Loot*>(lootObject);
			loot->equip(this);
		}
	}
}
Example #8
0
State* TempSelection::Update(int ddsize, float * ddata) {
	std::cerr << "TempSelection::Update" << std::endl;
	btVector3 start, end;
	std::pair<glm::vec4, glm::vec4> p = view->getCloseFar(ddata[0], ddata[1]);
	start = *(btVector3 *)&p.first;
	end = *(btVector3 *)&p.second;

//	start = btVector3(3.0f, -100.0f, 3.0f);
//	end = btVector3(3.0f, 50.0f, 3.0f);

	btCollisionWorld::AllHitsRayResultCallback crr_callback(start, end);
	w->dynamicsWorld->rayTest(start, end, crr_callback);

	btRigidBody * rb;
	Object * obj;
	renObjs.clear();
	for( int i=0; i<crr_callback.m_collisionObjects.size(); i++ ) {
		rb = (btRigidBody *) crr_callback.m_collisionObjects[i];
		obj = (Object *)(rb->getMotionState());
		if( obj->getType() != 10 ) {
			continue;
		}
		renObjs.push_back((Renderable *)obj);
	}
	return 0;
}	
Example #9
0
void	Session::spawnPlayer(Player *player)
{
  unsigned char	NewPosX;
  unsigned char	NewPosY;
  int		unblock = 10000;
  Object	*obj;
  std::list<Object *>::iterator it;

  NewPosX = 8 + rand() % 4;
  NewPosY = rand() % 32;
  it = _listObj.begin();
  while (it != _listObj.end())
    {
      obj = *it;
      if (obj->getType() != 5)
	{
	  if (obj->getX() < NewPosX + 6 && obj->getX() > NewPosX - 6 &&
	      obj->getY() < NewPosY + 6 && obj->getY() > NewPosY - 6)
	    {
	      NewPosX = 8 + rand() % 4;
	      NewPosY = rand() % 32;
	      it = _listObj.begin();
	    }
	}
      it++;
      unblock--;
      if (unblock == 0)
	return;
    }
  player->setPosx(NewPosX);
  player->setPosy(NewPosY);
}
Example #10
0
// ---------------------------------------------------------------------
void ShadowMap::loadSceneArray(ArrayElementContainer* elements, uint index_vao)
{
	Object** objects = elements->getObjects();
	uint nb_objects = elements->getNbObjects();

	Light** lights = elements->getLights();
	uint nb_lights = elements->getNbLights();

	// Build the VBOs and VAOs:
	// For each mesh object:
	for(uint i=0 ; i < nb_objects ; i++)
	{
		// Only select mesh objects:
		Object* obj = objects[i];
		if(obj->getType() != Object::MESH)
			continue;

		MeshObject* mesh_obj = (MeshObject*)obj;

		// Build the VAO (and the VBO is built automatically if needed):
		mesh_obj->getGeometry()->buildVAO(index_vao, SHADOW_MAP_ATTRIB_POSITION, 0, 0);
	}

	// Add shadow maps to each light:
	for(uint i=0 ; i < nb_lights ; i++)
	{
		Light* l = lights[i];
		l->setUserData(LIGHT_DATA_SHADOW_MAP, new ShadowMap(l->getShadowMapSize()));
	}
}
Example #11
0
void ShadowMap::unloadSceneArray(ArrayElementContainer* elements, uint index_vao)
{
	Object** objects = elements->getObjects();
	uint nb_objects = elements->getNbObjects();

	Light** lights = elements->getLights();
	uint nb_lights = elements->getNbLights();

	// Delete the VAOs:
	// For each mesh object:
	for(uint i=0 ; i < nb_objects ; i++)
	{
		// Only select mesh objects:
		Object* obj = objects[i];
		if(obj->getType() != Object::MESH)
			continue;

		MeshObject* mesh_obj = (MeshObject*)obj;

		// Delete the VAO:
		mesh_obj->getGeometry()->deleteVAO(index_vao);
	}

	// Remove the shadow maps for each light:
	for(uint i=0 ; i < nb_lights ; i++)
	{
		Light* l = lights[i];
		l->setUserData(LIGHT_DATA_SHADOW_MAP, NULL);
	}
}
Example #12
0
void SpatialIndexManager::createInWorld(Object* object)
{
    uint32 baseCell = 0xffffffff;

    //get parent object determine who to send creates for

    if(object->getParentId() == 0)    {
        //just create in the SI - it will keep track of nearby players
        this->_AddObject(object);
        return;
    }

    Object* parent = gWorldManager->getObjectById(object->getParentId());

    //start with equipped items
	if(parent->getType() == ObjType_Player)    {
		PlayerObject* player = static_cast<PlayerObject*>(parent);
        //add to equiplist manually yet we dont use the objectcontainer for equipped items yet
        player->getEquipManager()->addEquippedObject(object);
        gContainerManager->createObjectToRegisteredPlayers(parent, object);

        //sendCreateObject(object,player,false);
        gContainerManager->updateEquipListToRegisteredPlayers(player);
        return;
    }

    if(parent)    {
        //items in containers
        gContainerManager->createObjectToRegisteredPlayers(parent, object);
        return;
    }

	assert(false && "No valid parent");

}
Example #13
0
// Called when we change the scene
void DebugRenderer::loadSceneArray(Scene* scene)
{
	logInfo("setup scene \"", scene->getName(), "\"");

	// Get some pointers and values
	ArrayElementContainer* elements = (ArrayElementContainer*)(scene->getElements());
	Object** objects = elements->getObjects();
	uint nb_objects = elements->getNbObjects();

	uint nb_lights = elements->getNbLights();

	// Load the materials:
	// - create or complete the list(s) of additional preprocessor symbols:
	Preprocessor::SymbolList preproc_syms;

	// - add _NB_LIGHTS_:
	preproc_syms.push_back(PreprocSym("_NB_LIGHTS_", nb_lights));

	// - add _BRDF_FUNCTION_:
	preproc_syms.push_back(PreprocSym("_BRDF_FUNCTION_", brdf_function));

	// - add _FORWARD_SHADING_:
	preproc_syms.push_back("_FORWARD_SHADING_");

	// For each mesh object:
	for(uint i=0 ; i < nb_objects ; i++)
	{
		// Get some pointers:
		Object* obj = objects[i];

		if(obj->getType() != Object::MESH)
			continue;

		MeshObject* mesh_obj = (MeshObject*)obj;
		Geometry* geo = mesh_obj->getGeometry();
		Material* mat = obj->getMaterial();
		GeneralProfile* profile = (GeneralProfile*)(mat->getProfile(GENERAL_PROFILE));

		// Load the material's general profile:
		profile->loadTextures();
		profile->loadProgram(preproc_syms);

		// Build the usual VAO (and VBO is done automatically if needed)
		GLuint vertex_attrib = GENERAL_PROFILE_ATTRIB_POSITION;
		GLuint normal_attrib = 0;
		GLuint texcoords_attrib = 0;

		if( ! profile->hasNormalMapping())
			normal_attrib = GENERAL_PROFILE_ATTRIB_NORMAL;

		if(profile->hasTextureMapping() || profile->hasNormalMapping())
			texcoords_attrib = GENERAL_PROFILE_ATTRIB_TEXCOORDS;

		geo->buildVAO(VAO_INDEX_RASTER, vertex_attrib, normal_attrib, texcoords_attrib);
	}

	// Sort objects by program
	elements->sortObjectsByProgram(GENERAL_PROFILE);
}
 uint32_t ObjectCache::getIdFromFrame(Frame* frame){
     Object* object = dynamic_cast<Object*>(frame);
     if(object != NULL && object->getType() == ft02_Object){
         return object->getId();
     }else{
         return 0xffffffff;
     }
 }
 uint64_t ObjectCache::getModTimeFromFrame(Frame* frame){
     Object* object = dynamic_cast<Object*>(frame);
     if(object != NULL && object->getType() == ft02_Object){
         return object->getLastModifiedTime();
     }else{
         return 0LL;
     }
 }
Example #16
0
	virtual void traverseObjectPtr(Object** ptrToObject)
	{
		Object* object = *ptrToObject;
		cout << object << "\n";
		
		if(object == NULL || Object::isInlineValue(object))
		{
			// nothing
		}
		else if(deep > 3)
		{
			cout << "...\n";
		}
		else
		{
			object->getType()->getTraverser()(&PrintTraverser(deep + 1), object->getType(), object);
		}
	}
Example #17
0
Object* MetaCategory::ControllerDefault (
  const MetaClass* cat, const DataValueDict& in, CommandManager* mgr
  )
{
  Action act = MetaClass::decodeAction(in);
  switch (act)
  {
    case REMOVE:
      throw DataException
      ("Entity " + cat->type + " doesn't support REMOVE action");
    case CHANGE:
      throw DataException
      ("Entity " + cat->type + " doesn't support CHANGE action");
    default:
      /* Lookup the class in the map of registered classes. */
      const MetaClass* j;
      if (cat->category)
        // Class metadata passed: we already know what type to create
        j = cat;
      else
      {
        // Category metadata passed: we need to look up the type
        const DataValue* type = in.get(Tags::type);
        j = static_cast<const MetaCategory&>(*cat).findClass(
          type ? Keyword::hash(type->getString()) : MetaCategory::defaultHash
          );
        if (!j)
        {
          string t(type ? type->getString() : "default");
          throw LogicException("No type " + t + " registered for category " + cat->type);
        }
      }

      // Call the factory method
      assert(j->factoryMethod);
      Object* result = j->factoryMethod();

      // Run the callback methods
      if (!result->getType().raiseEvent(result, SIG_ADD))
      {
        // Creation denied
        delete result;
        throw DataException("Can't create object");
      }

      // Report the creation to the manager
      if (mgr)
        mgr->add(new CommandCreateObject(result));

      // Creation accepted
      return result;
  }
  throw LogicException("Unreachable code reached");
  return nullptr;
}
Example #18
0
bool OCGs::optContentIsVisible( Object *dictRef )
{
  Object dictObj;
  Dict *dict;
  Object dictType;
  Object ocg;
  Object policy;
  bool result = true;
  dictRef->fetch( m_xref, &dictObj );
  if ( ! dictObj.isDict() ) {
    error(-1, "Unexpected oc reference target: %i", dictObj.getType() );
    dictObj.free();
    return result;
  }
  dict = dictObj.getDict();
  // printf("checking if optContent is visible\n");
  dict->lookup("Type", &dictType);
  if (dictType.isName("OCMD")) {
    // If we supported Visibility Expressions, we'd check
    // for a VE entry, and then call out to the parser here...
    // printf("found OCMD dict\n");
    dict->lookup("P", &policy);
    dict->lookupNF("OCGs", &ocg);
    if (ocg.isArray()) {
      if (policy.isName("AllOn")) {
	result = allOn( ocg.getArray() );
      } else if (policy.isName("AllOff")) {
	result = allOff( ocg.getArray() );
      } else if (policy.isName("AnyOff")) {
	result = anyOff( ocg.getArray() );
      } else if ( (!policy.isName()) || (policy.isName("AnyOn") ) ) {
	// this is the default
	result = anyOn( ocg.getArray() );
      }
    } else if (ocg.isRef()) {
      OptionalContentGroup* oc = findOcgByRef( ocg.getRef() );      
      if ( !oc || oc->getState() == OptionalContentGroup::Off ) {
	result = false;
      } else {
	result = true ;
      }
    }
    ocg.free();
    policy.free();
  } else if ( dictType.isName("OCG") ) {
    OptionalContentGroup* oc = findOcgByRef( dictRef->getRef() );
    if ( !oc || oc->getState() == OptionalContentGroup::Off ) {
      result=false;
    }
  }
  dictType.free();
  dictObj.free();
  // printf("visibility: %s\n", result? "on" : "off");
  return result;
}
Example #19
0
void ColoredWorld::deleteRigidBody(btRigidBody* rigidBody){
	bool remove = true;
	btCollisionObject* col_obj;
	Object* object;
//	printf("delete in color\n");

	if(m_objects.find(rigidBody) != m_objects.end()){
		object = m_objects.at(rigidBody);
		col_obj = object->getCollObj();

		if(object->getType() != COL_CASTLE){
			delete object;
		}
		m_objects.erase(rigidBody);

	} else if(m_transparentobjects.find(rigidBody) != m_transparentobjects.end()) {
		object = m_transparentobjects.at(rigidBody);
		col_obj = object->getCollObj();
		delete object;
		m_transparentobjects.erase(rigidBody);
	} else {

		// the object is not there any more!
		// This is a very nasty glitch due to errors in WallObject implementation
//		printf("not here\n");
		remove = false;
	}

	if(remove){
		if(object->getType() == COL_LETTERS){
			m_letterObjects.remove(object);
		}
	}


	if(remove){
	//	printf("numObjs: %d\n", m_objects.size());
		m_collMap.erase(col_obj);
		m_dynamicsWorld->removeRigidBody(rigidBody);
		delete rigidBody;
	}
}
void trackFilteredObject(Object theObject,Mat threshold,Mat HSV, Mat &cameraFeed)
{

    vector <Object> objects;
    Mat temp;
    threshold.copyTo(temp);
    //these two vectors needed for output of findContours
    vector< vector<Point> > contours;
    vector<Vec4i> hierarchy;
    //find contours of filtered image using openCV findContours function
    findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
    //use moments method to find our filtered object
    bool objectFound = false;
    if (hierarchy.size() > 0)
    {
        int numObjects = hierarchy.size();
        //if number of objects greater than MAX_NUM_OBJECTS we have a noisy filter
        if(numObjects<MAX_NUM_OBJECTS){
            for (int index = 0; index >= 0; index = hierarchy[index][0])
            {
                Moments moment = moments((cv::Mat)contours[index]);
                double area = moment.m00;

                //if the area is less than 20 px by 20px then it is probably just noise
                //if the area is the same as the 3/2 of the image size, probably just a bad filter
                //we only want the object with the largest area so we safe a reference area each
                //iteration and compare it to the area in the next iteration.
                if(area>MIN_OBJECT_AREA)
                {
                    Object object;

                    object.setXPos(moment.m10/area);
                    object.setYPos(moment.m01/area);
                    object.setType(theObject.getType());
                    object.setColor(theObject.getColor());

                    objects.push_back(object);

                    objectFound = true;

                }else objectFound = false;
            }
            //let user know you found an object
            if(objectFound ==true)
            {
                //draw object location on screen
                drawObject(objects,cameraFeed,temp,contours,hierarchy);
            }

        }
        else
            putText(cameraFeed,"TOO MUCH NOISE! ADJUST FILTER",Point(0,50),1,2,Scalar(0,0,255),2);
    }
}
Example #21
0
Math::Vector3d Command::getObjectPosition(const ResourceReference &targetRef, int32 *floorFace) {
	Object *target = targetRef.resolve<Object>();
	Floor *floor = StarkGlobal->getCurrent()->getFloor();

	Math::Vector3d position;
	switch (target->getType().get()) {
		case Type::kBookmark: {
			Bookmark *bookmark = Object::cast<Bookmark>(target);
			position = bookmark->getPosition();

			if (floorFace) {
				*floorFace = floor->findFaceContainingPoint(position);
			}

	        break;
		}
		case Type::kItem: {
			FloorPositionedItem *item = Object::cast<FloorPositionedItem>(target);
			position = item->getPosition3D();

			if (floorFace) {
				*floorFace = item->getFloorFaceIndex();
			}

			break;
		}
		case Type::kPath: {
			assert(target->getSubType() == Path::kPath3D);

			Path3D *path = Object::cast<Path3D>(target);
			position = path->getVertexPosition3D(0, floorFace);

			break;
		}
		default:
			warning("Unimplemented getObjectPosition target type %s", target->getType().getName());
	}

	return position;
}
Example #22
0
bool DrawPathTool::removeLastPointFromSelectedPath()
{
	if (editingInProgress() || map()->getNumSelectedObjects() != 1)
	{
		return false;
	}
	
	Object* object = map()->getFirstSelectedObject();
	if (object->getType() != Object::Path)
	{
		return false;
	}
	
	PathObject* path = object->asPath();
	if (path->parts().size() != 1)
	{
		return false;
	}
	
	int points_on_path = 0;
	int num_coords = path->getCoordinateCount();
	for (int i = 0; i < num_coords && points_on_path < 3; ++i)
	{
		++points_on_path;
		if (path->getCoordinate(i).isCurveStart())
		{
			i += 2; // Skip the control points.
		}
	}
	
	if (points_on_path < 3)
	{
		// Too few points after deleting the last: delete the whole object.
		map()->deleteSelectedObjects();
		return true;
	}
	
	ReplaceObjectsUndoStep* undo_step = new ReplaceObjectsUndoStep(map());
	Object* undo_duplicate = object->duplicate();
	undo_duplicate->setMap(map());
	undo_step->addObject(object, undo_duplicate);
	map()->push(undo_step);
	updateDirtyRect();
	
	path->parts().front().setClosed(false);
	path->deleteCoordinate(num_coords - 1, false);
	
	path->update();
	map()->setObjectsDirty();
	map()->emitSelectionEdited();
	return true;
}
Example #23
0
DECLARE_EXPORT void Tree::clear()
{
  // Tree is already empty
  if (empty()) return;

  // Erase all elements
  for (TreeNode* x = begin(); x != end(); x = begin())
  {
    Object *o = dynamic_cast<Object*>(x);
    if (o && o->getType().raiseEvent(o, SIG_REMOVE))
      delete(x);  // The destructor calls the erase method
    else
      throw DataException("Can't delete object");
  }
}
Example #24
0
void MoCap::copyFootsProperties()
{
    foots.clear();
    idfoots.clear();
    Vec4 aux;
    for(unsigned int i=0;i<chara->getBodiesFoot().size();i++){
        Object *foot = chara->getBodiesFoot().at(i);
        Object *newObj = new Object(Vec4(),QuaternionQ(),foot->getProperties(),foot->getType(),foot->getScene());
        aux.setVec4(0,foot->getProperties().y()/2.0,0);
        idfoots.push_back(chara->getIdObject(foot));
        foots.push_back(newObj);
    }
//    if(idfoots.size()>0)
//        updateHeightBody(aux,idfoots.at(0));
}
Example #25
0
void EditPointTool::drawImpl(QPainter* painter, MapWidget* widget)
{
	auto num_selected_objects = map()->selectedObjects().size();
	if (num_selected_objects > 0)
	{
		drawSelectionOrPreviewObjects(painter, widget, text_editor != nullptr);
		
		if (!text_editor)
		{
			Object* object = *map()->selectedObjectsBegin();
			if (num_selected_objects == 1 &&
			    object->getType() == Object::Text &&
			    !object->asText()->hasSingleAnchor())
			{
				drawBoundingPath(painter, widget, object->asText()->controlPoints(), hover_state.testFlag(OverFrame) ? active_color : selection_color);
			}
			else if (selection_extent.isValid())
			{
				auto active = hover_state.testFlag(OverFrame) && !hover_state.testFlag(OverObjectNode);
				drawBoundingBox(painter, widget, selection_extent, active ? active_color : selection_color);
			}
			
			if (num_selected_objects <= max_objects_for_handle_display)
			{
				for (const auto object: map()->selectedObjects())
				{
					auto active = hover_state.testFlag(OverObjectNode) && hover_object == object;
					auto hover_point = active ? this->hover_point : no_point;
					pointHandles().draw(painter, widget, object, hover_point, true, PointHandles::NormalHandleState);
				}
			}
		}
	}
	
	// Text editor
	if (text_editor)
	{
		painter->save();
		widget->applyMapTransform(painter);
		text_editor->draw(painter, widget);
		painter->restore();
	}
	
	// Box selection
	if (isDragging() && box_selection)
		drawSelectionBox(painter, widget, click_pos_map, cur_pos_map);
}
Example #26
0
Object* MetaCategory::ControllerDefault (const MetaClass* cat, const AttributeList& in)
{
  Action act = ADD;
  switch (act)
  {
    case REMOVE:
      throw DataException
      ("Entity " + cat->type + " doesn't support REMOVE action");
    case CHANGE:
      throw DataException
      ("Entity " + cat->type + " doesn't support CHANGE action");
    default:
      /* Lookup for the class in the map of registered classes. */
      const MetaClass* j;
      if (cat->category)
        // Class metadata passed: we already know what type to create
        j = cat;
      else
      {
        // Category metadata passed: we need to look up the type
        const DataElement* type = in.get(Tags::tag_type);
        j = static_cast<const MetaCategory&>(*cat).findClass(*type ? Keyword::hash(type->getString()) : MetaCategory::defaultHash);
        if (!j)
        {
          string t(*type ? type->getString() : "default");
          throw LogicException("No type " + t + " registered for category " + cat->type);
        }
      }

      // Call the factory method
      Object* result = j->factoryMethodDefault();

      // Run the callback methods
      if (!result->getType().raiseEvent(result, SIG_ADD))
      {
        // Creation denied
        delete result;
        throw DataException("Can't create object");
      }

      // Creation accepted
      return result;
  }
  throw LogicException("Unreachable code reached");
  return NULL;
}
void ObjectBrick::collide(const Object& object, Direction collideDirection)
{
	if (collideDirection == NONE)
		return;
	switch (object.getType())
	{
	case MARIO_BIG:
	case MARIO_SUPER:
		switch (collideDirection)
		{
		case UP:
			if (!dying_)
				destroy(BRICK_DYING_DURATION);
			break;
		}
		break;
	}
}
void ObjectFlagPole::collide(const Object& object, Direction collideDirection)
{
	if (collideDirection == NONE)
		return;

	switch (object.getType())
	{
	case MARIO_SMALL:
	case MARIO_BIG:
	case MARIO_SUPER:
		if (!inEvent_)
		{
			Arena& arena = Arena::getUniqueInstance();
			arena.addEvent(KEEP_NOT_PASSABLE, this, 1000, 0);
			arena.addEvent(KEEP_MOVING_Y, flag_, 1000, FLAG_POLE_HEIGHT - 30);
		}
		break;
	}
}
Example #29
0
void Session::collision_player_mob()
{
  Command       cmd(_game_n);
  Object	*obj;
  Object	*obj2;
  std::list<Object *>::iterator it;
  std::list<Object *>::iterator it2;
  int   j;

  it = _listObj.begin();
  while (it != _listObj.end())
    {
      j = 0;
      obj = *it;
      while (j <= 3)
	{
	  if (_tabPlayer[j] != NULL && obj->getType() != 5 && 
	      obj->getX() < _tabPlayer[j]->getPosx() + 2 && obj->getX() > _tabPlayer[j]->getPosx() - 2 &&
	      obj->getY() < _tabPlayer[j]->getPosy() + 2 && obj->getY() > _tabPlayer[j]->getPosy() - 2)
	    {
	      if (obj->getType() == 26)
		{
		  std::cout << "Collison avec coeur !!!" << std::endl;
		  _tabPlayer[j]->setLife(_tabPlayer[j]->getLife() + 1);
		  cmd.sendLife(_tabPlayer[j], _p);
		  cmd.sendDestroy(obj->getId() , 0, _p);
		  _listObj.erase(it);
		  it = _listObj.begin();
		}
	      else if ((_tabPlayer[j]->getLife() - 1) > 0)
		{
		  std::cout << "ca pas Collison avec coeur !!!" << std::endl;
		  _tabPlayer[j]->setLife(_tabPlayer[j]->getLife() - 1);
		  cmd.sendLife(_tabPlayer[j], _p);
		  if (obj->getType() != 9 && obj->getType() != 21 && obj->getType() != 22 && obj->getType() != 24) // Les murs et les boss ne se detruisent pas
		    {
		      cmd.sendDestroy(obj->getId() , 0, _p); 
		      _listObj.erase(it);
		      it = _listObj.begin();
		    }
		  spawnPlayer(_tabPlayer[j]);
		}
	      else
		_pingTime[j] = 0;
	    }
	  j++;
	}
      it++;
    }
}
Example #30
0
//=============================================================================================
// gets a headcount of all tangible (!!!) Objects in the container
// including those contained in containers
uint16 Object::getHeadCount() {
    uint16_t count = 0;

    std::for_each(mData.begin(), mData.end(), [&count] (uint64_t object_id) {
        Object* object = gWorldManager->getObjectById(object_id);

        if (object->getType() != ObjType_Tangible) {
            return;
        }

        TangibleObject* tangible = static_cast<TangibleObject*>(object);

        if (!tangible->getStatic()) {
            count += tangible->getHeadCount();
            ++count;
        }
    });

    return count;
}