Skip to content

Commit

Permalink
Converted coordinate_conversions.h usages
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed Oct 1, 2024
1 parent 62d3a93 commit e24153b
Show file tree
Hide file tree
Showing 32 changed files with 240 additions and 435 deletions.
6 changes: 3 additions & 3 deletions src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "colony.h"
#include "color.h"
#include "computer.h"
#include "coordinate_conversions.h"
#include "coordinates.h"
#include "creature.h"
#include "creature_tracker.h"
Expand Down Expand Up @@ -317,8 +316,9 @@ static void remove_submap_turrets()
map &here = get_map();
for( monster &critter : g->all_monsters() ) {
// Check 1) same overmap coords, 2) turret, 3) hostile
if( ms_to_omt_copy( here.getabs( critter.pos() ) ) == ms_to_omt_copy( here.getabs(
player_character.pos() ) ) &&
if( coords::project_to<coords::omt>( here.getglobal( critter.pos_bub() ) ) ==
coords::project_to<coords::omt>( here.getglobal(
player_character.pos_bub() ) ) &&
critter.has_flag( mon_flag_CONSOLE_DESPAWN ) &&
critter.attitude_to( player_character ) == Creature::Attitude::HOSTILE ) {
g->remove_zombie( critter );
Expand Down
162 changes: 0 additions & 162 deletions src/coordinate_conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,170 +17,8 @@ static int divide( int v, int m, int &r )
return result;
}

point omt_to_om_copy( const point &p )
{
return point( divide( p.x, OMAPX ), divide( p.y, OMAPY ) );
}

tripoint omt_to_om_copy( const tripoint &p )
{
return tripoint( divide( p.x, OMAPX ), divide( p.y, OMAPY ), p.z );
}

void omt_to_om( int &x, int &y )
{
x = divide( x, OMAPX );
y = divide( y, OMAPY );
}

point omt_to_om_remain( int &x, int &y )
{
return point( divide( x, OMAPX, x ), divide( y, OMAPY, y ) );
}

point om_to_omt_copy( const point &p )
{
return point( p.x * OMAPX, p.y * OMAPY );
}

point sm_to_omt_copy( const point &p )
{
return point( divide( p.x, 2 ), divide( p.y, 2 ) );
}

tripoint sm_to_omt_copy( const tripoint &p )
{
return tripoint( divide( p.x, 2 ), divide( p.y, 2 ), p.z );
}

void sm_to_omt( int &x, int &y )
{
x = divide( x, 2 );
y = divide( y, 2 );
}

point sm_to_omt_remain( int &x, int &y )
{
return point( divide( x, 2, x ), divide( y, 2, y ) );
}

point sm_to_om_copy( const point &p )
{
return point( divide( p.x, 2 * OMAPX ), divide( p.y, 2 * OMAPY ) );
}

tripoint sm_to_om_copy( const tripoint &p )
{
return tripoint( divide( p.x, 2 * OMAPX ), divide( p.y, 2 * OMAPY ), p.z );
}

void sm_to_om( int &x, int &y )
{
x = divide( x, 2 * OMAPX );
y = divide( y, 2 * OMAPY );
}

point sm_to_om_remain( int &x, int &y )
{
return point( divide( x, 2 * OMAPX, x ), divide( y, 2 * OMAPY, y ) );
}

point omt_to_ms_copy( const point &p )
{
return point( p.x * 2 * SEEX, p.y * 2 * SEEY );
}

point omt_to_sm_copy( const point &p )
{
return point( p.x * 2, p.y * 2 );
}

tripoint omt_to_sm_copy( const tripoint &p )
{
return tripoint( p.x * 2, p.y * 2, p.z );
}

void omt_to_sm( int &x, int &y )
{
x *= 2;
y *= 2;
}

point om_to_sm_copy( const point &p )
{
return point( p.x * 2 * OMAPX, p.y * 2 * OMAPX );
}

tripoint om_to_sm_copy( const tripoint &p )
{
return tripoint( p.x * 2 * OMAPX, p.y * 2 * OMAPX, p.z );
}

void om_to_sm( int &x, int &y )
{
x *= 2 * OMAPX;
y *= 2 * OMAPY;
}

point ms_to_sm_copy( const point &p )
{
return point( divide( p.x, SEEX ), divide( p.y, SEEY ) );
}

tripoint ms_to_sm_copy( const tripoint &p )
{
return tripoint( divide( p.x, SEEX ), divide( p.y, SEEY ), p.z );
}

void ms_to_sm( int &x, int &y )
{
x = divide( x, SEEX );
y = divide( y, SEEY );
}

point ms_to_sm_remain( int &x, int &y )
{
return point( divide( x, SEEX, x ), divide( y, SEEY, y ) );
}

void sm_to_ms( int &x, int &y )
{
x *= SEEX;
y *= SEEY;
}

point ms_to_omt_copy( const point &p )
{
return point( divide( p.x, SEEX * 2 ), divide( p.y, SEEY * 2 ) );
}

tripoint ms_to_omt_copy( const tripoint &p )
{
return tripoint( divide( p.x, SEEX * 2 ), divide( p.y, SEEY * 2 ), p.z );
}

void ms_to_omt( int &x, int &y )
{
x = divide( x, SEEX * 2 );
y = divide( y, SEEY * 2 );
}

point ms_to_omt_remain( int &x, int &y )
{
return point( divide( x, SEEX * 2, x ), divide( y, SEEY * 2, y ) );
}

tripoint omt_to_seg_copy( const tripoint &p )
{
return tripoint( divide( p.x, SEG_SIZE ), divide( p.y, SEG_SIZE ), p.z );
}

point sm_to_mmr_remain( int &x, int &y )
{
return point( divide( x, MM_REG_SIZE, x ), divide( y, MM_REG_SIZE, y ) );
}

tripoint mmr_to_sm_copy( const tripoint &p )
{
return tripoint( p.x * MM_REG_SIZE, p.y * MM_REG_SIZE, p.z );
}
160 changes: 0 additions & 160 deletions src/coordinate_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,171 +13,11 @@
* doc/POINTS_COORDINATES.md.
*
* This file provides static translation functions, named like this:
@code
static point <from>_to_<to>_copy(int x, int y);
static point <from>_to_<to>_copy(const point& p);
static tripoint <from>_to_<to>_copy(const tripoint& p);
static void <from>_to_<to>(int &x, int &y);
static void <from>_to_<to>(point& p);
static void <from>_to_<to>(tripoint& p);
static point <from>_to_<to>_remain(int &x, int &y);
static point <from>_to_<to>_remain(point& p);
@endcode
* Functions ending with _copy return the translated coordinates,
* other functions change the parameters itself and don't return anything.
* Functions ending with _remain return the translated coordinates and
* store the remainder in the parameters.
*/

// overmap terrain to overmap
point omt_to_om_copy( const point &p );
tripoint omt_to_om_copy( const tripoint &p );
void omt_to_om( int &x, int &y );
inline void omt_to_om( point &p )
{
omt_to_om( p.x, p.y );
}
inline void omt_to_om( tripoint &p )
{
omt_to_om( p.x, p.y );
}
point omt_to_om_remain( int &x, int &y );
inline point omt_to_om_remain( point &p )
{
return omt_to_om_remain( p.x, p.y );
}
// overmap to overmap terrain
point om_to_omt_copy( const point &p );
// submap to overmap terrain
point sm_to_omt_copy( const point &p );
tripoint sm_to_omt_copy( const tripoint &p );
void sm_to_omt( int &x, int &y );
inline void sm_to_omt( point &p )
{
sm_to_omt( p.x, p.y );
}
inline void sm_to_omt( tripoint &p )
{
sm_to_omt( p.x, p.y );
}
point sm_to_omt_remain( int &x, int &y );
inline point sm_to_omt_remain( point &p )
{
return sm_to_omt_remain( p.x, p.y );
}
// submap to overmap, basically: x / (OMAPX * 2)
point sm_to_om_copy( const point &p );
tripoint sm_to_om_copy( const tripoint &p );
void sm_to_om( int &x, int &y );
inline void sm_to_om( point &p )
{
sm_to_om( p.x, p.y );
}
inline void sm_to_om( tripoint &p )
{
sm_to_om( p.x, p.y );
}
point sm_to_om_remain( int &x, int &y );
inline point sm_to_om_remain( point &p )
{
return sm_to_om_remain( p.x, p.y );
}
// overmap terrain to submap, basically: x *= 2
inline int omt_to_sm_copy( int a )
{
return 2 * a;
}
point omt_to_sm_copy( const point &p );
tripoint omt_to_sm_copy( const tripoint &p );
void omt_to_sm( int &x, int &y );
inline void omt_to_sm( point &p )
{
omt_to_sm( p.x, p.y );
}
inline void omt_to_sm( tripoint &p )
{
omt_to_sm( p.x, p.y );
}
// overmap terrain to map square
point omt_to_ms_copy( const point &p );
// overmap to submap, basically: x *= 2 * OMAPX
point om_to_sm_copy( const point &p );
tripoint om_to_sm_copy( const tripoint &p );
void om_to_sm( int &x, int &y );
inline void om_to_sm( point &p )
{
om_to_sm( p.x, p.y );
}
inline void om_to_sm( tripoint &p )
{
om_to_sm( p.x, p.y );
}
// map squares to submap, basically: x /= SEEX
point ms_to_sm_copy( const point &p );
tripoint ms_to_sm_copy( const tripoint &p );
void ms_to_sm( int &x, int &y );
inline void ms_to_sm( point &p )
{
ms_to_sm( p.x, p.y );
}
inline void ms_to_sm( tripoint &p )
{
ms_to_sm( p.x, p.y );
}
point ms_to_sm_remain( int &x, int &y );
inline point ms_to_sm_remain( point &p )
{
return ms_to_sm_remain( p.x, p.y );
}
inline tripoint ms_to_sm_remain( tripoint &p )
{
return tripoint( ms_to_sm_remain( p.x, p.y ), p.z );
}
// submap back to map squares, basically: x *= SEEX
// Note: this gives you the map square coordinates of the top-left corner
// of the given submap.
inline point sm_to_ms_copy( const point &p )
{
return point( p.x * SEEX, p.y * SEEY );
}

inline tripoint sm_to_ms_copy( const tripoint &p )
{
return tripoint( p.x * SEEX, p.y * SEEY, p.z );
}
void sm_to_ms( int &x, int &y );
inline void sm_to_ms( point &p )
{
sm_to_ms( p.x, p.y );
}
inline void sm_to_ms( tripoint &p )
{
sm_to_ms( p.x, p.y );
}
// map squares to overmap terrain, basically: x /= SEEX * 2
point ms_to_omt_copy( const point &p );
tripoint ms_to_omt_copy( const tripoint &p );
void ms_to_omt( int &x, int &y );
inline void ms_to_omt( point &p )
{
ms_to_omt( p.x, p.y );
}
inline void ms_to_omt( tripoint &p )
{
ms_to_omt( p.x, p.y );
}
point ms_to_omt_remain( int &x, int &y );
inline point ms_to_omt_remain( point &p )
{
return ms_to_omt_remain( p.x, p.y );
}
// overmap terrain to map segment.
tripoint omt_to_seg_copy( const tripoint &p );
// Submap to memory map region.
point sm_to_mmr_remain( int &x, int &y );
// Memory map region to submap.
// Note: this produces sm coords of top-left corner of the region.
tripoint mmr_to_sm_copy( const tripoint &p );

#endif // CATA_SRC_COORDINATE_CONVERSIONS_H
19 changes: 19 additions & 0 deletions src/coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

#include <cstdlib>

// Moved from obsolete coordinate_conversions
static point om_to_omt_copy( const point &p )
{
return point( p.x * OMAPX, p.y * OMAPY );
}

static point omt_to_ms_copy( const point &p )
{
return point( p.x * 2 * SEEX, p.y * 2 * SEEY );
}

// End of moved code.

void real_coords::fromabs( const point &abs )
{
const point norm( std::abs( abs.x ), std::abs( abs.y ) );
Expand Down Expand Up @@ -34,6 +47,12 @@ void real_coords::fromabs( const point &abs )
om_pos.y = om_sub.y / 2;
}

void real_coords::fromomap( const point &rel_om, const point &rel_om_pos )
{
const point a = om_to_omt_copy( rel_om ) + rel_om_pos;
fromabs( omt_to_ms_copy( a ) );
}

point_rel_ms rebase_rel( point_sm_ms p )
{
return point_rel_ms( p.raw() );
Expand Down
Loading

0 comments on commit e24153b

Please sign in to comment.