コード例 #1
0
ファイル: Map.cpp プロジェクト: aceofspades/flare-engine
int Map::load(std::string fname) {
	FileParser infile;
	maprow *cur_layer = NULL;

	clearEvents();
	clearLayers();
	clearQueues();

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemies.push(Map_Enemy());
			else if (infile.section == "enemygroup")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile, &cur_layer);
		else if (infile.section == "enemy")
			loadEnemy(infile);
		else if (infile.section == "enemygroup")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	return 0;
}
コード例 #2
0
int Map::load(const std::string& fname) {
	FileParser infile;

	clearEvents();
	clearLayers();
	clearQueues();

	music_filename = "";

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile);
		else if (infile.section == "enemy")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	// create a temporary EffectDef for immunity; will be used for map StatBlocks
	EffectDef immunity_effect;
	immunity_effect.id = "MAP_EVENT_IMMUNITY";
	immunity_effect.type = "immunity";

	// create StatBlocks for events that need powers
	for (unsigned i=0; i<events.size(); ++i) {
		Event_Component *ec_power = events[i].getComponent(EC_POWER);
		if (ec_power) {
			statblocks.push_back(StatBlock());
			StatBlock *statb = &statblocks.back();

			if (!statb) {
				logError("Map: Could not create StatBlock for Event.");
				continue;
			}

			// store the index of this StatBlock so that we can find it when the event is activated
			ec_power->y = static_cast<int>(statblocks.size())-1;

			statb->starting[STAT_ACCURACY] = 1000; // always hit the target

			Event_Component *ec_path = events[i].getComponent(EC_POWER_PATH);
			if (ec_path) {
				// source is power path start
				statb->pos.x = static_cast<float>(ec_path->x) + 0.5f;
				statb->pos.y = static_cast<float>(ec_path->y) + 0.5f;
			}
			else {
				// source is event location
				statb->pos.x = static_cast<float>(events[i].location.x) + 0.5f;
				statb->pos.y = static_cast<float>(events[i].location.y) + 0.5f;
			}

			Event_Component *ec_damage = events[i].getComponent(EC_POWER_DAMAGE);
			if (ec_damage) {
				statb->starting[STAT_DMG_MELEE_MIN] = statb->starting[STAT_DMG_RANGED_MIN] = statb->starting[STAT_DMG_MENT_MIN] = ec_damage->a;
				statb->starting[STAT_DMG_MELEE_MAX] = statb->starting[STAT_DMG_RANGED_MAX] = statb->starting[STAT_DMG_MENT_MAX] = ec_damage->b;
			}

			// this is used to store cooldown ticks for a map power
			// the power id, type, etc are not used
			statb->powers_ai.resize(1);

			// make this StatBlock immune to negative status effects
			// this is mostly to prevent a player with a damage return bonus from damaging this StatBlock
			statb->effects.addEffect(immunity_effect, 0, 0, false, -1, 0, SOURCE_TYPE_ENEMY);
		}
	}

	// ensure that our map contains a collison layer
	if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) {
		layernames.push_back("collision");
		layers.resize(layers.size()+1);
		layers.back().resize(w);
		for (size_t i=0; i<layers.back().size(); ++i) {
			layers.back()[i].resize(h, 0);
		}
		collision_layer = static_cast<int>(layers.size())-1;
	}

	return 0;
}
コード例 #3
0
ファイル: Map.cpp プロジェクト: hansjoachim/flare-engine
int Map::load(const std::string& fname) {
	FileParser infile;

	clearEvents();
	clearLayers();
	clearQueues();

	music_filename = "";

	collision_layer = -1;
	w = 1;
	h = 1;
	hero_pos_enabled = false;
	hero_pos.x = 0;
	hero_pos.y = 0;

	// @CLASS Map|Description of maps/
	if (!infile.open(fname))
		return 0;

	logInfo("Map: Loading map '%s'", fname.c_str());

	this->filename = fname;

	while (infile.next()) {
		if (infile.new_section) {

			// for sections that are stored in collections, add a new object here
			if (infile.section == "enemy")
				enemy_groups.push(Map_Group());
			else if (infile.section == "npc")
				npcs.push(Map_NPC());
			else if (infile.section == "event")
				events.push_back(Event());

		}
		if (infile.section == "header")
			loadHeader(infile);
		else if (infile.section == "layer")
			loadLayer(infile);
		else if (infile.section == "enemy")
			loadEnemyGroup(infile, &enemy_groups.back());
		else if (infile.section == "npc")
			loadNPC(infile);
		else if (infile.section == "event")
			EventManager::loadEvent(infile, &events.back());
	}

	infile.close();

	// create StatBlocks for events that need powers
	for (unsigned i=0; i<events.size(); ++i) {
		Event_Component *ec_power = events[i].getComponent(EC_POWER);
		if (ec_power) {
			// store the index of this StatBlock so that we can find it when the event is activated
			ec_power->y = addEventStatBlock(events[i]);
		}
	}

	// ensure that our map contains a collision layer
	if (std::find(layernames.begin(), layernames.end(), "collision") == layernames.end()) {
		layernames.push_back("collision");
		layers.resize(layers.size()+1);
		layers.back().resize(w);
		for (size_t i=0; i<layers.back().size(); ++i) {
			layers.back()[i].resize(h, 0);
		}
		collision_layer = static_cast<int>(layers.size())-1;
	}

	if (!hero_pos_enabled) {
		logError("Map: Hero spawn position (hero_pos) not defined in map header. Defaulting to (0,0).");
	}

	return 0;
}