Skip to content

Commit

Permalink
Selected astylings.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingranade committed Nov 10, 2015
1 parent 2a3ffb0 commit b6284a4
Show file tree
Hide file tree
Showing 71 changed files with 645 additions and 641 deletions.
12 changes: 6 additions & 6 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,25 +541,25 @@ action_id handle_action_menu()
std::map<action_id, int> action_weightings;

// Check if we're in a potential combat situation, if so, sort a few actions to the top.
if(!g->u.get_hostile_creatures().empty()) {
if( !g->u.get_hostile_creatures().empty() ) {
// Only prioritize movement options if we're not driving.
if(!g->u.controlling_vehicle) {
if( !g->u.controlling_vehicle ) {
action_weightings[ACTION_TOGGLE_MOVE] = 400;
}
// Only prioritize fire weapon options if we're wielding a ranged weapon.
if(g->u.weapon.is_gun() || g->u.weapon.has_flag( "REACH_ATTACK" ) ) {
if( g->u.weapon.is_gun() || g->u.weapon.has_flag( "REACH_ATTACK" ) ) {
action_weightings[ACTION_FIRE] = 350;
}
}

// If we're already running, make it simple to toggle running to off.
if(g->u.move_mode != "walk") {
if( g->u.move_mode != "walk" ) {
action_weightings[ACTION_TOGGLE_MOVE] = 300;
}

// If our wielded item is a gun, doesn't have full ammo, and we do have the ammo,
// prioritize reloading.
if(g->u.can_reload()) {
if( g->u.can_reload() ) {
action_weightings[ACTION_RELOAD] = 250;
}

Expand Down Expand Up @@ -818,7 +818,7 @@ bool choose_direction( const std::string &message, tripoint &offset, bool allow_

//~ appended to "Close where?" "Pry where?" etc.
const std::string query_text = message + _( " (Direction button)" );
popup(query_text, PF_NO_WAIT_ON_TOP);
popup( query_text, PF_NO_WAIT_ON_TOP );

const std::string action = ctxt.handle_input();
if( input_context::get_direction( offset.x, offset.y, action ) ) {
Expand Down
35 changes: 19 additions & 16 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,37 @@ enum action_id : int {
};

// Load keybindings from disk
void load_keyboard_settings(std::map<char, action_id> &keymap, std::string &keymap_file_loaded_from,
std::set<action_id> &unbound_keymap);
void load_keyboard_settings( std::map<char, action_id> &keymap,
std::string &keymap_file_loaded_from,
std::set<action_id> &unbound_keymap );
std::string default_keymap_txt();
// All keys bound to act
std::vector<char> keys_bound_to(action_id act);
action_id look_up_action(std::string ident);
std::string action_ident(action_id);
std::vector<char> keys_bound_to( action_id act );
action_id look_up_action( std::string ident );
std::string action_ident( action_id );
// Lookup key in keymap, return the mapped action or ACTION_NULL
action_id action_from_key(char ch);
action_id action_from_key( char ch );
// Use the keymap to figure out direction properly
void get_direction(int &x, int &y, char ch);
void get_direction( int &x, int &y, char ch );
// Get input from the player to choose an adjacent tile (for examine() etc)
bool choose_adjacent( std::string message, int &x, int &y );
bool choose_adjacent( std::string message, tripoint &p, bool allow_vertical = false );
// Input from player for a direction, not related to the player position
bool choose_direction(const std::string &message, int &x, int &y);
bool choose_adjacent_highlight(std::string message, int &x, int &y, action_id action_to_highlight);
bool choose_direction( const std::string &message, int &x, int &y );
bool choose_adjacent_highlight( std::string message, int &x, int &y,
action_id action_to_highlight );
bool choose_direction( const std::string &message, tripoint &offset, bool allow_vertical = false );
bool choose_adjacent_highlight( std::string message, tripoint &offset, action_id action_to_highlight );
bool choose_adjacent_highlight( std::string message, tripoint &offset,
action_id action_to_highlight );

// (Press X (or Y)|Try) to Z
std::string press_x(action_id act);
std::string press_x(action_id act, std::string key_bound,
std::string key_unbound);
std::string press_x(action_id act, std::string key_bound_pre,
std::string key_bound_suf, std::string key_unbound);
std::string press_x( action_id act );
std::string press_x( action_id act, std::string key_bound,
std::string key_unbound );
std::string press_x( action_id act, std::string key_bound_pre,
std::string key_bound_suf, std::string key_unbound );
// ('Z'ing|zing) (X( or Y)))
std::string press_x(action_id act, std::string act_desc);
std::string press_x( action_id act, std::string act_desc );

// Helper function to convert co-ordinate delta to a movement direction
action_id get_movement_direction_from_delta( const int dx, const int dy, const int dz = 0 );
Expand Down
5 changes: 3 additions & 2 deletions src/active_item_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

void active_item_cache::remove( std::list<item>::iterator it, point location )
{
active_items[it->processing_speed()].remove_if( [&] (const item_reference &active_item) {
return location == active_item.location && active_item.item_iterator == it; } );
active_items[it->processing_speed()].remove_if( [&]( const item_reference & active_item ) {
return location == active_item.location && active_item.item_iterator == it;
} );
active_item_set.erase( &*it );
}

Expand Down
27 changes: 13 additions & 14 deletions src/active_item_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#include <unordered_set>

// A struct used to uniquely identify an item within a submap or vehicle.
struct item_reference
{
struct item_reference {
point location;
std::list<item>::iterator item_iterator;
// Do not access this from outside this module, it is only used as an ID for active_item_set.
Expand All @@ -18,19 +17,19 @@ struct item_reference

class active_item_cache
{
private:
std::unordered_map<int, std::list<item_reference>> active_items;
// Cache for fast lookup when we're iterating over the active items to verify the item is present.
std::unordered_set<item *> active_item_set;
private:
std::unordered_map<int, std::list<item_reference>> active_items;
// Cache for fast lookup when we're iterating over the active items to verify the item is present.
std::unordered_set<item *> active_item_set;

public:
void remove( std::list<item>::iterator it, point location );
void add( std::list<item>::iterator it, point location );
bool has( std::list<item>::iterator it, point ) const;
// Use this one if there's a chance that the item being referenced has been invalidated.
bool has( item_reference const &itm ) const;
bool empty() const;
std::list<item_reference> get();
public:
void remove( std::list<item>::iterator it, point location );
void add( std::list<item>::iterator it, point location );
bool has( std::list<item>::iterator it, point ) const;
// Use this one if there's a chance that the item being referenced has been invalidated.
bool has( item_reference const &itm ) const;
bool empty() const;
std::list<item_reference> get();
};

#endif
22 changes: 11 additions & 11 deletions src/addiction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
class addiction;
class player;
enum add_type : int;
enum morale_type : int;
enum morale_type : int;

constexpr int MIN_ADDICTION_LEVEL = 3; // Minimum intensity before effects are seen
constexpr int MIN_ADDICTION_LEVEL = 3; // Minimum intensity before effects are seen

// cancel_activity is called when the addication effect wants to interrupt the player
// with an optional pre-translated message.
void addict_effect(player &u, addiction &add,
std::function<void (char const*)> const &cancel_activity);
// cancel_activity is called when the addication effect wants to interrupt the player
// with an optional pre-translated message.
void addict_effect( player &u, addiction &add,
std::function<void ( char const * )> const &cancel_activity );

std::string addiction_type_name(add_type cur);
std::string addiction_type_name( add_type cur );

std::string addiction_name(addiction const &cur);
std::string addiction_name( addiction const &cur );

morale_type addiction_craving(add_type cur);
morale_type addiction_craving( add_type cur );

add_type addiction_type(std::string const &name);
add_type addiction_type( std::string const &name );

std::string addiction_text(player const &u, addiction const &cur);
std::string addiction_text( player const &u, addiction const &cur );

#endif
42 changes: 23 additions & 19 deletions src/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,44 @@

#include <unordered_map>

namespace {
namespace
{
using ammo_map_t = std::unordered_map<std::string, ammunition_type>;

ammo_map_t& all_ammunition_types() {
ammo_map_t &all_ammunition_types()
{
static ammo_map_t the_map;
return the_map;
}
} //namespace

void ammunition_type::load_ammunition_type(JsonObject &jsobj)
void ammunition_type::load_ammunition_type( JsonObject &jsobj )
{
auto const result = all_ammunition_types().insert(std::make_pair(
jsobj.get_string("id"), ammunition_type {}));
auto const result = all_ammunition_types().insert( std::make_pair(
jsobj.get_string( "id" ), ammunition_type {} ) );

if (!result.second) {
debugmsg("duplicate ammo id: %s", result.first->first.c_str());
if( !result.second ) {
debugmsg( "duplicate ammo id: %s", result.first->first.c_str() );
}

auto &ammo = result.first->second;
ammo.name_ = jsobj.get_string("name");
ammo.default_ammotype_ = jsobj.get_string("default");
ammo.name_ = jsobj.get_string( "name" );
ammo.default_ammotype_ = jsobj.get_string( "default" );
}

ammunition_type const& ammunition_type::find_ammunition_type(std::string const &ident)
ammunition_type const &ammunition_type::find_ammunition_type( std::string const &ident )
{
auto const& the_map = all_ammunition_types();
auto const &the_map = all_ammunition_types();

auto const it = the_map.find(ident);
if (it != the_map.end()) {
auto const it = the_map.find( ident );
if( it != the_map.end() ) {
return it->second;
}

debugmsg("Tried to get invalid ammunition: %s", ident.c_str());
static ammunition_type const null_ammunition {"null"};
debugmsg( "Tried to get invalid ammunition: %s", ident.c_str() );
static ammunition_type const null_ammunition {
"null"
};
return null_ammunition;
}

Expand All @@ -49,17 +53,17 @@ void ammunition_type::reset()

void ammunition_type::check_consistency()
{
for (const auto &ammo : all_ammunition_types()) {
for( const auto &ammo : all_ammunition_types() ) {
auto const &id = ammo.first;
auto const &at = ammo.second.default_ammotype_;

// TODO: these ammo types should probably not have default ammo at all.
if (at == "UPS" || at == "components" || at == "thrown") {
if( at == "UPS" || at == "components" || at == "thrown" ) {
continue;
}

if (!at.empty() && !item::type_is_defined(at)) {
debugmsg("ammo type %s has invalid default ammo %s", id.c_str(), at.c_str());
if( !at.empty() && !item::type_is_defined( at ) ) {
debugmsg( "ammo type %s has invalid default ammo %s", id.c_str(), at.c_str() );
}
}
}
42 changes: 21 additions & 21 deletions src/ammo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ class JsonObject;

class ammunition_type
{
friend class DynamicDataLoader;
public:
ammunition_type() = default;
explicit ammunition_type(std::string name) : name_(std::move(name)) { }

std::string const& name() const {
return name_;
}

std::string const& default_ammotype() const {
return default_ammotype_;
}

static ammunition_type const& find_ammunition_type(std::string const &ident);
private:
std::string name_;
std::string default_ammotype_;

static void load_ammunition_type(JsonObject &jsobj);
static void reset();
static void check_consistency();
friend class DynamicDataLoader;
public:
ammunition_type() = default;
explicit ammunition_type( std::string name ) : name_( std::move( name ) ) { }

std::string const &name() const {
return name_;
}

std::string const &default_ammotype() const {
return default_ammotype_;
}

static ammunition_type const &find_ammunition_type( std::string const &ident );
private:
std::string name_;
std::string default_ammotype_;

static void load_ammunition_type( JsonObject &jsobj );
static void reset();
static void check_consistency();
};

#endif
32 changes: 15 additions & 17 deletions src/artifact.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,39 +62,37 @@ class it_artifact_tool : public it_tool, public JsonSerializer, public JsonDeser
{
public:
using JsonSerializer::serialize;
void serialize(JsonOut &json) const override;
void serialize( JsonOut &json ) const override;
using JsonDeserializer::deserialize;
void deserialize(JsonObject &jo);
void deserialize(JsonIn &jsin) override
{
void deserialize( JsonObject &jo );
void deserialize( JsonIn &jsin ) override {
JsonObject jo = jsin.get_object();
deserialize(jo);
deserialize( jo );
}

it_artifact_tool();
it_artifact_tool(JsonObject &jo);
it_artifact_tool( JsonObject &jo );

void create_name(const std::string &type);
void create_name(const std::string &property_name, const std::string &shape_name);
void create_name( const std::string &type );
void create_name( const std::string &property_name, const std::string &shape_name );
};

class it_artifact_armor : public itype, public JsonSerializer, public JsonDeserializer
{
public:
using JsonSerializer::serialize;
void serialize(JsonOut &json) const override;
void serialize( JsonOut &json ) const override;
using JsonDeserializer::deserialize;
void deserialize(JsonObject &jo);
void deserialize(JsonIn &jsin) override
{
void deserialize( JsonObject &jo );
void deserialize( JsonIn &jsin ) override {
JsonObject jo = jsin.get_object();
deserialize(jo);
deserialize( jo );
}

it_artifact_armor();
it_artifact_armor(JsonObject &jo);
it_artifact_armor( JsonObject &jo );

void create_name(const std::string &type);
void create_name( const std::string &type );
};


Expand All @@ -106,8 +104,8 @@ std::string new_natural_artifact( artifact_natural_property prop );
std::string architects_cube();

// note: needs to be called by main() before MAPBUFFER.load
void load_artifacts(const std::string &filename);
void load_artifacts_from_ifstream(std::ifstream &f);
void load_artifacts( const std::string &filename );
void load_artifacts_from_ifstream( std::ifstream &f );
// save artifact definitions to json, path must be the same as for loading.
bool save_artifacts( const std::string &path );

Expand Down
Loading

0 comments on commit b6284a4

Please sign in to comment.