Skip to content

Commit

Permalink
Merge pull request #16210 from illi-kun/astyle_construction_cpp_part4
Browse files Browse the repository at this point in the history
Astyle construction.cpp, part 4
  • Loading branch information
Rivet-the-Zombie committed Apr 15, 2016
2 parents a97ae2e + 21d5185 commit c5aad12
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,32 +610,32 @@ bool can_construct( const std::string &desc )
return false;
}

bool can_construct(construction const *con, int x, int y)
bool can_construct( construction const *con, int x, int y )
{
// see if the special pre-function checks out
bool place_okay = con->pre_special(point(x, y));
bool place_okay = con->pre_special( point( x, y ) );
// see if the terrain type checks out
if (!con->pre_terrain.empty()) {
if (con->pre_is_furniture) {
if( !con->pre_terrain.empty() ) {
if( con->pre_is_furniture ) {
furn_id f = furnmap[con->pre_terrain].loadid;
place_okay &= (g->m.furn(x, y) == f);
place_okay &= ( g->m.furn( x, y ) == f );
} else {
ter_id t = termap[con->pre_terrain].loadid;
place_okay &= (g->m.ter(x, y) == t);
place_okay &= ( g->m.ter( x, y ) == t );
}
}
// see if the flags check out
place_okay &= std::all_of(begin(con->pre_flags), end(con->pre_flags),
[&](std::string const& flag) { return g->m.has_flag(flag, x, y); });

// make sure the construction would actually do something
if (!con->post_terrain.empty()) {
if (con->post_is_furniture) {
if( !con->post_terrain.empty() ) {
if( con->post_is_furniture ) {
furn_id f = furnmap[con->post_terrain].loadid;
place_okay &= (g->m.furn(x, y) != f);
place_okay &= ( g->m.furn( x, y ) != f );
} else {
ter_id t = termap[con->post_terrain].loadid;
place_okay &= (g->m.ter(x, y) != t);
place_okay &= ( g->m.ter( x, y ) != t );
}
}
return place_okay;
Expand All @@ -656,16 +656,16 @@ bool can_construct( construction const *con )
return false;
}

void place_construction(const std::string &desc)
void place_construction( const std::string &desc )
{
g->refresh_all();
const inventory &total_inv = g->u.crafting_inventory();

std::vector<construction *> cons = constructions_by_desc(desc);
std::vector<construction *> cons = constructions_by_desc( desc );
std::map<tripoint, construction *> valid;
for (int x = g->u.posx() - 1; x <= g->u.posx() + 1; x++) {
for (int y = g->u.posy() - 1; y <= g->u.posy() + 1; y++) {
if (x == g->u.posx() && y == g->u.posy()) {
for( int x = g->u.posx() - 1; x <= g->u.posx() + 1; x++ ) {
for( int y = g->u.posy() - 1; y <= g->u.posy() + 1; y++ ) {
if( x == g->u.posx() && y == g->u.posy() ) {
y++;
}
for( auto &con : cons ) {
Expand All @@ -680,21 +680,21 @@ void place_construction(const std::string &desc)
g->m.drawsq( g->w_terrain, g->u, elem.first, true, false,
g->u.pos() + g->u.view_offset );
}
wrefresh(g->w_terrain);
wrefresh( g->w_terrain );

int dirx, diry;
if (!choose_adjacent(_("Construct where?"), dirx, diry)) {
if( !choose_adjacent( _( "Construct where?" ), dirx, diry ) ) {
return;
}

tripoint choice( dirx, diry, g->u.posz() );
if (valid.find(choice) == valid.end()) {
add_msg(m_info, _("You cannot build there!"));
if( valid.find( choice ) == valid.end() ) {
add_msg( m_info, _( "You cannot build there!" ) );
return;
}

construction *con = valid[choice];
g->u.assign_activity(ACT_BUILD, con->adjusted_time(), con->id);
g->u.assign_activity( ACT_BUILD, con->adjusted_time(), con->id );
g->u.activity.placement = choice;
}

Expand All @@ -703,13 +703,13 @@ void complete_construction()
player &u = g->u;
const construction &built = constructions[u.activity.index];

u.practice( built.skill, (int)( (10 + 15*built.difficulty) * (1 + built.time/30000.0) ),
(int)(built.difficulty * 1.25) );
u.practice( built.skill, ( int )( ( 10 + 15 * built.difficulty ) * ( 1 + built.time / 30000.0 ) ),
( int )( built.difficulty * 1.25 ) );


// Friendly NPCs gain exp from assisting or watching...
for( auto &elem : g->active_npc ) {
if (rl_dist( elem->pos(), u.pos() ) < PICKUP_RANGE && elem->is_friend()){
if( rl_dist( elem->pos(), u.pos() ) < PICKUP_RANGE && elem->is_friend() ) {
//If the NPC can understand what you are doing, they gain more exp
if (elem->skillLevel(built.skill) >= built.difficulty){
elem->practice( built.skill, (int)( (10 + 15*built.difficulty) * (1 + built.time/30000.0) ),
Expand All @@ -724,22 +724,22 @@ void complete_construction()
}
}

for (const auto &it : built.requirements.get_components()) {
for( const auto &it : built.requirements.get_components() ) {
// Tried issuing rope for WEB_ROPE here. Didn't arrive in time for the
// gear check. Ultimately just coded a bypass in crafting.cpp.
u.consume_items(it);
u.consume_items( it );
}
for( const auto &it : built.requirements.get_tools() ) {
u.consume_tools( it );
}

// Make the terrain change
int terx = u.activity.placement.x, tery = u.activity.placement.y;
if (built.post_terrain != "") {
if (built.post_is_furniture) {
g->m.furn_set(terx, tery, built.post_terrain);
if( built.post_terrain != "" ) {
if( built.post_is_furniture ) {
g->m.furn_set( terx, tery, built.post_terrain );
} else {
g->m.ter_set(terx, tery, built.post_terrain);
g->m.ter_set( terx, tery, built.post_terrain );
}
}

Expand Down Expand Up @@ -851,17 +851,17 @@ const vpart_str_id &vpart_from_item( const std::string &item_id )
return frame_id;
}

void construct::done_vehicle(point p)
void construct::done_vehicle( point p )
{
std::string name = string_input_popup(_("Enter new vehicle name:"), 20);
if(name.empty()) {
name = _("Car");
std::string name = string_input_popup( _( "Enter new vehicle name:" ), 20 );
if( name.empty() ) {
name = _( "Car" );
}

vehicle *veh = g->m.add_vehicle( vproto_id( "none" ), p.x, p.y, 270, 0, 0);
vehicle *veh = g->m.add_vehicle( vproto_id( "none" ), p.x, p.y, 270, 0, 0 );

if (!veh) {
debugmsg ("error constructing vehicle");
if( !veh ) {
debugmsg( "error constructing vehicle" );
return;
}
veh->name = name;
Expand All @@ -872,22 +872,22 @@ void construct::done_vehicle(point p)
g->m.add_vehicle_to_cache( veh );
}

void construct::done_deconstruct(point p)
void construct::done_deconstruct( point p )
{
// TODO: Make this the argument
tripoint p3( p, g->get_levz() );
if (g->m.has_furn(p.x, p.y)) {
const furn_t &f = g->m.furn_at(p.x, p.y);
if (!f.deconstruct.can_do) {
add_msg(m_info, _("That %s can not be disassembled!"), f.name.c_str());
if( g->m.has_furn( p.x, p.y ) ) {
const furn_t &f = g->m.furn_at( p.x, p.y );
if( !f.deconstruct.can_do ) {
add_msg( m_info, _( "That %s can not be disassembled!" ), f.name.c_str() );
return;
}
if (f.deconstruct.furn_set.empty()) {
g->m.furn_set(p.x, p.y, f_null);
if( f.deconstruct.furn_set.empty() ) {
g->m.furn_set( p.x, p.y, f_null );
} else {
g->m.furn_set(p.x, p.y, f.deconstruct.furn_set);
g->m.furn_set( p.x, p.y, f.deconstruct.furn_set );
}
add_msg(_("You disassemble the %s."), f.name.c_str());
add_msg( _( "You disassemble the %s." ), f.name.c_str() );
g->m.spawn_items( p3, item_group::items_from( f.deconstruct.drop_group, calendar::turn ) );
// Hack alert.
// Signs have cosmetics associated with them on the submap since
Expand All @@ -896,23 +896,23 @@ void construct::done_deconstruct(point p)
// writing from the submap.
g->m.delete_signage( p3 );
} else {
const ter_t &t = g->m.ter_at(p.x, p.y);
if (!t.deconstruct.can_do) {
add_msg(_("That %s can not be disassembled!"), t.name.c_str());
const ter_t &t = g->m.ter_at( p.x, p.y );
if( !t.deconstruct.can_do ) {
add_msg( _( "That %s can not be disassembled!" ), t.name.c_str() );
return;
}
if (t.id == "t_console_broken") {
if (g->u.skillLevel( skill_electronics ) >= 1) {
g->u.practice( skill_electronics, 20, 4);
if( t.id == "t_console_broken" ) {
if( g->u.skillLevel( skill_electronics ) >= 1 ) {
g->u.practice( skill_electronics, 20, 4 );
}
}
if (t.id == "t_console") {
if (g->u.skillLevel( skill_electronics ) >= 1) {
g->u.practice( skill_electronics, 40, 8);
if( t.id == "t_console" ) {
if( g->u.skillLevel( skill_electronics ) >= 1 ) {
g->u.practice( skill_electronics, 40, 8 );
}
}
g->m.ter_set(p.x, p.y, t.deconstruct.ter_set);
add_msg(_("You disassemble the %s."), t.name.c_str());
g->m.ter_set( p.x, p.y, t.deconstruct.ter_set );
add_msg( _( "You disassemble the %s." ), t.name.c_str() );
g->m.spawn_items( p3, item_group::items_from( t.deconstruct.drop_group, calendar::turn ) );
}
}
Expand Down

0 comments on commit c5aad12

Please sign in to comment.