-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move struct mapgendata into separate header and source file
Also convert it into a class for consistency. And add some preliminary documentation.
- Loading branch information
Showing
5 changed files
with
245 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include "mapgendata.h" | ||
|
||
#include "regional_settings.h" | ||
#include "map.h" | ||
|
||
mapgendata::mapgendata( oter_id north, oter_id east, oter_id south, oter_id west, | ||
oter_id northeast, oter_id southeast, oter_id southwest, oter_id northwest, | ||
oter_id up, oter_id down, int z, const regional_settings &rsettings, map &mp ) | ||
: t_nesw{ north, east, south, west, northeast, southeast, southwest, northwest } | ||
, t_above( up ) | ||
, t_below( down ) | ||
, zlevel( z ) | ||
, region( rsettings ) | ||
, m( mp ) | ||
, default_groundcover( region.default_groundcover ) | ||
{ | ||
} | ||
|
||
void mapgendata::set_dir( int dir_in, int val ) | ||
{ | ||
switch( dir_in ) { | ||
case 0: | ||
n_fac = val; | ||
break; | ||
case 1: | ||
e_fac = val; | ||
break; | ||
case 2: | ||
s_fac = val; | ||
break; | ||
case 3: | ||
w_fac = val; | ||
break; | ||
case 4: | ||
ne_fac = val; | ||
break; | ||
case 5: | ||
se_fac = val; | ||
break; | ||
case 6: | ||
sw_fac = val; | ||
break; | ||
case 7: | ||
nw_fac = val; | ||
break; | ||
default: | ||
debugmsg( "Invalid direction for mapgendata::set_dir. dir_in = %d", dir_in ); | ||
break; | ||
} | ||
} | ||
|
||
void mapgendata::fill( int val ) | ||
{ | ||
n_fac = val; | ||
e_fac = val; | ||
s_fac = val; | ||
w_fac = val; | ||
ne_fac = val; | ||
se_fac = val; | ||
sw_fac = val; | ||
nw_fac = val; | ||
} | ||
|
||
int &mapgendata::dir( int dir_in ) | ||
{ | ||
switch( dir_in ) { | ||
case 0: | ||
return n_fac; | ||
case 1: | ||
return e_fac; | ||
case 2: | ||
return s_fac; | ||
case 3: | ||
return w_fac; | ||
case 4: | ||
return ne_fac; | ||
case 5: | ||
return se_fac; | ||
case 6: | ||
return sw_fac; | ||
case 7: | ||
return nw_fac; | ||
default: | ||
debugmsg( "Invalid direction for mapgendata::set_dir. dir_in = %d", dir_in ); | ||
//return something just so the compiler doesn't freak out. Not really correct, though. | ||
return n_fac; | ||
} | ||
} | ||
|
||
void mapgendata::square_groundcover( const int x1, const int y1, const int x2, const int y2 ) | ||
{ | ||
m.draw_square_ter( default_groundcover, point( x1, y1 ), point( x2, y2 ) ); | ||
} | ||
|
||
void mapgendata::fill_groundcover() | ||
{ | ||
m.draw_fill_background( default_groundcover ); | ||
} | ||
|
||
bool mapgendata::is_groundcover( const ter_id &iid ) const | ||
{ | ||
for( const auto &pr : default_groundcover ) { | ||
if( pr.obj == iid ) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool mapgendata::has_basement() const | ||
{ | ||
const std::vector<std::string> &all_basements = region.city_spec.basements.all; | ||
return std::any_of( all_basements.begin(), all_basements.end(), [this]( const std::string & b ) { | ||
return t_below == oter_id( b ); | ||
} ); | ||
} | ||
|
||
ter_id mapgendata::groundcover() | ||
{ | ||
const ter_id *tid = default_groundcover.pick(); | ||
return tid != nullptr ? *tid : t_null; | ||
} | ||
|
||
const oter_id &mapgendata::neighbor_at( om_direction::type dir ) const | ||
{ | ||
// TODO: De-uglify, implement proper conversion somewhere | ||
switch( dir ) { | ||
case om_direction::type::north: | ||
return north(); | ||
case om_direction::type::east: | ||
return east(); | ||
case om_direction::type::south: | ||
return south(); | ||
case om_direction::type::west: | ||
return west(); | ||
default: | ||
break; | ||
} | ||
|
||
debugmsg( "Tried to get neighbor from invalid direction %d", dir ); | ||
return north(); | ||
} |
Oops, something went wrong.