void MagicSchool::initMagic() { ConfigLang *config = ConfigLang::load( "config/spell.cfg" ); vector<ConfigNode*> *v = config->getDocument()-> getChildrenByName( "magic_school" ); MagicSchool *current = NULL; Spell *currentSpell = NULL; char name[255], displayName[255], notes[255], dice[255]; char line[2000], symbol[255], targetTypeStr[255], align[255] /*, prereqName[255]*/; float alignment; 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( notes, node->getValueAsString( "deity" ) ); int skill = Skill::getSkillIndexByName( node->getValueAsString( "skill" ) ); int resistSkill = Skill::getSkillIndexByName( node->getValueAsString( "resist_skill" ) ); strcpy( line, node->getValueAsString( "rgb" ) ); strcpy( align, node->getValueAsString( "base_alignment" ) ); if ( strcmp( align, "chaotic" ) == 0 ) { alignment = ALIGNMENT_CHAOTIC; } else if ( strcmp( align, "neutral" ) == 0 ) { alignment = ALIGNMENT_NEUTRAL; } else if ( strcmp( align, "lawful" ) == 0 ) { alignment = ALIGNMENT_LAWFUL; } float red = static_cast<float>( strtod( strtok( line, "," ), NULL ) ); float green = static_cast<float>( strtod( strtok( NULL, "," ), NULL ) ); float blue = static_cast<float>( strtod( strtok( NULL, "," ), NULL ) ); strcpy( symbol, node->getValueAsString( "symbol" ) ); current = new MagicSchool( name, displayName, notes, skill, resistSkill, alignment, red, green, blue, symbol ); strcpy( line, node->getValueAsString( "deity_description" ) ); if ( strlen( line ) ) current->addToDeityDescription( line ); schools[schoolCount++] = current; string nameStr = name; schoolMap[nameStr] = current; vector<ConfigNode*> *vv = node->getChildrenByName( "low_donate" ); for ( unsigned int i = 0; vv && i < vv->size(); i++ ) { ConfigNode *node2 = ( *vv )[i]; current->lowDonate.push_back( node2->getValueAsString( "text" ) ); } vv = node->getChildrenByName( "neutral_donate" ); for ( unsigned int i = 0; vv && i < vv->size(); i++ ) { ConfigNode *node2 = ( *vv )[i]; current->neutralDonate.push_back( node2->getValueAsString( "text" ) ); } vv = node->getChildrenByName( "high_donate" ); for ( unsigned int i = 0; vv && i < vv->size(); i++ ) { ConfigNode *node2 = ( *vv )[i]; current->highDonate.push_back( node2->getValueAsString( "text" ) ); } vv = node->getChildrenByName( "spell" ); for ( unsigned int i = 0; vv && i < vv->size(); i++ ) { ConfigNode *node2 = ( *vv )[i]; strcpy( name, node2->getValueAsString( "name" ) ); strcpy( displayName, node2->getValueAsString( "display_name" ) ); strcpy( symbol, node2->getValueAsString( "symbol" ) ); int level = node2->getValueAsInt( "level" ); int mp = node2->getValueAsInt( "mp" ); int exp = node2->getValueAsInt( "mp" ); int failureRate = node2->getValueAsInt( "failureRate" ); strcpy( dice, node2->getValueAsString( "action" ) ); int distance = node2->getValueAsInt( "distance" ); if ( distance < static_cast<int>( MIN_DISTANCE ) ) distance = static_cast<int>( MIN_DISTANCE ); int targetType = ( !strcmp( node2->getValueAsString( "targetType" ), "single" ) ? SINGLE_TARGET : GROUP_TARGET ); int speed = node2->getValueAsInt( "speed" ); int effect = Constants::getEffectByName( node2->getValueAsString( "effect" ) ); strcpy( targetTypeStr, node2->getValueAsString( "target" ) ); bool creatureTarget = ( strchr( targetTypeStr, 'C' ) != NULL ); bool locationTarget = ( strchr( targetTypeStr, 'L' ) != NULL ); bool itemTarget = ( strchr( targetTypeStr, 'I' ) != NULL ); bool partyTarget = ( strchr( targetTypeStr, 'P' ) != NULL ); bool doorTarget = ( strchr( targetTypeStr, 'D' ) != NULL ); strcpy( line, node2->getValueAsString( "icon" ) ); int iconTileX = atoi( strtok( line, "," ) ) - 1; int iconTileY = atoi( strtok( NULL, "," ) ) - 1; // Friendly/Hostile marker bool friendly = node2->getValueAsBool( "friendly" ); int stateModPrereq = -1; strcpy( line, node2->getValueAsString( "prerequisite" ) ); if ( strlen( line ) ) { // is it a potion state mod? int n = Constants::getPotionSkillByName( line ); if ( n == -1 ) { StateMod *mod = StateMod::getStateModByName( line ); if ( !mod ) { cerr << "Can't find state mod: >" << line << "<" << endl; exit( 1 ); } n = mod->getIndex(); } stateModPrereq = n; if ( stateModPrereq == -1 ) { cerr << "Error: spell=" << name << endl; cerr << "\tCan't understand prereq for spell: " << line << endl; } } currentSpell = new Spell( name, displayName, symbol, level, mp, exp, failureRate, dice, distance, targetType, speed, effect, creatureTarget, locationTarget, itemTarget, partyTarget, doorTarget, current, iconTileX, iconTileY, friendly, stateModPrereq ); current->addSpell( currentSpell ); strcpy( line, node2->getValueAsString( "sound" ) ); if ( strlen( line ) ) currentSpell->setSound( line ); strcpy( line, node2->getValueAsString( "notes" ) ); if ( strlen( notes ) ) currentSpell->addNotes( line ); } } delete config; }