Пример #1
0
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);
 }
}
Пример #2
0
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 );
    }
}