Skip to content

Commit

Permalink
things are back to broke
Browse files Browse the repository at this point in the history
I am losing my mind
  • Loading branch information
mlangsdorf committed May 2, 2019
1 parent 16b60c7 commit 78106cd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
9 changes: 8 additions & 1 deletion data/json/mapgen/evac_center.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,14 @@
{ "item": "allclothes", "x": [ 3, 15 ], "y": [ 11, 11 ], "chance": 60 },
{ "item": "allclothes", "x": [ 6, 15 ], "y": [ 16, 16 ], "chance": 60 }
],
"place_monsters": [ { "monster": "GROUP_MALL", "x": [ 2, 15 ], "y": [ 4, 20 ], "density": 0.6 } ]
"place_monsters": [ { "monster": "GROUP_MALL", "x": [ 2, 15 ], "y": [ 4, 20 ], "density": 0.6 } ],
"place_zones": [
{ "type": "NPC_NO_INVESTIGATE", "faction": "lobby_beggars", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "type": "NPC_NO_INVESTIGATE", "faction": "free_merchants", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "type": "NPC_NO_INVESTIGATE", "faction": "old_guard", "x": [ 0, 23 ], "y": [ 0, 23 ] },
{ "type": "NPC_NO_INVESTIGATE", "faction": "wasteland_scavengers", "x": [ 0, 23 ], "y": [ 0, 23 ] }
]

}
},
{
Expand Down
8 changes: 4 additions & 4 deletions src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,12 @@ void zone_manager::rotate_zones( map &target_map, const int turns )
if( turns == 0 ) {
return;
}
const tripoint &a_start = target_map.getabs( tripoint( 0, 0, 0 ) );
const tripoint &a_end = target_map.getabs( tripoint( 23, 23, 0 ) );
const tripoint a_start = target_map.getabs( tripoint( 0, 0, 0 ) );
const tripoint a_end = target_map.getabs( tripoint( 23, 23, 0 ) );

for( zone_data &zone: zones ) {
const tripoint &z_start = zone.get_start_point();
const tripoint &z_end = zone.get_end_point();
const tripoint z_start = zone.get_start_point();
const tripoint z_end = zone.get_end_point();
if( ( a_start.x <= z_start.x && a_start.y <= z_start.y ) &&
( a_end.x >= z_end.x && a_end.y >= a_end.y ) ) {
tripoint z_l_start = target_map.getlocal( z_start );
Expand Down
4 changes: 2 additions & 2 deletions src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ struct npc_follower_rules {
};

struct dangerous_sound {
tripoint pos;
tripoint abs_pos;
int type;
int volume;
};
Expand Down Expand Up @@ -330,7 +330,7 @@ struct npc_short_term_cache {
// map of positions / type / volume of suspicious sounds
std::vector<dangerous_sound> sound_alerts;
// current sound position being investigated
tripoint spos;
tripoint s_abs_pos;
// Position to return to guarding
cata::optional<tripoint> guard_pos;
double my_weapon_value;
Expand Down
35 changes: 16 additions & 19 deletions src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void npc::regen_ai_cache()
{
auto i = std::begin( ai_cache.sound_alerts );
while( i != std::end( ai_cache.sound_alerts ) ) {
if( sees( i->pos ) ) {
if( sees( g->m.getlocal( i->abs_pos ) ) ) {
i = ai_cache.sound_alerts.erase( i );
if( ai_cache.sound_alerts.size() == 1 ) {
path.clear();
Expand Down Expand Up @@ -597,7 +597,7 @@ void npc::move()
action = method_of_attack();
} else if( !ai_cache.sound_alerts.empty() && !is_walking_with() ) {
if( !ai_cache.guard_pos ) {
ai_cache.guard_pos = pos();
ai_cache.guard_pos = g->m.getabs( pos() );
}
if( ai_cache.sound_alerts.size() > 1 ) {
std::sort( ai_cache.sound_alerts.begin(), ai_cache.sound_alerts.end(),
Expand All @@ -606,13 +606,13 @@ void npc::move()
ai_cache.sound_alerts.resize( 10 );
}
}
ai_cache.spos = ai_cache.sound_alerts.front().pos;
add_msg( m_debug, "NPC %s: investigating sound at x(%d) y(%d)", name, ai_cache.spos.x,
ai_cache.spos.y );
ai_cache.s_abs_pos = ai_cache.sound_alerts.front().abs_pos;
add_msg( "NPC %s: investigating sound at x(%d) y(%d)", name, ai_cache.s_abs_pos.x,
ai_cache.s_abs_pos.y );
action = npc_investigate_sound;
} else if( ai_cache.sound_alerts.empty() && ai_cache.guard_pos ) {
tripoint return_guard_pos = *ai_cache.guard_pos;
add_msg( m_debug, "NPC %s: returning to guard spot at x(%d) y(%d)", name,
add_msg( "NPC %s: returning to guard spot at x(%d) y(%d)", name,
return_guard_pos.x, return_guard_pos.y );
action = npc_return_to_guard_pos;
} else {
Expand Down Expand Up @@ -727,14 +727,15 @@ void npc::execute_action( npc_action action )
break;

case npc_investigate_sound: {
update_path( ai_cache.spos );
update_path( g->m.getlocal( ai_cache.s_abs_pos ) );
move_to_next();
}
break;

case npc_return_to_guard_pos: {
update_path( *ai_cache.guard_pos );
if( pos() == *ai_cache.guard_pos || path.empty() ) {
const tripoint local_guard_pos = g->m.getlocal( *ai_cache.guard_pos );
update_path( local_guard_pos );
if( pos() == local_guard_pos || path.empty() ) {
move_pause();
ai_cache.guard_pos = cata::nullopt;
path.clear();
Expand Down Expand Up @@ -3156,7 +3157,7 @@ void npc::reach_omt_destination()
{
if( is_travelling() ) {
talk_function::assign_guard( *this );
guard_pos = global_square_location();
guard_pos = g->m.getabs( pos() );
omt_path.clear();
goal = no_goal_point;
if( rl_dist( g->u.pos(), pos() ) > SEEX * 2 || !g->u.sees( pos() ) ) {
Expand All @@ -3176,7 +3177,7 @@ void npc::reach_omt_destination()
}
// If we are guarding, remember our position in case we get forcibly moved
goal = global_omt_location();
if( guard_pos == global_square_location() ) {
if( guard_pos == g->m.getabs( pos() ) ) {
// This is the specific point
return;
}
Expand All @@ -3185,14 +3186,10 @@ void npc::reach_omt_destination()
// No point recalculating the path to get home
move_to_next();
} else if( guard_pos != no_goal_point ) {
const tripoint sm_dir = goal - submap_coords;
const tripoint dest( sm_dir.x * SEEX + guard_pos.x - posx(),
sm_dir.y * SEEY + guard_pos.y - posy(),
guard_pos.z );
update_path( dest );
update_path( g->m.getlocal( guard_pos ) );
move_to_next();
} else {
guard_pos = global_square_location();
guard_pos = g->m.getabs( pos() );
}
}

Expand Down Expand Up @@ -3243,7 +3240,7 @@ void npc::set_omt_destination()
void npc::go_to_omt_destination()
{
if( ai_cache.guard_pos ) {
if( pos() == *ai_cache.guard_pos ) {
if( g->m.getabs( pos() ) == *ai_cache.guard_pos ) {
path.clear();
ai_cache.guard_pos = cata::nullopt;
move_pause();
Expand Down Expand Up @@ -3311,7 +3308,7 @@ void npc::go_to_omt_destination()
void npc::guard_current_pos()
{
goal = global_omt_location();
guard_pos = global_square_location();
guard_pos = g->m.getabs( pos() );
}

std::string npc_action_name( npc_action action )
Expand Down
32 changes: 20 additions & 12 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ void game::chat()
void npc::handle_sound( int priority, const std::string &description, int heard_volume,
const tripoint &spos )
{
add_msg( m_debug, "%s heard '%s', priority %d at volume %d from %d:%d, my pos %d:%d",
disp_name(), description, priority, heard_volume, spos.x, spos.y, pos().x, pos().y );
const tripoint s_abs_pos = g->m.getabs( spos );
const tripoint my_abs_pos = g->m.getabs( pos() );

add_msg( "%s heard '%s', priority %d at volume %d from %d:%d, my pos %d:%d",
disp_name(), description, priority, heard_volume, s_abs_pos.x, s_abs_pos.y,
my_abs_pos.x, my_abs_pos.y );

const sounds::sound_t spriority = static_cast<sounds::sound_t>( priority );
bool player_ally = g->u.pos() == spos && is_player_ally();
Expand All @@ -321,19 +325,19 @@ void npc::handle_sound( int priority, const std::string &description, int heard_
// but only for bantering purposes, not for investigating.
if( spriority < sounds::sound_t::alarm ) {
if( player_ally ) {
add_msg( m_debug, "Allied NPC ignored same faction %s", name );
add_msg( "Allied NPC ignored same faction %s", name );
return;
}
if( npc_ally ) {
add_msg( m_debug, "NPC ignored same faction %s", name );
add_msg( "NPC ignored same faction %s", name );
return;
}
}
// discount if sound source is player, or seen by player,
// and listener is friendly and sound source is combat or alert only.
if( spriority < sounds::sound_t::alarm && g->u.sees( spos ) ) {
if( is_player_ally() ) {
add_msg( m_debug, "NPC %s ignored low priority noise that player can see", name );
add_msg( "NPC %s ignored low priority noise that player can see", name );
return;
// discount if sound source is player, or seen by player,
// listener is neutral and sound type is worth investigating.
Expand Down Expand Up @@ -363,23 +367,27 @@ void npc::handle_sound( int priority, const std::string &description, int heard_
}
bool should_check = rl_dist( pos(), spos ) < investigate_dist;
if( should_check ) {
add_msg( "%s could check sound", name );
const zone_manager &mgr = zone_manager::get_manager();
const tripoint &s_abs_pos = g->m.getabs( spos );
if( mgr.has( zone_no_investigate, s_abs_pos, fac_id ) ) {
add_msg( "sound in ignore at %d:%d", name, s_abs_pos.x, s_abs_pos.y);
should_check = false;
} else if( mgr.has_defined( zone_investigate_only, fac_id ) &&
!mgr.has( zone_investigate_only, s_abs_pos, fac_id ) ) {
should_check = false;
} else if( mgr.has( zone_investigate_only, my_abs_pos, fac_id ) ) {
add_msg( "%s is investigate only", name );
if( !mgr.has( zone_investigate_only, s_abs_pos, fac_id ) ) {
add_msg( "sound not in an %d:%d", name, s_abs_pos.x, s_abs_pos.y);
should_check = false;
}
}
}
if( should_check ) {
add_msg( m_debug, "NPC %s added noise at pos %d:%d", name, spos.x, spos.y );
add_msg( "NPC %s added noise at pos %d:%d", name, s_abs_pos.x, s_abs_pos.y );
dangerous_sound temp_sound;
temp_sound.pos = spos;
temp_sound.abs_pos = s_abs_pos;
temp_sound.volume = heard_volume;
temp_sound.type = priority;
if( !ai_cache.sound_alerts.empty() ) {
if( ai_cache.sound_alerts.back().pos != spos ) {
if( ai_cache.sound_alerts.back().abs_pos != s_abs_pos ) {
ai_cache.sound_alerts.push_back( temp_sound );
}
} else {
Expand Down

0 comments on commit 78106cd

Please sign in to comment.