void wield_check_internal( player &dummy, item &the_item, const char *section_text, const std::string &var_name, int expected_cost ) { dummy.weapon = dummy.ret_null; dummy.set_moves( 1000 ); int old_moves = dummy.moves; dummy.wield( the_item ); int move_cost = old_moves - dummy.moves; if( expected_cost < 0 ) { printf( " wield_check( %s, dummy, %s, %d );\n", section_text, var_name.c_str(), move_cost ); } else { INFO( "Strength:" << dummy.get_str() ); int max_cost = expected_cost * 1.1f; int min_cost = expected_cost * 0.9f; CHECK( move_cost <= max_cost ); CHECK( move_cost >= min_cost ); } }
void start_location::place_player( player &u ) const { // Need the "real" map with it's inside/outside cache and the like. map &m = g->m; // Start us off somewhere in the center of the map u.setx( SEEX * int( MAPSIZE / 2 ) + 5 ); u.sety( SEEY * int( MAPSIZE / 2 ) + 6 ); u.setz( g->get_levz() ); m.build_map_cache( m.get_abs_sub().z ); const bool must_be_inside = flags().count( "ALLOW_OUTSIDE" ) == 0; ///\EFFECT_STR allows player to start behind less-bashable furniture and terrain const int bash = u.get_str(); // TODO: Allow using items here // Remember biggest found location // Sometimes it may be impossible to automatically found an ideal location // but the player may be more creative than this algorithm and do away with just "good" int best_rate = 0; // In which attempt did this area get checked? // We can overwrite earlier attempts, but not start in them int checked[SEEX * MAPSIZE][SEEY * MAPSIZE]; std::fill_n( &checked[0][0], SEEX * MAPSIZE * SEEY * MAPSIZE, 0 ); bool found_good_spot = false; // Try some random points at start int tries = 0; const auto check_spot = [&]( const tripoint & pt ) { tries++; const int rate = rate_location( m, pt, must_be_inside, bash, tries, checked ); if( best_rate < rate ) { best_rate = rate; u.setpos( pt ); if( rate == INT_MAX ) { found_good_spot = true; } } }; while( !found_good_spot && tries < 100 ) { tripoint rand_point( ( SEEX * int( MAPSIZE / 2 ) ) + rng( 0, SEEX * 2 ), ( SEEY * int( MAPSIZE / 2 ) ) + rng( 0, SEEY * 2 ), u.posz() ); check_spot( rand_point ); } // If we haven't got a good location by now, screw it and brute force it // This only happens in exotic locations (deep of a science lab), but it does happen if( !found_good_spot ) { tripoint tmp = u.pos(); int &x = tmp.x; int &y = tmp.y; for( x = 0; x < SEEX * MAPSIZE; x++ ) { for( y = 0; y < SEEY * MAPSIZE; y++ ) { check_spot( tmp ); } } } if( !found_good_spot ) { debugmsg( "Could not find a good starting place for character" ); } }