示例#1
0
int do_climb(string arg)
{
    object me;

    me=this_player();

    if( !arg || (arg != "up" && arg != "down" && arg != "left" && arg != "right") )
    {
        return notify_fail("你要爬到哪里去?\n");
    }

    if( arg == "up" )
    {
        message_vision("$N手足并用,小心翼翼地往"+direction_name(arg)+"爬了过去。\n", me);
        me->move(__DIR__"binggukou");
    }
    else if( arg == "down" )
    {
        message_vision("$N手足并用,小心翼翼地往"+direction_name(arg)+"爬了过去。\n", me);
        me->move(__DIR__"bingya-up6");
    }
    else return notify_fail( "往"+direction_name(arg)+"已经没有着手之点了。\n" );

    message_vision("$N从"+direction_rev(arg)+"面爬了过来,长长地舒了口气。\n", me);
    return 1;
}
示例#2
0
std::string overmapbuffer::get_description_at( const tripoint &where )
{
    const std::string ter_name = ter( sm_to_omt_copy( where ) )->get_name();

    if( where.z != 0 ) {
        return ter_name;
    }

    const auto closest_cref = closest_known_city( where );

    if( !closest_cref ) {
        return ter_name;
    }

    const auto &closest_city = *closest_cref.city;
    const direction dir = direction_from( closest_cref.abs_sm_pos, where );
    const std::string dir_name = direction_name( dir );

    const int sm_size = omt_to_sm_copy( closest_cref.city->size );
    const int sm_dist = closest_cref.distance;

    if( sm_dist <= 3 * sm_size / 4 ) {
        if( sm_size >= 16 ) {
            // The city is big enough to be split in districts.
            if( sm_dist <= sm_size / 4 ) {
                //~ First parameter is a terrain name, second parameter is a city name.
                return string_format( _( "%1$s in central %2$s" ), ter_name.c_str(), closest_city.name.c_str() );
            } else {
                //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name.
                return string_format( _( "%1$s in %2$s %3$s" ), ter_name.c_str(), dir_name.c_str(),
                                      closest_city.name.c_str() );
            }
        } else {
            //~ First parameter is a terrain name, second parameter is a city name.
            return string_format( _( "%1$s in %2$s" ), ter_name.c_str(), closest_city.name.c_str() );
        }
    } else if( sm_dist <= sm_size ) {
        if( sm_size >= 8 ) {
            // The city is big enough to have outskirts.
            //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name.
            return string_format( _( "%1$s on the %2$s outskirts of %3$s" ), ter_name.c_str(), dir_name.c_str(),
                                  closest_city.name.c_str() );
        } else {
            //~ First parameter is a terrain name, second parameter is a city name.
            return string_format( _( "%1$s in %2$s" ), ter_name.c_str(), closest_city.name.c_str() );
        }
    }

    //~ First parameter is a terrain name, second parameter is a direction, and third parameter is a city name.
    return string_format( _( "%1$s %2$s from %3$s" ), ter_name.c_str(), dir_name.c_str(),
                          closest_city.name.c_str() );
}
示例#3
0
static void
dump_lines (PangoLayout *layout, GString *string)
{
  PangoLayoutIter *iter;
  const gchar *text;
  gint index, index2;
  gboolean has_more;
  gchar *char_str;
  gint i;
  PangoLayoutLine *line;

  text = pango_layout_get_text (layout);
  iter = pango_layout_get_iter (layout);

  has_more = TRUE;
  index = pango_layout_iter_get_index (iter);
  i = 0;
  while (has_more)
    {
      line = pango_layout_iter_get_line (iter);
      has_more = pango_layout_iter_next_line (iter);
      i++;

      if (has_more)
        {
          index2 = pango_layout_iter_get_index (iter);
          char_str = g_strndup (text + index, index2 - index);          
        }
      else
        {
          char_str = g_strdup (text + index);
        }

      g_string_append_printf (string, "i=%d, index=%d, paragraph-start=%d, dir=%s '%s'\n",
                              i, index, line->is_paragraph_start, direction_name (line->resolved_dir), 
                              char_str);
      g_free (char_str);

      index = index2;
    }
  pango_layout_iter_free (iter);
}
示例#4
0
void sounds::process_sound_markers( player *p )
{
    bool is_deaf = p->is_deaf();
    const float volume_multiplier = p->hearing_ability();
    const int safe_volume = p->worn_with_flag("PARTIAL_DEAF") ? 100 : 9999;
    const int weather_vol = weather_data( g->weather ).sound_attn;
    for( const auto &sound_event_pair : sounds_since_last_turn ) {
        const int volume = std::min(safe_volume, (int)(sound_event_pair.second.volume * volume_multiplier));
        const std::string& sfx_id = sound_event_pair.second.id;
        const std::string& sfx_variant = sound_event_pair.second.variant;
        const int max_volume = std::max( volume, sound_event_pair.second.volume );  // For deafness checks
        int dist = rl_dist( p->pos(), sound_event_pair.first );
        bool ambient = sound_event_pair.second.ambient;
        // Too far away, we didn't hear it!
        if( dist > volume ) {
            continue;
        }
        if( is_deaf ) {
            // Has to be here as well to work for stacking deafness (loud noises prolong deafness)
            if( !p->is_immune_effect( effect_deaf )
                    && rng( ( max_volume - dist ) / 2, ( max_volume - dist ) ) >= 150 ) {
                // Prolong deafness, but not as much as if it was freshly applied
                int duration = std::min( 40, ( max_volume - dist - 130 ) / 8 );
                p->add_effect( effect_deaf, duration );
                if( !p->has_trait( "DEADENED" ) ) {
                    p->add_msg_if_player( m_bad, _( "Your eardrums suddenly ache!" ) );
                    if( p->get_pain() < 10 ) {
                        p->mod_pain( rng( 0, 2 ) );
                    }
                }
            }
            // We're deaf, skip rest of processing.
            continue;
        }
        // Player volume meter includes all sounds from their tile and adjacent tiles
        // TODO: Add noises from vehicle player is in.
        if( dist <= 1 ) {
            p->volume = std::max( p->volume, volume );
        }
        // Check for deafness
        if( !p->is_immune_effect( effect_deaf ) && rng((max_volume - dist) / 2, (max_volume - dist)) >= 150 ) {
            int duration = (max_volume - dist - 130) / 4;
            p->add_effect( effect_deaf, duration );
            if( p->is_deaf() ) {
                // Need to check for actual deafness
                is_deaf = true;
                sfx::do_hearing_loss( duration );
                continue;
            }
        }
        // At this point we are dealing with attention (as opposed to physical effects)
        // so reduce volume by the amount of ambient noise from the weather.
        const int mod_vol = ( sound_event_pair.second.volume - weather_vol ) * volume_multiplier;
        // The noise was drowned out by the surroundings.
        if( mod_vol - dist < 0 ) {
            continue;
        }
        // See if we need to wake someone up
        if( p->has_effect( effect_sleep ) ) {
            if( ( !( p->has_trait( "HEAVYSLEEPER" ) ||
                     p->has_trait( "HEAVYSLEEPER2" ) ) && dice( 2, 15 ) < mod_vol - dist ) ||
                    ( p->has_trait( "HEAVYSLEEPER" ) && dice( 3, 15 ) < mod_vol - dist ) ||
                    ( p->has_trait( "HEAVYSLEEPER2" ) && dice( 6, 15 ) < mod_vol - dist ) ) {
                //Not kidding about sleep-thru-firefight
                p->wake_up();
                add_msg( m_warning, _( "Something is making noise." ) );
            } else {
                continue;
            }
        }
        const tripoint &pos = sound_event_pair.first;
        const std::string &description = sound_event_pair.second.description;
        if( !ambient && ( pos != p->pos() ) && !g->m.pl_sees( pos, dist ) ) {
            if( p->activity.ignore_trivial != true ) {
                std::string query;
                if( description.empty() ) {
                    query = _( "Heard a noise!" );
                } else {
                    query = string_format( _( "Heard %s!" ),
                                           sound_event_pair.second.description.c_str() );
                }
                if( g->cancel_activity_or_ignore_query( query.c_str() ) ) {
                    p->activity.ignore_trivial = true;
                    for( auto activity : p->backlog ) {
                        activity.ignore_trivial = true;
                    }
                }
            }
        }
        // Only print a description if it exists
        if( !description.empty() ) {
            // If it came from us, don't print a direction
            if( pos == p->pos() ) {
                add_msg( _( "You hear %s" ), description.c_str() );
            } else {
                // Else print a direction as well
                std::string direction = direction_name( direction_from( p->pos(), pos ) );
                add_msg( m_warning, _( "From the %s you hear %s" ), direction.c_str(), description.c_str() );
            }
        }
        // Play the sound effect, if any.
        if( !sfx_id.empty() ) {
            // for our sfx API, 100 is "normal" volume, so scale accordingly
            int heard_volume = sfx::get_heard_volume( pos );
            sfx::play_variant_sound( sfx_id, sfx_variant, heard_volume );
            //add_msg("Playing sound effect %s, %s, %d", sfx_id.c_str(), sfx_variant.c_str(), heard_volume);
        }
        // If Z coord is different, draw even when you can see the source
        const bool diff_z = pos.z != p->posz();
        // Place footstep markers.
        if( pos == p->pos() || p->sees( pos ) ) {
            // If we are or can see the source, don't draw a marker.
            continue;
        }
        int err_offset;
        if( mod_vol / dist < 2 ) {
            err_offset = 3;
        } else if( mod_vol / dist < 3 ) {
            err_offset = 2;
        } else {
            err_offset = 1;
        }
        // Enumerate the valid points the player *cannot* see.
        // Unless the source is on a different z-level, then any point is fine
        std::vector<tripoint> unseen_points;
        tripoint newp = pos;
        int &newx = newp.x;
        int &newy = newp.y;
        for( newx = pos.x - err_offset; newx <= pos.x + err_offset; newx++ ) {
            for( newy = pos.y - err_offset; newy <= pos.y + err_offset; newy++ ) {
                if( diff_z || !p->sees( newp ) ) {
                    unseen_points.emplace_back( newp );
                }
            }
        }
        // Then place the sound marker in a random one.
        if( !unseen_points.empty() ) {
            sound_markers.emplace( random_entry( unseen_points ),
                                   sound_event_pair.second );
        }
    }
    sounds_since_last_turn.clear();
}
void
treasure_map_generate(struct treasure_map *treasure_map, struct rnd *rnd)
{
    enum treasure_map_type treasure_map_type;
    int score = roll("1d100", rnd);
    if (score <= 5) {
        treasure_map_type = treasure_map_type_false_map;
        treasure_map->is_false = true;
        /* TODO: generate description of false treasure */
    } else if (score <= 70) {
        treasure_map_type = treasure_map_type_map_to_monetary_treasure;
        generate_monetary_treasure(&treasure_map->treasure, rnd);
    } else if (score <= 90) {
        treasure_map_type = treasure_map_type_map_to_magic_treasure;
        generate_magic_treasure(&treasure_map->treasure, rnd);
    } else {
        treasure_map_type = treasure_map_type_map_to_combined_hoard;
        generate_combined_hoard(&treasure_map->treasure, rnd);
    }
    
    int miles;
    score = roll("1d100", rnd);
    if (score <= 20) {
        miles = 0;
    } else if (score <= 60) {
        miles = roll("1d4", rnd) + 4;
    } else if (score <= 90) {
        miles = roll("1d4", rnd) * 10;
    } else {
        miles = roll("1d10", rnd) * 50;
    }
    
    enum direction direction = direction_random(rnd);
    if (miles) {
        char const *disposition;
        score = roll("1d100", rnd);
        if (score <= 10) {
            disposition = "buried and unguarded";
        } else if (score <= 20) {
            disposition = "hidden in water";
        } else if (score <= 70) {
            disposition = "guarded in a lair";
        } else if (score <= 80) {
            disposition = "somewhere in a ruins";
        } else if (score <= 90) {
            disposition = "in a burial crypt";
        } else {
            disposition = "secreted in a town";
        }
        
        char *description = treasure_alloc_description(&treasure_map->treasure);
        treasure_map->true_description = str_alloc_formatted("%smap to %s of %s %i miles to the %s, %s",
                                                             (treasure_map->is_false ? "false " : ""),
                                                             treasure_map_types[treasure_map_type],
                                                             description,
                                                             miles,
                                                             direction_name(direction),
                                                             disposition);
        free_or_die(description);
    } else {
        char *description = treasure_alloc_description(&treasure_map->treasure);
        treasure_map->true_description = str_alloc_formatted("%smap to %s of %s in nearby labyrinth to the %s",
                                                             (treasure_map->is_false ? "false " : ""),
                                                             treasure_map_types[treasure_map_type],
                                                             description,
                                                             direction_name(direction));
        free_or_die(description);
    }
}