expr_t* cooldown_t::create_expression( action_t*, const std::string& name_str ) { if ( name_str == "remains" ) return make_mem_fn_expr( name_str, *this, &cooldown_t::remains ); else if ( name_str == "duration" ) return make_mem_fn_expr( name_str, *this, &cooldown_t::duration ); else if ( name_str == "up" ) return make_mem_fn_expr( name_str, *this, &cooldown_t::up ); else if ( name_str == "charges" ) return make_ref_expr( name_str, current_charge ); else if ( name_str == "charges_fractional" ) { struct charges_fractional_expr_t : public expr_t { const cooldown_t* cd; charges_fractional_expr_t( const cooldown_t* c ) : expr_t( "charges_fractional" ), cd( c ) { } virtual double evaluate() { double charges = cd -> current_charge; if ( cd -> recharge_event ) { recharge_event_t* re = debug_cast<recharge_event_t*>( cd -> recharge_event ); charges += 1 - ( re -> remains() / re -> event_duration_ ); } return charges; } }; return new charges_fractional_expr_t( this ); } else if ( name_str == "recharge_time" ) { struct recharge_time_expr_t : public expr_t { const cooldown_t* cd; recharge_time_expr_t( const cooldown_t* c ) : expr_t( "recharge_time" ), cd( c ) { } virtual double evaluate() { if ( cd -> recharge_event ) return cd -> recharge_event -> remains().total_seconds(); else return cd -> duration.total_seconds(); } }; return new recharge_time_expr_t( this ); } else if ( name_str == "max_charges" ) return make_ref_expr( name_str, charges ); return nullptr; }
expr_t* cooldown_t::create_expression( action_t*, const std::string& name_str ) { if ( name_str == "remains" ) return make_mem_fn_expr( name_str, *this, &cooldown_t::remains ); else if ( name_str == "duration" ) return make_ref_expr( name_str, duration ); else if ( name_str == "up" ) return make_mem_fn_expr( name_str, *this, &cooldown_t::up ); return nullptr; }