Skip to content

Commit

Permalink
Merge pull request #76696 from mqrause/spell_typed_tripoints
Browse files Browse the repository at this point in the history
Use typed tripoints in magic.h and adjacent code
  • Loading branch information
Maleclypse authored Sep 29, 2024
2 parents 8cef429 + 8981dd6 commit 5845b32
Show file tree
Hide file tree
Showing 33 changed files with 394 additions and 373 deletions.
4 changes: 2 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3798,8 +3798,8 @@ void activity_handlers::spellcasting_finish( player_activity *act, Character *yo
}

// choose target for spell before continuing
const std::optional<tripoint> target = act->coords.empty() ? spell_being_cast.select_target(
you ) : get_map().bub_from_abs( act->coords.front() ).raw();
const std::optional<tripoint_bub_ms> target = act->coords.empty() ? spell_being_cast.select_target(
you ) : get_map().bub_from_abs( act->coords.front() );
if( target ) {
// npcs check for target viability
if( !you->is_npc() || spell_being_cast.is_valid_target( *you, *target ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8439,8 +8439,8 @@ void Character::spores()
fungal_effects fe;
//~spore-release sound
sounds::sound( pos(), 10, sounds::sound_t::combat, _( "Pouf!" ), false, "misc", "puff" );
for( const tripoint &sporep : here.points_in_radius( pos(), 1 ) ) {
if( sporep == pos() ) {
for( const tripoint_bub_ms &sporep : here.points_in_radius( pos_bub(), 1 ) ) {
if( sporep == pos_bub() ) {
continue;
}
fe.fungalize( sporep, this, 0.25 );
Expand Down
21 changes: 11 additions & 10 deletions src/fungal_effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "calendar.h"
#include "character.h"
#include "coordinates.h"
#include "creature.h"
#include "creature_tracker.h"
#include "debug.h"
Expand Down Expand Up @@ -55,7 +56,7 @@ static const ter_str_id ter_t_tree_fungal_young( "t_tree_fungal_young" );
static const trait_id trait_TAIL_CATTLE( "TAIL_CATTLE" );
static const trait_id trait_THRESH_MYCUS( "THRESH_MYCUS" );

void fungal_effects::fungalize( const tripoint &p, Creature *origin, double spore_chance )
void fungal_effects::fungalize( const tripoint_bub_ms &p, Creature *origin, double spore_chance )
{
Character &player_character = get_player_character();
if( monster *const mon_ptr = get_creature_tracker().creature_at<monster>( p ) ) {
Expand All @@ -68,7 +69,7 @@ void fungal_effects::fungalize( const tripoint &p, Creature *origin, double spor
critter.add_effect( effect_stunned, rng( 1_turns, 3_turns ) );
critter.apply_damage( origin, bodypart_id( "torso" ), rng( 25, 50 ) );
}
} else if( player_character.pos() == p ) {
} else if( player_character.pos_bub() == p ) {
// TODO: Make this accept NPCs when they understand fungals
///\EFFECT_DEX increases chance of knocking fungal spores away with your TAIL_CATTLE
///\EFFECT_MELEE increases chance of knocking fungal sports away with your TAIL_CATTLE
Expand Down Expand Up @@ -115,14 +116,14 @@ void fungal_effects::fungalize( const tripoint &p, Creature *origin, double spor
}
}

void fungal_effects::create_spores( const tripoint &p, Creature *origin )
void fungal_effects::create_spores( const tripoint_bub_ms &p, Creature *origin )
{
for( const tripoint &tmp : get_map().points_in_radius( p, 1 ) ) {
for( const tripoint_bub_ms &tmp : get_map().points_in_radius( p, 1 ) ) {
fungalize( tmp, origin, 0.25 );
}
}

void fungal_effects::marlossify( const tripoint &p )
void fungal_effects::marlossify( const tripoint_bub_ms &p )
{
map &here = get_map();
const ter_t &terrain = here.ter( p ).obj();
Expand All @@ -141,7 +142,7 @@ void fungal_effects::marlossify( const tripoint &p )
}
}

void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth )
void fungal_effects::spread_fungus_one_tile( const tripoint_bub_ms &p, const int growth )
{
map &here = get_map();
bool converted = false;
Expand Down Expand Up @@ -239,19 +240,19 @@ void fungal_effects::spread_fungus_one_tile( const tripoint &p, const int growth
} );
if( seed == items.end() || !seed->is_seed() ) {
DebugLog( D_ERROR, DC_ALL ) << "No seed item in the PLANT terrain at position " <<
string_format( "%d,%d,%d.", p.x, p.y, p.z );
p.to_string_writable();
} else {
*seed = item( "fungal_seeds", calendar::turn );
}
}
}
}

void fungal_effects::spread_fungus( const tripoint &p )
void fungal_effects::spread_fungus( const tripoint_bub_ms &p )
{
int growth = 1;
map &here = get_map();
for( const tripoint &tmp : here.points_in_radius( p, 1 ) ) {
for( const tripoint_bub_ms &tmp : here.points_in_radius( p, 1 ) ) {
if( tmp == p ) {
continue;
}
Expand All @@ -267,7 +268,7 @@ void fungal_effects::spread_fungus( const tripoint &p )
if( growth == 9 ) {
return;
}
for( const tripoint &dest : here.points_in_radius( p, 1 ) ) {
for( const tripoint_bub_ms &dest : here.points_in_radius( p, 1 ) ) {
// One spread on average
if( !here.has_flag( ter_furn_flag::TFLAG_FUNGUS, dest ) && one_in( 9 - growth ) ) {
//growth chance is 100 in X simplified
Expand Down
13 changes: 7 additions & 6 deletions src/fungal_effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
#ifndef CATA_SRC_FUNGAL_EFFECTS_H
#define CATA_SRC_FUNGAL_EFFECTS_H

struct tripoint;
#include "coords_fwd.h"

class Creature;

class fungal_effects
{
public:
void marlossify( const tripoint &p );
void marlossify( const tripoint_bub_ms &p );
/** Makes spores at p. source is used for kill counting */
void create_spores( const tripoint &p, Creature *origin = nullptr );
void fungalize( const tripoint &p, Creature *origin = nullptr, double spore_chance = 0.0 );
void create_spores( const tripoint_bub_ms &p, Creature *origin = nullptr );
void fungalize( const tripoint_bub_ms &p, Creature *origin = nullptr, double spore_chance = 0.0 );

void spread_fungus( const tripoint &p );
void spread_fungus_one_tile( const tripoint &p, int growth );
void spread_fungus( const tripoint_bub_ms &p );
void spread_fungus_one_tile( const tripoint_bub_ms &p, int growth );
};

#endif // CATA_SRC_FUNGAL_EFFECTS_H
2 changes: 1 addition & 1 deletion src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ void iexamine::fungus( Character &you, const tripoint &examp )
{
map &here = get_map();
add_msg( _( "The %s crumbles into spores!" ), here.furnname( examp ) );
fungal_effects().create_spores( examp, &you );
fungal_effects().create_spores( tripoint_bub_ms( examp ), &you );
here.furn_set( examp, furn_str_id::NULL_ID() );
you.mod_moves( -to_moves<int>( 1_seconds ) * 0.5 );
}
Expand Down
6 changes: 3 additions & 3 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,11 +1248,11 @@ static void spawn_spores( const Character &p )
map &here = get_map();
fungal_effects fe;
creature_tracker &creatures = get_creature_tracker();
for( const tripoint &dest : closest_points_first( p.pos(), 4 ) ) {
for( const tripoint_bub_ms &dest : closest_points_first( p.pos_bub(), 4 ) ) {
if( here.impassable( dest ) ) {
continue;
}
float dist = rl_dist( dest, p.pos() );
float dist = rl_dist( dest, p.pos_bub() );
if( x_in_y( 1, dist ) ) {
fe.marlossify( dest );
}
Expand Down Expand Up @@ -1517,7 +1517,7 @@ std::optional<int> iuse::mycus( Character *p, item *, const tripoint & )
_( "As, in time, shall we adapt to better welcome those who have not received us." ) );*/
map &here = get_map();
fungal_effects fe;
for( const tripoint &nearby_pos : here.points_in_radius( p->pos(), 3 ) ) {
for( const tripoint_bub_ms &nearby_pos : here.points_in_radius( p->pos_bub(), 3 ) ) {
if( here.move_cost( nearby_pos ) != 0 && !here.has_furn( nearby_pos ) &&
!here.has_flag( ter_furn_flag::TFLAG_DEEP_WATER, nearby_pos ) &&
!here.has_flag( ter_furn_flag::TFLAG_NO_FLOOR, nearby_pos ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ std::optional<int> cast_spell_actor::use( Character *p, item &it, const tripoint

// Spell is being cast from a non-held item
if( p == nullptr ) {
casting.cast_all_effects( pos );
casting.cast_all_effects( tripoint_bub_ms( pos ) );
return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions src/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ std::vector<point> squares_in_direction( const point &p1, const point &p2 );
// Currently limited to the same z-level as @from.
std::vector<tripoint> squares_closer_to( const tripoint &from, const tripoint &to );
void calc_ray_end( units::angle, int range, const tripoint &p, tripoint &out );
template<typename Point, coords::origin Origin, coords::scale Scale>
void calc_ray_end( units::angle angle, int range,
const coords::coord_point_ob<Point, Origin, Scale> &p,
coords::coord_point_ob<Point, Origin, Scale> &out )
{
calc_ray_end( angle, range, p.raw(), out.raw() );
}
/**
* Calculates the horizontal angle between the lines from (0,0,0) to @p a and
* the line from (0,0,0) to @p b.
Expand Down
Loading

0 comments on commit 5845b32

Please sign in to comment.