Esempio n. 1
0
//Initiates the attack action between the two Characters.
//Pre:  Both characters have been loaded.
//Post: The initiator's attack is checked against the
//      receiver's defense. The attack that is leftover
//      after the defense is subtracted is then reduced
//      from the receiver's hitpoints. If the HP are reduced
//      to 0 or below, the Character will be dead.
void ShieldBash::execute(){

    if(initiator == NULL || receiver == NULL)
        return;

    //Determines the damage to the receiver.
    calculateDamage();

    //Remove receiver's hitpoints.
    receiver->addToRemainingHP(-damageToReceiver);

    loadAnimations();
}
void EntityResourceManager::loadResource(const std::string filepath)
{
	//open up the file
	std::filebuf fb;
	fb.open(filepath, std::ios::in);

	//try to parse it
	Json::Value root;
	Json::Reader reader;
	bool parseSuccessful = reader.parse(std::istream(&fb), root);
	//now we have it parsed we can close it
	fb.close();

	if(!parseSuccessful)
	{
		std::cerr << "Unable to load entity: " << filepath << std::endl;
		std::cerr << reader.getFormattedErrorMessages() << std::endl;
		return;
	}

	Entity *entityPtr = loadType(root);
	if(entityPtr == NULL)
	{
		std::cerr << "Invalid type in entity file " << filepath << std::endl;
		return;
	}

	loadGenerics(*entityPtr, root);
	loadDamagingEntity(*entityPtr, root);
	loadCharacter(*entityPtr, root);

	std::string behaviour = root.get("behaviour", "").asString();
	if(!behaviour.empty())
	{
		loadBehaviour(*entityPtr, root);
	}

	Json::Value animations = root["animations"];
	if(animations.size() > 0)
	{
		loadAnimations(*entityPtr, root);
	}

	Json::Value abilities = root["abilities"];
	if(abilities.size() > 0)
	{
		loadAbilities(*entityPtr, root);
	}

	resourceMap[filepath] = entityPtr;
}
Esempio n. 3
0
// Note: DOES update member loaded
void CreatureManager::loadCreature(const CreatureType ct) {
	assert(loaded.count(ct) == 0);	// should not already be loaded
	auto& list = loaded[ct];	// insert and get default object
	// find name associated with CreatureType
	auto it = lookupMap.cbegin();
	for (; it != lookupMap.cend(); ++it) {
		if (it->second == ct)
			break;
	}
	assert(it != lookupMap.cend());
	// load
	std::shared_ptr<rapidjson::Document> data = GameData::instance().resources->getCreatureData(it->first);
	//! TODO process attr
	loadAnimations(*data, list);
}
size_t EnemyManager::loadEnemyPrototype(const std::string& type_id) {
	for (size_t i = 0; i < prototypes.size(); i++) {
		if (prototypes[i].type == type_id) {
			return i;
		}
	}

	Enemy e = Enemy();

	e.eb = new BehaviorStandard(&e);
	e.stats.load(type_id);
	e.type = type_id;

	if (e.stats.animations == "")
		Utils::logError("EnemyManager: No animation file specified for entity: %s", type_id.c_str());

	loadAnimations(&e);
	e.loadSounds();

	// set cooldown_hit to duration of hit animation if undefined
	if (e.stats.cooldown_hit == -1) {
		Animation *hit_anim = e.animationSet->getAnimation("hit");
		if (hit_anim) {
			e.stats.cooldown_hit = hit_anim->getDuration();
			delete hit_anim;
		}
		else {
			e.stats.cooldown_hit = 0;
		}
	}

	prototypes.push_back(e);
	size_t prototype = prototypes.size() - 1;

	for (size_t i = 0; i < e.stats.powers_ai.size(); i++) {
		int power_index = e.stats.powers_ai[i].id;
		const std::string& spawn_type = powers->powers[power_index].spawn_type;
		if (power_index != 0 && spawn_type != "" && spawn_type != "untransform") {
			std::vector<Enemy_Level> spawn_enemies = enemyg->getEnemiesInCategory(spawn_type);
			for (size_t j = 0; j < spawn_enemies.size(); j++) {
				loadEnemyPrototype(spawn_enemies[j].type);
			}
		}
	}

	return prototype;
}
Esempio n. 5
0
// Create a model by deserializing it from Json
Model::Model(const Json::Value& root, const std::string& directory, TextureCache &_textureCache)
    : meshes(0, NULL), skeleton(new Node()), textureCache(_textureCache), previousProgram(NULL), uploaded(false)
{
    // Load animations
    loadAnimations(root);
    
    // Load materials
    loadMaterials(root, directory);
    
    // Load mesh data
    loadMeshes(root);
    
    // Load node data
    loadSkeleton(root);
    
    // Load parts
    loadParts(root);
}
Esempio n. 6
0
 //--------------------------------------------------------------------------
 void FLevelFile::loadModels()
 {
     HRCFileManager &hrc_mgr( HRCFileManager::getSingleton() );
     ModelList      &models( m_model_list->getModels() );
     ModelList::const_iterator it    ( models.begin() )
                             , it_end( models.end()   );
     while( it != it_end )
     {
         String hrc_name( it->hrc_name );
         Ogre::LogManager::getSingleton().stream()
             << "Loading Model: " << hrc_name;
         StringUtil::toLowerCase( hrc_name );
         HRCFilePtr  hrc( hrc_mgr.load( hrc_name, mGroup ) );
         loadAnimations( hrc, it->animations );
         m_hrc_files.push_back( hrc );
         ++it;
     }
 }
Esempio n. 7
0
void GameModule::load(const char *filename) {
	debug(0, "GameModule::load()");

	unload();

	Common::File fd;

	if (!fd.open(filename))
		error("GameModule::load() Could not open %s", filename);

	loadBgSprites(fd);
	loadCameraInits(fd);
	loadWalkRects(fd);
	loadSceneExits(fd);
	loadBgObjects(fd);
	loadAnimations(fd);
	loadSceneObjectDefs(fd);
	loadSceneObjectInits(fd);
	loadActions(fd);
	loadGuiSpriteIndices(fd);
	loadInventoryItemSpriteIndices(fd);
	loadInventoryItemInfos(fd);
	loadDialogItemSpriteIndices(fd);
	loadSceneSounds(fd);
	loadPreloadSounds(fd);

	fd.seek(0xC);
	_fieldC = fd.readUint32LE();

	fd.seek(0x1A8);
	_buttheadObjectIndex = fd.readUint32LE();

	fd.close();

	debug(0, "GameModule::load() OK");
}
Esempio n. 8
0
void gkGamePlayer::load(gkBlendFile* playerData)
{
	gkScene* dest = m_levelData->getLevel();
	gkScene* tscene = playerData->getMainScene();


	GK_ASSERT(
	    tscene->hasObject(GK_RESOURCE_PLAYER_SKEL) &&
	    tscene->hasObject(GK_RESOURCE_PLAYER_MESH) &&
	    tscene->hasObject(GK_RESOURCE_PLAYER_VIEW) &&
	    tscene->hasObject(GK_RESOURCE_PLAYER_ZROT) &&
	    tscene->hasObject(GK_RESOURCE_PLAYER_XROT) &&
	    tscene->hasObject(GK_RESOURCE_PLAYER_PHYS)
	);


	m_skeleton = tscene->getObject(GK_RESOURCE_PLAYER_SKEL)->getSkeleton();
	m_entity   = tscene->getObject(GK_RESOURCE_PLAYER_MESH)->getEntity();
	m_camera   = tscene->getObject(GK_RESOURCE_PLAYER_VIEW)->getCamera();
	m_zRot     = tscene->getObject(GK_RESOURCE_PLAYER_ZROT);
	m_xRot     = tscene->getObject(GK_RESOURCE_PLAYER_XROT);
	m_physics  = tscene->getObject(GK_RESOURCE_PLAYER_PHYS);

	m_playerData.setup(this);
	
	dest->addObject(m_skeleton);
	dest->addObject(m_entity);
	dest->addObject(m_camera);
	dest->addObject(m_zRot);
	dest->addObject(m_xRot);
	dest->addObject(m_physics);

	loadConstraints();
	loadAnimations();
	loadHuds();
}
Esempio n. 9
0
bool Loader::loadFromModel(const char *fileName)
{
    printf("load %s begin\n",fileName);
    printf("parsing..\n");
    const aiScene* pScene = m_Importer.ReadFile(fileName,aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenSmoothNormals |aiProcess_CalcTangentSpace);
    this->m_pScene = (aiScene*)pScene;
    if(!m_pScene)
    {
        printf("parsing failure!\n");
        return false;
    }
    else
    {
        printf("parsing succes!\n");
        printf("extracting data to memory...\n");
        m_model = new CMC_ModelData();

        auto inverseTransform = pScene->mRootNode->mTransformation;
        inverseTransform = inverseTransform.Inverse();
        m_model->setGlobalInverseTransform (toQMatrix(inverseTransform));
        LoadMaterial(pScene,fileName);

        const aiVector3D Zero3D(0.0f, 0.0f, 0.0f);
        for(int i =0 ;i< pScene->mNumMeshes ;i++)
        {
            const aiMesh* the_mesh = pScene->mMeshes[i];
            auto mesh = new CMC_MeshData;
            m_model->addMesh(mesh);
            //set material
            mesh->setMaterialIndex (the_mesh->mMaterialIndex);
            for(int j =0; j<the_mesh->mNumVertices;j++)
            {
                const aiVector3D* pPos = &(the_mesh->mVertices[j]);
                const aiVector3D* pNormal = &(the_mesh->mNormals[j]);
                const aiVector3D* pTexCoord = the_mesh->HasTextureCoords(0) ? &(the_mesh->mTextureCoords[0][j]) : &Zero3D;
                const aiVector3D* pTangent = &(the_mesh->mTangents[i]);
                CMC_Vertex  vec;
                vec.setPos (QVector3D(pPos->x,pPos->y,pPos->z));
                vec.setNormal (QVector3D(pNormal->x,pNormal->y,pNormal->z));
                vec.setUV (QVector2D(pTexCoord->x,pTexCoord->y));
            if(pTangent)
            {
                 vec.setTangent (QVector3D(pTangent->x,pTangent->y,pTangent->z));
            }
            mesh->pushVertex (vec);
            }

            for (unsigned int k = 0 ; k < the_mesh->mNumFaces ; k++) {
                const aiFace& Face = the_mesh->mFaces[k];
                assert(Face.mNumIndices == 3);
                mesh->pushIndex (Face.mIndices[0]);
                mesh->pushIndex(Face.mIndices[1]);
                mesh->pushIndex(Face.mIndices[2]);
            }
            //load bones
            loadBoneList(the_mesh,mesh);
            //mesh->finish();
        }
        loadNodeHeirarchy(nullptr,m_pScene->mRootNode);
        loadAnimations ();
        printf("extracting finish..\n");
        return true;
    }
}
Esempio n. 10
0
Drone::Drone(int x, int y) 
	 : Enemy(x, y)
{
	health = 30;
	loadAnimations();
}
Esempio n. 11
0
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
	: QMainWindow(parent, flags)
	, gameData(nullptr)
	, gameWorld(nullptr)
	, renderer(nullptr)
{
	setMinimumSize(640, 480);

	QMenuBar* mb = this->menuBar();
	QMenu* file = mb->addMenu("&File");

	file->addAction("Open &Game", this, SLOT(loadGame()));

	file->addSeparator();
	for(int i = 0; i < MaxRecentGames; ++i) {
		QAction* r = file->addAction("");
		recentGames.append(r);
		connect(r, SIGNAL(triggered()), SLOT(openRecent()));
	}

	recentSep = file->addSeparator();
	auto ex = file->addAction("E&xit");
	ex->setShortcut(QKeySequence::Quit);
	connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows()));

	//----------------------- View Mode setup
	viewerWidget = new ViewerWidget;
	viewerWidget->context()->makeCurrent();
	connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*)));

	//------------- Object Viewer
	m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
	m_viewNames[ViewMode::Object] = "Objects";

	//------------- Model Viewer
	m_views[ViewMode::Model]  = new ModelViewer(viewerWidget);
	m_viewNames[ViewMode::Model] = "Model";

	//------------- World Viewer
	m_views[ViewMode::World] = new WorldViewer(viewerWidget);
	m_viewNames[ViewMode::World] = "World";

	//------------- display mode switching
	viewSwitcher = new QStackedWidget;
	auto signalMapper = new QSignalMapper(this);
	auto switchPanel = new QVBoxLayout();
	int i = 0;
	for(auto viewer : m_views) {
		viewSwitcher->addWidget(viewer);
		connect(this, SIGNAL(loadedData(GameWorld*)), viewer, SLOT(showData(GameWorld*)));

		auto viewerButton = new QPushButton(m_viewNames[i].c_str());
		signalMapper->setMapping(m_views[i], i);
		signalMapper->setMapping(viewerButton, i);
		connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
		switchPanel->addWidget(viewerButton);
		i++;
	}
	// Map world viewer loading placements to switch to the world viewer
	connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)), signalMapper, SLOT(map()));

	switchView(ViewMode::Object);

	connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t)));
	connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
	connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model], SLOT(loadAnimations(QString)));

	connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
	connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int)));

	switchPanel->addStretch();
	auto mainlayout = new QHBoxLayout();
	mainlayout->addLayout(switchPanel);
	mainlayout->addWidget(viewSwitcher);
	auto mainwidget = new QWidget();
	mainwidget->setLayout(mainlayout);

	QMenu* data = mb->addMenu("&Data");
	//data->addAction("Export &Model", objectViewer, SLOT(exportModel()));

	QMenu* anim = mb->addMenu("&Animation");
	anim->addAction("Load &Animations", this, SLOT(openAnimations()));

	QMenu* map = mb->addMenu("&Map");
	map->addAction("Load IPL", m_views[ViewMode::World], SLOT(loadPlacements()));

	this->setCentralWidget(mainwidget);

	updateRecentGames();
}