std::string faction::describe() { std::string ret = name + " have the ultimate goal of " + facgoal_data[goal].name + ". Their primary concern is " + facjob_data[job1].name; if (job2 == FACJOB_NULL) ret += "."; else ret += ", but they are also involved in " + facjob_data[job2].name + "."; if (values != 0) { ret += " They are known for "; for (int i = 0; i < NUM_FACVALS; i++) { if (has_value(faction_value(i))) ret += facval_data[i].name + ", "; } } size_t pos = ret.find_last_of(","); if (pos != std::string::npos) { ret.replace(pos, 2, "."); pos = ret.find_last_of(","); if (pos != std::string::npos) ret.replace(pos, 2, ", and "); } return ret; }
std::string faction::describe() { std::string ret; ret = desc + "\n \n" + string_format( _("%s have the ultimate goal of %s."), name.c_str(), facgoal_data[goal].name.c_str()); if (job2 == FACJOB_NULL) { ret += string_format( _(" Their primary concern is %s."), facjob_data[job1].name.c_str()); } else { ret += string_format( _(" Their primary concern is %s, but they are also involved in %s."), facjob_data[job1].name.c_str(), facjob_data[job2].name.c_str()); } if (values != 0) { ret += _(" They are known for "); for (int i = 0; i < NUM_FACVALS; i++) { if (has_value(faction_value(i))) { ret += facval_data[i].name + _(", "); } } } size_t pos = ret.rfind(_(", ")); if (pos != std::string::npos) { ret.replace(pos, std::string(_(", ")).length(), _(".")); pos = ret.rfind(_(", ")); if (pos != std::string::npos) { ret.replace(pos, std::string(_(", ")).length(), _(", and ")); } } return ret; }
std::string faction::describe() const { std::string ret = _( desc.c_str() ); ret = ret + "\n\n" + string_format( _( "%1$s have the ultimate goal of %2$s." ), _( name.c_str() ), pgettext( "faction_goal", facgoal_data[goal].name.c_str() ) ); if( job2 == FACJOB_NULL ) { ret += string_format( _( " Their primary concern is %s." ), pgettext( "faction_job", facjob_data[job1].name.c_str() ) ); } else { ret += string_format( _( " Their primary concern is %1$s, but they are also involved in %2$s." ), pgettext( "faction_job", facjob_data[job1].name.c_str() ), pgettext( "faction_job", facjob_data[job2].name.c_str() ) ); } if( values == 0 ) { return ret; } std::vector<faction_value> vals; vals.reserve( NUM_FACVALS ); for( int i = 0; i < NUM_FACVALS; i++ ) { vals.push_back( faction_value( i ) ); } const std::string known_vals = enumerate_as_string( vals.begin(), vals.end(), [ this ]( const faction_value val ) { return has_value( val ) ? pgettext( "faction_value", facval_data[val].name.c_str() ) : ""; } ); if( !known_vals.empty() ) { ret += _( " They are known for " ) + known_vals + "."; } return ret; }
bool faction::matches_us(faction_value v) { int numvals = 2; if (job2 != FACJOB_NULL) { numvals++; } for (int i = 0; i < NUM_FACVALS; i++) { if (has_value(faction_value(i))) { numvals++; } } if (has_job(FACJOB_DRUGS) && v == FACVAL_STRAIGHTEDGE) { // Mutually exclusive return false; } int avggood = (good / numvals + good) / 2; int avgstrength = (strength / numvals + strength) / 2; int avgsneak = (sneak / numvals + sneak / 2); int avgcrime = (crime / numvals + crime / 2); int avgcult = (cult / numvals + cult / 2); /* debugmsg("AVG: GOO %d STR %d SNK %d CRM %d CLT %d\n\ VAL: GOO %d STR %d SNK %d CRM %d CLT %d (%s)", avggood, avgstrength, avgsneak, avgcrime, avgcult, facval_data[v].good, facval_data[v].strength, facval_data[v].sneak, facval_data[v].crime, facval_data[v].cult, facval_data[v].name.c_str()); */ if ((abs(facval_data[v].good - avggood) <= 3 || (avggood >= 5 && facval_data[v].good >= 1) || (avggood <= -5 && facval_data[v].good <= 0)) && (abs(facval_data[v].strength - avgstrength) <= 5 || (avgstrength >= 5 && facval_data[v].strength >= 3) || (avgstrength <= -5 && facval_data[v].strength <= -1)) && (abs(facval_data[v].sneak - avgsneak) <= 4 || (avgsneak >= 5 && facval_data[v].sneak >= 1) || (avgsneak <= -5 && facval_data[v].sneak <= -1)) && (abs(facval_data[v].crime - avgcrime) <= 4 || (avgcrime >= 5 && facval_data[v].crime >= 0) || (avgcrime <= -5 && facval_data[v].crime <= -1)) && (abs(facval_data[v].cult - avgcult) <= 3 || (avgcult >= 5 && facval_data[v].cult >= 1) || (avgcult <= -5 && facval_data[v].cult <= -1))) { return true; } return false; }
void faction::randomize() { // Set up values // TODO: Not always in overmap 0,0 omx = 0; omy = 0; mapx = rng(OMAPX / 10, OMAPX - OMAPX / 10); mapy = rng(OMAPY / 10, OMAPY - OMAPY / 10); // Pick an overall goal. goal = faction_goal(rng(1, NUM_FACGOALS - 1)); if (one_in(4)) goal = FACGOAL_NONE; // Slightly more likely to not have a real goal good = facgoal_data[goal].good; strength = facgoal_data[goal].strength; sneak = facgoal_data[goal].sneak; crime = facgoal_data[goal].crime; cult = facgoal_data[goal].cult; job1 = faction_job(rng(1, NUM_FACJOBS - 1)); do job2 = faction_job(rng(0, NUM_FACJOBS - 1)); while (job2 == job1); good += facjob_data[job1].good + facjob_data[job2].good; strength += facjob_data[job1].strength + facjob_data[job2].strength; sneak += facjob_data[job1].sneak + facjob_data[job2].sneak; crime += facjob_data[job1].crime + facjob_data[job2].crime; cult += facjob_data[job1].cult + facjob_data[job2].cult; int num_values = 0; int tries = 0; values = 0; do { int v = rng(1, NUM_FACVALS - 1); if (!has_value(faction_value(v)) && matches_us(faction_value(v))) { values |= mfb(v); tries = 0; num_values++; good += facval_data[v].good; strength += facval_data[v].strength; sneak += facval_data[v].sneak; crime += facval_data[v].crime; cult += facval_data[v].cult; } else tries++; } while((one_in(num_values) || one_in(num_values)) && tries < 15); std::string noun; int sel = 1, best = strength; if (sneak > best) { sel = 2; best = sneak; } if (crime > best) { sel = 3; best = crime; } if (cult > best) sel = 4; if (strength <= 0 && sneak <= 0 && crime <= 0 && cult <= 0) sel = 0; switch (sel) { case 1: noun = faction_noun_strong[rng(0, 14)]; power = dice(5, 20); size = dice(5, 6); break; case 2: noun = faction_noun_sneak [rng(0, 14)]; power = dice(5, 8); size = dice(5, 8); break; case 3: noun = faction_noun_crime [rng(0, 14)]; power = dice(5, 16); size = dice(5, 8); break; case 4: noun = faction_noun_cult [rng(0, 14)]; power = dice(8, 8); size = dice(4, 6); break; default: noun = faction_noun_none [rng(0, 14)]; power = dice(6, 8); size = dice(6, 6); } if (one_in(4)) { do name = "The " + noun + " of " + invent_name(); while (name.length() > MAX_FAC_NAME_SIZE); } else if (one_in(2)) { do name = "The " + invent_adj() + " " + noun; while (name.length() > MAX_FAC_NAME_SIZE); } else { do { std::string adj; if (good >= 3) adj = faction_adj_pos[rng(0, 14)]; else if (good <= -3) adj = faction_adj_bad[rng(0, 14)]; else adj = faction_adj_neu[rng(0, 14)]; name = "The " + adj + " " + noun; if (one_in(4)) name += " of " + invent_name(); } while (name.length() > MAX_FAC_NAME_SIZE); } }
void faction::randomize() { // Set up values // TODO: Not always in overmap 0,0 mapx = rng( OMAPX / 10, OMAPX - OMAPX / 10 ); mapy = rng( OMAPY / 10, OMAPY - OMAPY / 10 ); // Pick an overall goal. goal = faction_goal( rng( 1, NUM_FACGOALS - 1 ) ); if( one_in( 4 ) ) { goal = FACGOAL_NONE; // Slightly more likely to not have a real goal } good = facgoal_data[goal].good; strength = facgoal_data[goal].strength; sneak = facgoal_data[goal].sneak; crime = facgoal_data[goal].crime; cult = facgoal_data[goal].cult; job1 = faction_job( rng( 1, NUM_FACJOBS - 1 ) ); do { job2 = faction_job( rng( 0, NUM_FACJOBS - 1 ) ); } while( job2 == job1 ); good += facjob_data[job1].good + facjob_data[job2].good; strength += facjob_data[job1].strength + facjob_data[job2].strength; sneak += facjob_data[job1].sneak + facjob_data[job2].sneak; crime += facjob_data[job1].crime + facjob_data[job2].crime; cult += facjob_data[job1].cult + facjob_data[job2].cult; int num_values = 0; int tries = 0; values = 0; do { int v = rng( 1, NUM_FACVALS - 1 ); if( !has_value( faction_value( v ) ) && matches_us( faction_value( v ) ) ) { values |= mfb( v ); tries = 0; num_values++; good += facval_data[v].good; strength += facval_data[v].strength; sneak += facval_data[v].sneak; crime += facval_data[v].crime; cult += facval_data[v].cult; } else { tries++; } } while( ( one_in( num_values ) || one_in( num_values ) ) && tries < 15 ); std::string noun; int sel = 1; int best = strength; if( sneak > best ) { sel = 2; best = sneak; } if( crime > best ) { sel = 3; best = crime; } if( cult > best ) { sel = 4; } if( strength <= 0 && sneak <= 0 && crime <= 0 && cult <= 0 ) { sel = 0; } switch( sel ) { case 1: noun = pgettext( "faction_adj", random_entry_ref( faction_noun_strong ).c_str() ); power = dice( 5, 20 ); size = dice( 5, 6 ); break; case 2: noun = pgettext( "faction_adj", random_entry_ref( faction_noun_sneak ).c_str() ); power = dice( 5, 8 ); size = dice( 5, 8 ); break; case 3: noun = pgettext( "faction_adj", random_entry_ref( faction_noun_crime ).c_str() ); power = dice( 5, 16 ); size = dice( 5, 8 ); break; case 4: noun = pgettext( "faction_adj", random_entry_ref( faction_noun_cult ).c_str() ); power = dice( 8, 8 ); size = dice( 4, 6 ); break; default: noun = pgettext( "faction_adj", random_entry_ref( faction_noun_none ).c_str() ); power = dice( 6, 8 ); size = dice( 6, 6 ); } if( one_in( 4 ) ) { do { name = string_format( _( "The %1$s of %2$s" ), noun.c_str(), invent_name().c_str() ); } while( utf8_width( name ) > MAX_FAC_NAME_SIZE ); } else if( one_in( 2 ) ) { do { name = string_format( _( "The %1$s %2$s" ), invent_adj().c_str(), noun.c_str() ); } while( utf8_width( name ) > MAX_FAC_NAME_SIZE ); } else { do { std::string adj; if( good >= 3 ) { adj = _( random_entry_ref( faction_adj_pos ).c_str() ); } else if( good <= -3 ) { adj = _( random_entry_ref( faction_adj_bad ).c_str() ); } else { adj = _( random_entry_ref( faction_adj_neu ).c_str() ); } name = string_format( _( "The %1$s %2$s" ), adj.c_str(), noun.c_str() ); if( one_in( 4 ) ) { name = string_format( _( "%1$s of %2$s" ), name.c_str(), invent_name().c_str() ); } } while( utf8_width( name ) > MAX_FAC_NAME_SIZE ); } }