Skip to content
Permalink
Browse files

Cleanup style in the dodge system rewrite.

  • Loading branch information...
kevingranade committed May 11, 2013
2 parents dbbc4fe + f28e427 commit ed836648888b0c7a47ca3c29e4e6cd82e2dac0a1
Showing with 311 additions and 205 deletions.
  1. +1 −0 data/changelog.txt
  2. +35 −33 melee.cpp
  3. +69 −49 monattack.cpp
  4. +205 −115 monmove.cpp
  5. +0 −7 monster.cpp
  6. +1 −1 mtype.h
@@ -118,6 +118,7 @@ Stop roads from going through buildings so often.
Pits less awkward to board over (can use nearby items).
Tweak glass bottle weight/volume.
Allow for reading/sewing in the dark through mutations/CBM's with a speed penalty.
Rewrote dodge abilities to have a noticeable impact.


0.4
@@ -452,44 +452,46 @@ bool player::scored_crit(int target_dodge)
}

int player::dodge(game *g)
//Returns 1/2*DEX + dodge skill level + static bonuses from mutations
//Return numbers range from around 4 (starting player, no boosts) to 29 (20 DEX, 10 dodge, +9 mutations)
{
if (has_disease(DI_SLEEP) || has_disease(DI_LYING_DOWN))
return 0;
if (activity.type != ACT_NULL)
return 0;
int ret = 4 + (dex_cur / 2);
ret += skillLevel("dodge");
ret += disease_intensity(DI_DODGE_BOOST);
ret -= (encumb(bp_legs) / 2) + encumb(bp_torso);
ret += int(current_speed(g) / 150);
if (has_trait(PF_TAIL_LONG))
ret += 4;
if (has_trait(PF_TAIL_FLUFFY))
ret += 8;
if (has_trait(PF_WHISKERS))
ret += 1;
if (has_trait(PF_WINGS_BAT))
ret -= 3;
if (str_max >= 16)
ret--; // Penalty if we're hyuuge
else if (str_max <= 5)
ret++; // Bonus if we're small
if (dodges_left <= 0) { // We already dodged this turn
if (rng(1, skillLevel("dodge") + dex_cur + 15) <= skillLevel("dodge") + dex_cur)
ret = rng(0, ret);
else
ret = 0;
}
dodges_left--;
// If we're over our cap, average it with our cap
if (ret > int(dex_cur / 2) + skillLevel("dodge") * 2)
ret = ( ret + int(dex_cur / 2) + skillLevel("dodge") * 2 ) / 2;
return ret;
//If we're asleep or busy we can't dodge
if (has_disease(DI_SLEEP) || has_disease(DI_LYING_DOWN)) {return 0;}
if (activity.type != ACT_NULL) {return 0;}

int ret = (dex_cur / 2);
ret += skillLevel("dodge");
ret += disease_intensity(DI_DODGE_BOOST);
ret -= (encumb(bp_legs) / 2) + encumb(bp_torso);
ret += int(current_speed(g) / 150); //Faster = small dodge advantage

//Mutations
if (has_trait(PF_TAIL_LONG)) {ret += 4;}
if (has_trait(PF_TAIL_FLUFFY)) {ret += 8;}
if (has_trait(PF_WHISKERS)) {ret += 1;}
if (has_trait(PF_WINGS_BAT)) {ret -= 3;}

if (str_max >= 16) {ret--;} // Penalty if we're huge
else if (str_max <= 5) {ret++;} // Bonus if we're small

if (dodges_left <= 0) // We already dodged this turn
{
if (rng(0, skillLevel("dodge") + dex_cur + 15) <= skillLevel("dodge") + dex_cur)
{
ret = rng(ret/2, ret); //Penalize multiple dodges per turn
}
else
{
ret = 0;
}
}
dodges_left--;
return ret;
}

int player::dodge_roll(game *g)
{
return dice(dodge(g), 6);
return dice(dodge(g), 10); //Matches NPC and monster dodge_roll functions
}

int player::base_damage(bool real_life, int stat)
@@ -5,6 +5,10 @@
#include "line.h"
#include "bodypart.h"

//Used for e^(x) functions
#include <stdio.h>
#include <math.h>

void mattack::antqueen(game *g, monster *z)
{
std::vector<point> egg_points;
@@ -184,6 +188,7 @@ void mattack::boomer(game *g, monster *z)
g->u.infect(DI_BOOMERED, bp_eyes, 3, 12, g);
else if (u_see)
g->add_msg("You dodge it!");
g->u.practice(g->turn, "dodge", 10);
}

void mattack::resurrect(game *g, monster *z)
@@ -694,7 +699,7 @@ void mattack::leap(game *g, monster *z)
if (!blocked_path && g->is_empty(x, y) &&
g->m.sees(z->posx, z->posy, x, y, g->light_level(), linet) &&
(( fleeing && rl_dist(g->u.posx, g->u.posy, x, y) >= best) ||
(!fleeing && rl_dist(g->u.posx, g->u.posy, x, y) <= best) ))
(!fleeing && rl_dist(g->u.posx, g->u.posy, x, y) <= best) ))
{
options.push_back( point(x, y) );
best = rl_dist(g->u.posx, g->u.posy, x, y);
@@ -704,10 +709,10 @@ void mattack::leap(game *g, monster *z)
}

// Go back and remove all options that aren't tied for best
for (int i = 0; i < options.size() && options.size() > 1; i++)
for (int i = 0; i < options.size() && options.size() > 1; i++)
{
point p = options[i];
if (rl_dist(g->u.posx, g->u.posy, options[i].x, options[i].y) != best)
if (rl_dist(g->u.posx, g->u.posy, options[i].x, options[i].y) != best)
{
options.erase(options.begin() + i);
i--;
@@ -736,14 +741,15 @@ void mattack::dermatik(game *g, monster *z)

z->sp_timeout = z->type->sp_freq; // Reset timer

// Can we dodge the attack?
int attack_roll = dice(z->type->melee_skill, 10);
int player_dodge = g->u.dodge_roll(g);
if (player_dodge > attack_roll) {
g->add_msg("The %s tries to land on you, but you dodge.", z->name().c_str());
z->stumble(g, false);
return;
}
// Can we dodge the attack? Uses player dodge function % chance (melee.cpp)
int dodge_check = std::max(g->u.dodge(g) - rng(0, z->type->melee_skill), 0L);
if (rng(0, 10000) < 10000 / (1 + (99 * exp(-.6 * dodge_check))))
{
g->add_msg("The %s tries to land on you, but you dodge.", z->name().c_str());
z->stumble(g, false);
g->u.practice(g->turn, "dodge", z->type->melee_skill * 2);
return;
}

// Can we swat the bug away?
int dodge_roll = z->dodge_roll();
@@ -871,29 +877,35 @@ void mattack::dogthing(game *g, monster *z)

void mattack::tentacle(game *g, monster *z)
{
int t;
if (!g->sees_u(z->posx, z->posy, t))
return;

g->add_msg("The %s lashes its tentacle at you!", z->name().c_str());
z->moves -= 100;
z->sp_timeout = z->type->sp_freq; // Reset timer
int t;
if (!g->sees_u(z->posx, z->posy, t))
{
return;
}
g->add_msg("The %s lashes its tentacle at you!", z->name().c_str());
z->moves -= 100;
z->sp_timeout = z->type->sp_freq; // Reset timer

std::vector<point> line = line_to(z->posx, z->posy, g->u.posx, g->u.posy, t);
for (int i = 0; i < line.size(); i++) {
int tmpdam = 20;
g->m.shoot(g, line[i].x, line[i].y, tmpdam, true, 0);
}
std::vector<point> line = line_to(z->posx, z->posy, g->u.posx, g->u.posy, t);
for (int i = 0; i < line.size(); i++)
{
int tmpdam = 20;
g->m.shoot(g, line[i].x, line[i].y, tmpdam, true, 0);
}

if (rng(0, 20) > g->u.dodge(g) || one_in(g->u.dodge(g))) {
body_part hit = random_body_part();
int dam = rng(10, 20), side = rng(0, 1);
g->add_msg("Your %s is hit for %d damage!", body_part_name(hit, side).c_str(),
dam);
g->u.hit(g, hit, side, dam, 0);
return;
}
g->add_msg("You dodge it!");
// Can we dodge the attack? Uses player dodge function % chance (melee.cpp)
int dodge_check = std::max(g->u.dodge(g) - rng(0, z->type->melee_skill), 0L);
if (rng(0, 10000) < 10000 / (1 + (99 * exp(-.6 * dodge_check))))
{
g->add_msg("You dodge it!");
g->u.practice(g->turn, "dodge", z->type->melee_skill*2);
return;
}
body_part hit = random_body_part();
int dam = rng(10, 20), side = rng(0, 1);
g->add_msg("Your %s is hit for %d damage!", body_part_name(hit, side).c_str(), dam);
g->u.hit(g, hit, side, dam, 0);
g->u.practice(g->turn, "dodge", z->type->melee_skill);
}

void mattack::vortex(game *g, monster *z)
@@ -1403,22 +1415,30 @@ void mattack::breathe(game *g, monster *z)

void mattack::bite(game *g, monster *z)
{
if (rl_dist(z->posx, z->posy, g->u.posx, g->u.posy) > 1)
return;
z->sp_timeout = z->type->sp_freq; // Reset timer
g->add_msg("The %s lunges forward attempting to bite you!", z->name().c_str());
z->moves -= 100;
if (rng(0, 20) > g->u.dodge(g) || one_in(g->u.dodge(g))) {
body_part hit = random_body_part();
int dam = rng(5, 10), side = rng(0, 1);
g->add_msg("Your %s is bitten for %d damage!", body_part_name(hit, side).c_str(),
dam);
g->u.hit(g, hit, side, dam, 0);
if(one_in(10)){
g->u.add_disease(DI_BITE, 3600, g);
}
return;
}
g->add_msg("You dodge it!");
if (rl_dist(z->posx, z->posy, g->u.posx, g->u.posy) > 1)
{
return;
}
z->sp_timeout = z->type->sp_freq; // Reset timer
g->add_msg("The %s lunges forward attempting to bite you!", z->name().c_str());
z->moves -= 100;

// Can we dodge the attack? Uses player dodge function % chance (melee.cpp)
int dodge_check = std::max(g->u.dodge(g) - rng(0, z->type->melee_skill), 0L);
if (rng(0, 10000) < 10000 / (1 + (99 * exp(-.6 * dodge_check))))
{
g->add_msg("You dodge it!");
g->u.practice(g->turn, "dodge", z->type->melee_skill*2);
return;
}
body_part hit = random_body_part();
int dam = rng(5, 10), side = rng(0, 1);
g->add_msg("Your %s is bitten for %d damage!", body_part_name(hit, side).c_str(), dam);
g->u.hit(g, hit, side, dam, 0);
if(one_in(10))
{
g->u.add_disease(DI_BITE, 3600, g);
}
g->u.practice(g->turn, "dodge", z->type->melee_skill);
}

0 comments on commit ed83664

Please sign in to comment.
You can’t perform that action at this time.