Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial cleanup of melee code #18697

Merged
merged 24 commits into from Oct 9, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -897,8 +897,6 @@ classes = {
{ name = "cut_resist", rval = "int", args = { } },
{ name = "cut_resist", rval = "int", args = { "bool" } },
{ name = "damage", rval = "int", args = { } },
{ name = "damage_bash", rval = "int", args = { } },
{ name = "damage_cut", rval = "int", args = { } },
{ name = "deserialize", rval = nil, args = { "string" } },
{ name = "destroyed_at_zero_charges", rval = "bool", args = { } },
{ name = "display_name", rval = "string", args = { "int" } },
@@ -970,14 +968,12 @@ classes = {
{ name = "is_ammo_container", rval = "bool", args = { } },
{ name = "is_armor", rval = "bool", args = { } },
{ name = "is_artifact", rval = "bool", args = { } },
{ name = "is_bashing_weapon", rval = "bool", args = { } },
{ name = "is_bionic", rval = "bool", args = { } },
{ name = "is_book", rval = "bool", args = { } },
{ name = "is_container", rval = "bool", args = { } },
{ name = "is_container_empty", rval = "bool", args = { } },
{ name = "is_container_full", rval = "bool", args = { } },
{ name = "is_corpse", rval = "bool", args = { } },
{ name = "is_cutting_weapon", rval = "bool", args = { } },
{ name = "is_dangerous", rval = "bool", args = { } },
{ name = "is_emissive", rval = "bool", args = { } },
{ name = "is_firearm", rval = "bool", args = { } },
@@ -1000,7 +996,7 @@ classes = {
{ name = "is_tool_reversible", rval = "bool", args = { } },
{ name = "is_two_handed", rval = "bool", args = { "player" } },
{ name = "is_watertight_container", rval = "bool", args = { } },
{ name = "is_weap", rval = "bool", args = { } },
{ name = "is_melee", rval = "bool", args = { } },
{ name = "label", rval = "string", args = { } },
{ name = "label", rval = "string", args = { "int" } },
{ name = "charges_per_volume", rval = "int", args = { "volume" } },
@@ -1053,7 +1049,7 @@ classes = {
{ name = "type_name", rval = "string", args = { "int" } },
{ name = "type_name", rval = "string", args = { } },
{ name = "volume", rval = "volume", args = { } },
{ name = "weap_skill", rval = "skill_id", args = { } },
{ name = "melee_skill", rval = "skill_id", args = { } },
{ name = "weight", rval = "int", args = { } },
}
},
@@ -1907,8 +1903,6 @@ classes = {
light_emission = { type = "int", writable = true },
m_to_hit = { type = "int", writable = true },
magazine_well = { type = "volume", writable = true },
melee_cut = { type = "int", writable = true },
melee_dam = { type = "int", writable = true },
min_dex = { type = "int", writable = true },
min_int = { type = "int", writable = true },
min_per = { type = "int", writable = true },
@@ -1030,18 +1030,15 @@ void activity_handlers::pulp_do_turn( player_activity *act, player *p )
{
const tripoint &pos = act->placement;

int cut_power = p->weapon.type->melee_cut;
// Stabbing weapons are a lot less effective at pulping
if( p->weapon.has_flag("STAB") || p->weapon.has_flag("SPEAR") ) {
cut_power /= 2;
}
int cut_power = std::max( p->weapon.damage_melee( DT_CUT ), p->weapon.damage_melee( DT_STAB ) / 2 );

// Slicing weapons are a moderately less effective at pulping
if( p->weapon.has_flag("SLICE") ) {
cut_power = cut_power * 2 / 3;
}
///\EFFECT_STR increases pulping power, with diminishing returns
float pulp_power = sqrt( (p->str_cur + p->weapon.type->melee_dam) * ( cut_power + 1.0f ) );
float pulp_power = sqrt( ( p->str_cur + p->weapon.damage_melee( DT_BASH ) ) * ( cut_power + 1.0f ) );
// Multiplier to get the chance right + some bonus for survival skill
pulp_power *= 40 + p->get_skill_level( skill_survival ) * 5;

@@ -675,8 +675,8 @@ std::string new_artifact()
art->weight = rng(info->weight_min, info->weight_max);
// Set up the basic weapon type
artifact_weapon_datum *weapon = &(artifact_weapon_data[info->base_weapon]);
art->melee_dam = rng(weapon->bash_min, weapon->bash_max);
art->melee_cut = rng(weapon->cut_min, weapon->cut_max);
art->melee[DT_BASH] = rng(weapon->bash_min, weapon->bash_max);
art->melee[DT_CUT] = rng(weapon->cut_min, weapon->cut_max);
art->m_to_hit = rng(weapon->to_hit_min, weapon->to_hit_max);
if( weapon->tag != "" ) {
art->item_tags.insert(weapon->tag);
@@ -688,8 +688,8 @@ std::string new_artifact()
weapon = &(artifact_weapon_data[ info->extra_weapons[select] ]);
art->volume += weapon->volume;
art->weight += weapon->weight;
art->melee_dam += rng(weapon->bash_min, weapon->bash_max);
art->melee_cut += rng(weapon->cut_min, weapon->cut_max);
art->melee[DT_BASH] += rng(weapon->bash_min, weapon->bash_max);
art->melee[DT_CUT] += rng(weapon->cut_min, weapon->cut_max);
art->m_to_hit += rng(weapon->to_hit_min, weapon->to_hit_max);
if( weapon->tag != "" ) {
art->item_tags.insert(weapon->tag);
@@ -796,8 +796,8 @@ std::string new_artifact()
art->materials.push_back(info->material);
art->volume = info->volume;
art->weight = info->weight;
art->melee_dam = info->melee_bash;
art->melee_cut = info->melee_cut;
art->melee[DT_BASH] = info->melee_bash;
art->melee[DT_CUT] = info->melee_cut;
art->m_to_hit = info->melee_hit;
art->armor->covers = info->covers;
art->armor->encumber = info->encumb;
@@ -910,8 +910,8 @@ std::string new_natural_artifact(artifact_natural_property prop)
art->materials.push_back( material_id( "stone" ) );
art->volume = rng(shape_data->volume_min, shape_data->volume_max);
art->weight = rng(shape_data->weight_min, shape_data->weight_max);
art->melee_dam = 0;
art->melee_cut = 0;
art->melee[DT_BASH] = 0;
art->melee[DT_CUT] = 0;
art->m_to_hit = 0;

art->create_name(property_data->name, shape_data->name);
@@ -1011,8 +1011,8 @@ std::string architects_cube()
art->weight = rng(info->weight_min, info->weight_max);
// Set up the basic weapon type
artifact_weapon_datum *weapon = &(artifact_weapon_data[info->base_weapon]);
art->melee_dam = rng(weapon->bash_min, weapon->bash_max);
art->melee_cut = rng(weapon->cut_min, weapon->cut_max);
art->melee[DT_BASH] = rng(weapon->bash_min, weapon->bash_max);
art->melee[DT_CUT] = rng(weapon->cut_min, weapon->cut_max);
art->m_to_hit = rng(weapon->to_hit_min, weapon->to_hit_max);
if( weapon->tag != "" ) {
art->item_tags.insert(weapon->tag);
@@ -1125,8 +1125,8 @@ void it_artifact_tool::deserialize(JsonObject &jo)
}
volume = jo.get_int("volume") * units::legacy_volume_factor;
weight = jo.get_int("weight");
melee_dam = jo.get_int("melee_dam");
melee_cut = jo.get_int("melee_cut");
melee[DT_BASH] = jo.get_int("melee_dam");
melee[DT_CUT] = jo.get_int("melee_cut");
m_to_hit = jo.get_int("m_to_hit");
item_tags = jo.get_tags("item_flags");

@@ -1195,8 +1195,8 @@ void it_artifact_armor::deserialize(JsonObject &jo)
}
volume = jo.get_int("volume") * units::legacy_volume_factor;
weight = jo.get_int("weight");
melee_dam = jo.get_int("melee_dam");
melee_cut = jo.get_int("melee_cut");
melee[DT_BASH] = jo.get_int("melee_dam");
melee[DT_CUT] = jo.get_int("melee_cut");
m_to_hit = jo.get_int("m_to_hit");
item_tags = jo.get_tags("item_flags");

@@ -1265,8 +1265,10 @@ void it_artifact_tool::serialize(JsonOut &json) const
json.end_array();
json.member("volume", volume / units::legacy_volume_factor);
json.member("weight", weight);
json.member("melee_dam", melee_dam);
json.member("melee_cut", melee_cut);

json.member( "melee_dam", melee[DT_BASH] );
json.member( "melee_cut", melee[DT_CUT] );

json.member("m_to_hit", m_to_hit);

json.member("item_flags", item_tags);
@@ -1310,8 +1312,10 @@ void it_artifact_armor::serialize(JsonOut &json) const
json.end_array();
json.member("volume", volume / units::legacy_volume_factor);
json.member("weight", weight);
json.member("melee_dam", melee_dam);
json.member("melee_cut", melee_cut);

json.member( "melee_dam", melee[DT_BASH] );
json.member( "melee_cut", melee[DT_CUT] );

json.member("m_to_hit", m_to_hit);

json.member("item_flags", item_tags);
@@ -592,7 +592,7 @@ item& Character::i_add(item it)
last_item = item_type_id;

if( it.is_food() || it.is_ammo() || it.is_gun() || it.is_armor() ||
it.is_book() || it.is_tool() || it.is_weap() || it.is_food_container() ) {
it.is_book() || it.is_tool() || it.is_melee() || it.is_food_container() ) {
inv.unsort();
}

@@ -202,6 +202,27 @@ const std::string &name_by_dt( const damage_type &dt )
return err_msg;
}

const skill_id &skill_by_dt( damage_type dt )
{
static skill_id skill_bashing( "bashing" );
static skill_id skill_cutting( "cutting" );
static skill_id skill_stabbing( "stabbing" );

switch( dt ) {
case DT_BASH:
return skill_bashing;

case DT_CUT:
return skill_cutting;

case DT_STAB:
return skill_stabbing;

default:
return NULL_ID;
}
}

damage_unit load_damage_unit( JsonObject &curr )
{
damage_type dt = dt_by_name( curr.get_string( "damage_type" ) );
@@ -2,6 +2,7 @@
#define DAMAGE_H

#include "enums.h"
#include "string_id.h"
#include <string>
#include <vector>
#include <set>
@@ -11,6 +12,9 @@ class item;
class monster;
class JsonObject;

class Skill;
using skill_id = string_id<Skill>;

enum body_part : int;

enum damage_type : int {
@@ -86,6 +90,8 @@ struct resistances {
damage_type dt_by_name( const std::string &name );
const std::string &name_by_dt( const damage_type &dt );

const skill_id &skill_by_dt( damage_type dt );

damage_instance load_damage_instance( JsonObject &jo );
damage_instance load_damage_instance( JsonArray &jarr );

@@ -7417,7 +7417,7 @@ void game::smash()
const int move_cost = !u.is_armed() ? 80 : u.weapon.attack_time() * 0.8;
bool didit = false;
///\EFFECT_STR increases smashing capability
int smashskill = int(u.str_cur + u.weapon.type->melee_dam);
int smashskill = u.str_cur + u.weapon.damage_melee( DT_BASH );
tripoint smashp;

const bool allow_floor_bash = debug_mode; // Should later become "true"
@@ -97,4 +97,10 @@ constexpr double accuracy_goodhit = 0.5;
constexpr double accuracy_standard = 0.8;
constexpr double accuracy_grazing = 1.0;

/** Minimum item damage output of relevant type to allow using with relevant weapon skill */
#define MELEE_STAT 5

This comment has been minimized.

Copy link
@Coolthulhu

Coolthulhu Oct 9, 2016

Contributor

That name is really ambiguous.
The old option - having is_cutting_weapon etc. was better.
Could be combined into is_weapon( damage_type ) - this would be both clear and centralized.

This comment has been minimized.

Copy link
@mugling

mugling Oct 9, 2016

Author Contributor

Or is_melee( damage_type ) to combine it with @codemime's suggestion

This comment has been minimized.

Copy link
@mugling

mugling Oct 9, 2016

Author Contributor

I've updated that retaining the constant only so that item_factory.cpp assigns the weapon category consistently with the check in is_melee()


/** Effective lower bound to combat skill levels when CQB bionic is active */
#define BIO_CQB_LEVEL 5

#endif
@@ -60,7 +60,7 @@ void iexamine::none(player &p, const tripoint &examp)
void iexamine::cvdmachine( player &p, const tripoint & ) {
// Select an item to which it is possible to apply a diamond coating
auto loc = g->inv_map_splice( []( const item &e ) {
return e.is_cutting_weapon() && e.made_of( material_id( "steel" ) ) &&
return e.is_melee( DT_CUT ) && e.made_of( material_id( "steel" ) ) &&
!e.has_flag( "DIAMOND" ) && !e.has_flag( "NO_CVD" );
}, _( "Apply diamond coating" ), 1, _( "You don't have a suitable item to coat with diamond" ) );

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.