Skip to content

Commit

Permalink
initial progress
Browse files Browse the repository at this point in the history
  • Loading branch information
OzoneH3 committed Nov 13, 2019
1 parent 7df9a89 commit 6a6499e
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 94 deletions.
93 changes: 93 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "map_memory.h"
#include "pldata.h"
#include "point.h"
#include "options.h"

class JsonIn;
class JsonObject;
Expand Down Expand Up @@ -44,6 +45,7 @@ class avatar : public player
bool create( character_type type, const std::string &tempname = "" );
void randomize( bool random_scenario, points_left &points, bool play_now = false );
bool load_template( const std::string &template_name, points_left &points );
static void save_template( const avatar &u, const std::string &name, const points_left &points );

bool is_avatar() const override {
return true;
Expand Down Expand Up @@ -219,4 +221,95 @@ class avatar : public player
int per_upgrade = 0;
};

struct points_left {
int stat_points;
int trait_points;
int skill_points;

enum point_limit : int {
FREEFORM = 0,
ONE_POOL,
MULTI_POOL,
TRANSFER,
} limit;

points_left() {
limit = MULTI_POOL;
init_from_options();
}

void init_from_options() {
stat_points = get_option<int>( "INITIAL_STAT_POINTS" );
trait_points = get_option<int>( "INITIAL_TRAIT_POINTS" );
skill_points = get_option<int>( "INITIAL_SKILL_POINTS" );
}

// Highest amount of points to spend on stats without points going invalid
int stat_points_left() const {
switch( limit ) {
case FREEFORM:
case ONE_POOL:
return stat_points + trait_points + skill_points;
case MULTI_POOL:
return std::min( trait_points_left(),
stat_points + std::min( 0, trait_points + skill_points ) );
case TRANSFER:
return 0;
}

return 0;
}

int trait_points_left() const {
switch( limit ) {
case FREEFORM:
case ONE_POOL:
return stat_points + trait_points + skill_points;
case MULTI_POOL:
return stat_points + trait_points + std::min( 0, skill_points );
case TRANSFER:
return 0;
}

return 0;
}

int skill_points_left() const {
return stat_points + trait_points + skill_points;
}

bool is_freeform() {
return limit == FREEFORM;
}

bool is_valid() {
return is_freeform() ||
( stat_points_left() >= 0 && trait_points_left() >= 0 &&
skill_points_left() >= 0 );
}

bool has_spare() {
return !is_freeform() && is_valid() && skill_points_left() > 0;
}

std::string to_string() {
if( limit == MULTI_POOL ) {
return string_format(
_( "Points left: <color_%s>%d</color>%c<color_%s>%d</color>%c<color_%s>%d</color>=<color_%s>%d</color>" ),
stat_points_left() >= 0 ? "light_gray" : "red", stat_points,
trait_points >= 0 ? '+' : '-',
trait_points_left() >= 0 ? "light_gray" : "red", abs( trait_points ),
skill_points >= 0 ? '+' : '-',
skill_points_left() >= 0 ? "light_gray" : "red", abs( skill_points ),
is_valid() ? "light_gray" : "red", stat_points + trait_points + skill_points );
} else if( limit == ONE_POOL ) {
return string_format( _( "Points left: %4d" ), skill_points_left() );
} else if( limit == TRANSFER ){
return _( "Character Transfer: No changes can be made." );
} else {
return _( "Freeform" );
}
}
};

#endif
39 changes: 36 additions & 3 deletions src/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ void main_menu::init_strings()
vWorldSubItems.push_back( pgettext( "Main Menu|World", "<R|r>eset World" ) );
vWorldSubItems.push_back( pgettext( "Main Menu|World", "<S|s>how World Mods" ) );
vWorldSubItems.push_back( pgettext( "Main Menu|World", "<C|c>opy World Settings" ) );
vWorldSubItems.push_back( pgettext( "Main Menu|World", "Character to <T|t>emplate" ) );

vWorldHotkeys.clear();
for( const std::string &item : vWorldSubItems ) {
Expand Down Expand Up @@ -877,8 +878,14 @@ bool main_menu::new_character_tab()
return start;
}

bool main_menu::load_character_tab()
bool main_menu::load_character_tab( bool transfer )
{
if( transfer ) {
layer = 3;
sel1 = 2;
sel2 -= 1;
}

bool start = false;
const auto all_worldnames = world_generator->all_worldnames();

Expand Down Expand Up @@ -1028,9 +1035,32 @@ bool main_menu::load_character_tab()

void main_menu::world_tab()
{
while( sel1 == 3 && ( layer == 2 || layer == 3 ) ) {
while( sel1 == 3 && ( layer == 2 || layer == 3 || layer == 4 ) ) {
print_menu( w_open, 3, menu_offset );
if( layer == 3 ) { // World Menu
if ( layer == 4 ) {
if ( load_character_tab( true ) ) {
//test_mode = true; //Prevent game drawing
//test_mode = false;

points_left points;
points.stat_points = 0;
points.trait_points = 0;
points.skill_points = 0;
points.limit = points_left::TRANSFER;
avatar::save_template(g->u, g->u.name, points);

g->uquit = QUIT_NOSAVED;
g->cleanup_at_end();

load_char_templates();

werase( w_background );
wrefresh( w_background );

layer = 3;
//sel1 = 3;
}
} else if( layer == 3 ) { // World Menu
// Show options for Destroy, Reset worlds.
// Reset and Destroy ask for world to modify.
// Reset empties world of everything but options, then makes new world within it.
Expand Down Expand Up @@ -1109,6 +1139,9 @@ void main_menu::world_tab()
} else if( sel3 == 3 ) { // Copy World settings
layer = 2;
world_generator->make_new_world( true, all_worldnames[sel2 - 1] );
} else if( sel3 == 4 ) { // Character to Template
layer = 4;
sel4 = 0;
}

if( query_yes ) {
Expand Down
3 changes: 2 additions & 1 deletion src/main_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class main_menu
// Tab functions. They return whether a game was started or not. The ones that can never
// start a game have a void return type.
bool new_character_tab();
bool load_character_tab();
bool load_character_tab( bool transfer = false );
void world_tab();

/*
Expand All @@ -67,6 +67,7 @@ class main_menu
int sel1 = 1;
int sel2 = 1;
int sel3 = 1;
int sel4 = 1;
int layer = 1;
point LAST_TERM;
catacurses::window w_open;
Expand Down
104 changes: 14 additions & 90 deletions src/newcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
#include "pimpl.h"
#include "type_id.h"

struct points_left;

// Colors used in this file: (Most else defaults to c_light_gray)
#define COL_STAT_ACT c_white // Selected stat
#define COL_STAT_BONUS c_light_green // Bonus
Expand Down Expand Up @@ -87,90 +85,6 @@ struct points_left;

static int skill_increment_cost( const Character &u, const skill_id &skill );

struct points_left {
int stat_points;
int trait_points;
int skill_points;

enum point_limit : int {
FREEFORM = 0,
ONE_POOL,
MULTI_POOL
} limit;

points_left() {
limit = MULTI_POOL;
init_from_options();
}

void init_from_options() {
stat_points = get_option<int>( "INITIAL_STAT_POINTS" );
trait_points = get_option<int>( "INITIAL_TRAIT_POINTS" );
skill_points = get_option<int>( "INITIAL_SKILL_POINTS" );
}

// Highest amount of points to spend on stats without points going invalid
int stat_points_left() const {
switch( limit ) {
case FREEFORM:
case ONE_POOL:
return stat_points + trait_points + skill_points;
case MULTI_POOL:
return std::min( trait_points_left(),
stat_points + std::min( 0, trait_points + skill_points ) );
}

return 0;
}

int trait_points_left() const {
switch( limit ) {
case FREEFORM:
case ONE_POOL:
return stat_points + trait_points + skill_points;
case MULTI_POOL:
return stat_points + trait_points + std::min( 0, skill_points );
}

return 0;
}

int skill_points_left() const {
return stat_points + trait_points + skill_points;
}

bool is_freeform() {
return limit == FREEFORM;
}

bool is_valid() {
return is_freeform() ||
( stat_points_left() >= 0 && trait_points_left() >= 0 &&
skill_points_left() >= 0 );
}

bool has_spare() {
return !is_freeform() && is_valid() && skill_points_left() > 0;
}

std::string to_string() {
if( limit == MULTI_POOL ) {
return string_format(
_( "Points left: <color_%s>%d</color>%c<color_%s>%d</color>%c<color_%s>%d</color>=<color_%s>%d</color>" ),
stat_points_left() >= 0 ? "light_gray" : "red", stat_points,
trait_points >= 0 ? '+' : '-',
trait_points_left() >= 0 ? "light_gray" : "red", abs( trait_points ),
skill_points >= 0 ? '+' : '-',
skill_points_left() >= 0 ? "light_gray" : "red", abs( skill_points ),
is_valid() ? "light_gray" : "red", stat_points + trait_points + skill_points );
} else if( limit == ONE_POOL ) {
return string_format( _( "Points left: %4d" ), skill_points_left() );
} else {
return _( "Freeform" );
}
}
};

enum struct tab_direction {
NONE,
FORWARD,
Expand All @@ -190,7 +104,6 @@ tab_direction set_description( const catacurses::window &w, avatar &you, bool al
points_left &points );

static cata::optional<std::string> query_for_template_name();
static void save_template( const avatar &u, const std::string &name, const points_left &points );
void reset_scenario( avatar &u, const scenario *scen );

void Character::pick_name( bool bUseDefault )
Expand Down Expand Up @@ -465,7 +378,9 @@ bool avatar::create( character_type type, const std::string &tempname )
}
// We want to prevent recipes known by the template from being applied to the
// new character. The recipe list will be rebuilt when entering the game.
learned_recipes->clear();
if( points.limit != points_left::TRANSFER ) {
learned_recipes->clear();
}
tab = NEWCHAR_TAB_MAX;
break;
}
Expand All @@ -491,6 +406,11 @@ bool avatar::create( character_type type, const std::string &tempname )
}
werase( w );
wrefresh( w );

if( points.limit == points_left::TRANSFER ) {
tab = 6;
}

switch( tab ) {
case 0:
result = set_points( w, *this, points );
Expand Down Expand Up @@ -543,6 +463,10 @@ bool avatar::create( character_type type, const std::string &tempname )
return false;
}

if( points.limit == points_left::TRANSFER ) {
return true;
}

save_template( *this, _( "Last Character" ), points );

recalc_hp();
Expand Down Expand Up @@ -2434,7 +2358,7 @@ tab_direction set_description( const catacurses::window &w, avatar &you, const b
return tab_direction::NONE;
} else if( action == "SAVE_TEMPLATE" ) {
if( const auto name = query_for_template_name() ) {
::save_template( you, *name, points );
avatar::save_template( you, *name, points );
}
// redraw after saving template
draw_character_tabs( w, _( "DESCRIPTION" ) );
Expand Down Expand Up @@ -2607,7 +2531,7 @@ cata::optional<std::string> query_for_template_name()
}
}

void save_template( const avatar &u, const std::string &name, const points_left &points )
void avatar::save_template( const avatar &u, const std::string &name, const points_left &points )
{
std::string native = utf8_to_native( name );
#if defined(_WIN32)
Expand Down

0 comments on commit 6a6499e

Please sign in to comment.