示例#1
0
文件: monster.cpp 项目: q4a/scourge
void Monster::initCreatures( ConfigLang *config ) {
	char name[255], model_name[255], skin_name[255];
	char portrait[255], type[255], tmp[3000];
	char displayName[255];
	char combatMusic[255];

	vector<ConfigNode*> *v = config->getDocument()->
	                         getChildrenByName( "creature" );

	for ( unsigned int i = 0; i < v->size(); i++ ) {
		ConfigNode *node = ( *v )[i];

		config->setUpdate( _( UPDATE_MESSAGE ), i, v->size() );

		strcpy( name, node->getValueAsString( "name" ) );
		strcpy( displayName, node->getValueAsString( "display_name" ) );
		strcpy( portrait, node->getValueAsString( "portrait" ) );
		strcpy( type, node->getValueAsString( "type" ) );
		strcpy( model_name, node->getValueAsString( "model" ) );
		strcpy( skin_name, node->getValueAsString( "skin" ) );
		strcpy( combatMusic, node->getValueAsString( "combat_music" ) );
		if ( !strcmp( skin_name, "*" ) ) strcpy( skin_name, "" );
		int level = node->getValueAsInt( "level" );
		int hp = node->getValueAsInt( "hp" );
		int mp = node->getValueAsInt( "mp" );
		int armor = node->getValueAsInt( "armor" );
		int rareness = node->getValueAsInt( "rareness" );
		int speed = node->getValueAsInt( "speed" );
		float scale = node->getValueAsFloat( "scale" );
		bool npc = node->getValueAsBool( "npc" );
		bool harmless = node->getValueAsBool( "harmless" );
		bool special = node->getValueAsBool( "special" );
		GLuint statemod = node->getValueAsInt( "statemod" );

		Monster *m =
		  new Monster( name, displayName,
		               type,
		               level, hp, mp,
		               model_name, skin_name,
		               rareness, speed, armor,
		               scale, npc, portrait,
		               harmless );
		
		if( strlen( combatMusic ) ) {
			m->setCombatMusic( combatMusic );
		}
		
		if ( npc ) {
			npcs.push_back( m );
			m->setStartingStateMod( statemod );
		} else if ( harmless ) {
			harmlessCreatures.push_back( m );
		} else if ( special ) {
			// don't add to random monsters list
			// these are placed monsters like Mycotharsius.
		} else {
			vector<Monster*> *list = NULL;
			if ( monsters.find( level ) == monsters.end() ) {
				list = new vector<Monster*>();
				monsters[level] = list;
			} else {
				list = monsters[level];
			}
			list->push_back( m );
		}
		string s = name;
		for ( int i = 0; monstersByName.find( s ) != monstersByName.end(); ++i ) {
			cerr << "*** Monster::initCreatures() '" << s << "' occurs multiple times." << endl;
			stringstream numbered;
			numbered << name << " " << i+2;
			s = numbered.str();
		}
		monstersByName[s] = m;

		// store type and add sounds
		string typeStr = m->getModelName();
		bool found = false;
		for ( int i = 0; i < static_cast<int>( monsterTypes.size() ); i++ ) {
			if ( !strcmp( monsterTypes[i].c_str(), m->getModelName() ) ) {
				found = true;
				break;
			}
		}
		if ( !found ) {
			if ( !( npc || harmless ) ) monsterTypes.push_back( typeStr );

			if ( soundMap.find( typeStr ) == soundMap.end() ) {
				currentSoundMap = new map<int, vector<string>*>();
				soundMap[typeStr] = currentSoundMap;
			} else {
				currentSoundMap = soundMap[typeStr];
			}
			addMd2Sounds( m->getModelName(), currentSoundMap );
		}

		// backpack
		strcpy( tmp, node->getValueAsString( "inventory" ) );
		char *p = strtok( tmp, "," );
		while ( p ) {
			m->addItem( RpgItem::getItemByName( p ) );
			p = strtok( NULL, "," );
		}

		// spells
		strcpy( tmp, node->getValueAsString( "spells" ) );
		p = strtok( tmp, "," );
		while ( p ) {
			m->addSpell( Spell::getSpellByName( p ) );
			p = strtok( NULL, "," );
		}

		// skills
		vector<ConfigNode*> *vv = config->getDocument()->
		                          getChildrenByName( "skills" );
		if ( vv && !vv->empty() ) {
			ConfigNode *n = ( *vv )[0];
			set<string> names;
			n->getKeys( &names );
			for ( set<string>::iterator e = names.begin(); e != names.end(); ) {
				string skillStr = *e;
				int value = n->getValueAsInt( name );
				m->skills[ skillStr ] = value;
			}
		}
	}
}