From 242fd65824c5bcccf29600f9d4074f9d04f3a578 Mon Sep 17 00:00:00 2001 From: Terane436 Date: Fri, 14 Jan 2022 11:04:33 +0100 Subject: [PATCH] (partial merge of 97f0723a4c69580457a4e1ba4b0ff60ecd4e2621) Preparations to support easily adding fields --- src/universe/party.cpp | 42 ++++++------ src/universe/universe.cpp | 130 -------------------------------------- src/universe/universe.hpp | 126 +++++++++++++++++++----------------- 3 files changed, 90 insertions(+), 208 deletions(-) diff --git a/src/universe/party.cpp b/src/universe/party.cpp index 69d45e95..e374401c 100644 --- a/src/universe/party.cpp +++ b/src/universe/party.cpp @@ -582,56 +582,56 @@ int cParty::get_shared_dmg(int) const { int cParty::get_health() const { int health = 0; - for(int i = 0; i < 6; i++) - if(adven[i]->is_alive()) - health += adven[i]->cur_health; + for(auto pc : adven) + if (pc && pc->is_alive()) + health += pc->cur_health; return health; } int cParty::get_magic() const { int magic = 0; - for(int i = 0; i < 6; i++) - if(adven[i]->is_alive()) - magic += adven[i]->cur_sp; + for(auto pc : adven) + if (pc && pc->is_alive()) + magic += pc->cur_sp; return magic; } int cParty::get_level() const { short j = 0; - for(int i = 0; i < 6; i++) - if(adven[i]->main_status == eMainStatus::ALIVE) - j += adven[i]->level; + for(auto pc : adven) + if (pc && pc->main_status == eMainStatus::ALIVE) + j += pc->level; return j; } void cParty::heal(int how_much) { - for(int i = 0; i < 6; i++) - adven[i]->heal(how_much); + for(auto pc : adven) + if (pc) pc->heal(how_much); } void cParty::poison(int how_much) { - for(int i = 0; i < 6; i++) - adven[i]->poison(how_much); + for(auto pc : adven) + if (pc) pc->poison(how_much); } void cParty::cure(int how_much) { - for(int i = 0; i < 6; i++) - adven[i]->cure(how_much); + for(auto pc : adven) + if (pc) pc->cure(how_much); } void cParty::acid(int how_much) { - for(int i = 0; i < 6; i++) - adven[i]->acid(how_much); + for(auto pc : adven) + if (pc) pc->acid(how_much); } void cParty::curse(int how_much) { - for(int i = 0; i < 6; i++) - adven[i]->curse(how_much); + for(auto pc : adven) + if (pc) pc->curse(how_much); } void cParty::slow(int how_much) { - for(int i = 0; i < 6; i++) - adven[i]->slow(how_much); + for(auto pc : adven) + if (pc) pc->slow(how_much); } void cParty::web(int how_much) { diff --git a/src/universe/universe.cpp b/src/universe/universe.cpp index 4067ba1c..fdf6cd93 100644 --- a/src/universe/universe.cpp +++ b/src/universe/universe.cpp @@ -206,61 +206,6 @@ cTown*const cCurTown::record() const { return univ.scenario.towns[univ.party.town_num]; } -bool cCurTown::is_explored(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_explored(fields[x][y]); -} - -bool cCurTown::is_force_wall(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_force_wall(fields[x][y]); -} - -bool cCurTown::is_fire_wall(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_fire_wall(fields[x][y]); -} - -bool cCurTown::is_antimagic(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_antimagic(fields[x][y]); -} - -bool cCurTown::is_scloud(short x, short y) const{ // stinking cloud - if(!record()->is_on_map(x,y)) return false; - return is_scloud(fields[x][y]); -} - -bool cCurTown::is_ice_wall(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_ice_wall(fields[x][y]); -} - -bool cCurTown::is_blade_wall(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_blade_wall(fields[x][y]); -} - -bool cCurTown::is_sleep_cloud(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_sleep_cloud(fields[x][y]); -} - -bool cCurTown::is_block(short x, short y) const{ // currently unused - if(!record()->is_on_map(x,y)) return false; - return is_block(fields[x][y]); -} - -bool cCurTown::is_spot(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_spot(fields[x][y]); -} - -bool cCurTown::is_road(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_road(fields[x][y]); -} - bool cCurTown::is_special(short x, short y) const{ if(!record()->is_on_map(x,y)) return false; location check(x,y); @@ -270,81 +215,6 @@ bool cCurTown::is_special(short x, short y) const{ return false; } -bool cCurTown::is_web(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_web(fields[x][y]); -} - -bool cCurTown::is_crate(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_crate(fields[x][y]); -} - -bool cCurTown::is_barrel(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_barrel(fields[x][y]); -} - -bool cCurTown::is_fire_barr(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_fire_barr(fields[x][y]); -} - -bool cCurTown::is_force_barr(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_force_barr(fields[x][y]); -} - -bool cCurTown::is_quickfire(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_quickfire(fields[x][y]); -} - -bool cCurTown::is_sm_blood(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_sm_blood(fields[x][y]); -} - -bool cCurTown::is_med_blood(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_med_blood(fields[x][y]); -} - -bool cCurTown::is_lg_blood(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_lg_blood(fields[x][y]); -} - -bool cCurTown::is_sm_slime(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_sm_slime(fields[x][y]); -} - -bool cCurTown::is_lg_slime(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_lg_slime(fields[x][y]); -} - -bool cCurTown::is_ash(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_ash(fields[x][y]); -} - -bool cCurTown::is_bones(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_bones(fields[x][y]); -} - -bool cCurTown::is_rubble(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_rubble(fields[x][y]); -} - -bool cCurTown::is_force_cage(short x, short y) const{ - if(!record()->is_on_map(x,y)) return false; - return is_force_cage(fields[x][y]); -} - bool cCurTown::set_explored(short x, short y, bool b){ if(!record()->is_on_map(x,y)) return false; if(b) fields[x][y] |= SPECIAL_EXPLORED; diff --git a/src/universe/universe.hpp b/src/universe/universe.hpp index cbb6d9b7..e67f6209 100644 --- a/src/universe/universe.hpp +++ b/src/universe/universe.hpp @@ -9,18 +9,19 @@ #ifndef BOE_DATA_UNIVERSE_H #define BOE_DATA_UNIVERSE_H +#include #include #include #include -#include -#include -#include "party.hpp" -#include "population.hpp" + +#include "fields.hpp" #include "item.hpp" +#include "party.hpp" +#include "pictypes.hpp" +#include "population.hpp" #include "scenario.hpp" #include "talking.hpp" #include "town.hpp" -#include "pictypes.hpp" namespace legacy { struct out_info_type; @@ -37,6 +38,17 @@ class cCurTown { cUniverse& univ; cTown* arena; cTown*const record() const; + + template static bool test_field(unsigned long allFields) + { + return allFields & Field; + } + template bool test_field(short x, short y) const + { + if(!record()->is_on_map(x,y)) return false; + return fields[x][y] & Field; + } + public: bool quickfire_present = false, belt_present = false; // formerly current_town_type @@ -61,59 +73,59 @@ public: void prep_arena(); // Set up for a combat arena void place_preset_fields(); - static bool is_explored(unsigned long allFields) { return allFields & SPECIAL_EXPLORED; } - static bool is_force_wall(unsigned long allFields) { return allFields & WALL_FORCE; } - static bool is_fire_wall(unsigned long allFields) { return allFields & WALL_FIRE; } - static bool is_antimagic(unsigned long allFields) { return allFields & FIELD_ANTIMAGIC; } - static bool is_scloud(unsigned long allFields) { return allFields & CLOUD_STINK; } // stinking cloud - static bool is_ice_wall(unsigned long allFields) { return allFields & WALL_ICE; } - static bool is_blade_wall(unsigned long allFields) { return allFields & WALL_BLADES; } - static bool is_sleep_cloud(unsigned long allFields) { return allFields & CLOUD_SLEEP; } - static bool is_block(unsigned long allFields) { return allFields & OBJECT_BLOCK; } // currently unused - static bool is_spot(unsigned long allFields) { return allFields & SPECIAL_SPOT; } - static bool is_web(unsigned long allFields) { return allFields & FIELD_WEB; } - static bool is_crate(unsigned long allFields) { return allFields & OBJECT_CRATE; } - static bool is_barrel(unsigned long allFields) { return allFields & OBJECT_BARREL; } - static bool is_fire_barr(unsigned long allFields) { return allFields & BARRIER_FIRE; } - static bool is_force_barr(unsigned long allFields) { return allFields & BARRIER_FORCE; } - static bool is_quickfire(unsigned long allFields) { return allFields & FIELD_QUICKFIRE; } - static bool is_sm_blood(unsigned long allFields) { return allFields & SFX_SMALL_BLOOD; } - static bool is_med_blood(unsigned long allFields) { return allFields & SFX_MEDIUM_BLOOD; } - static bool is_lg_blood(unsigned long allFields) { return allFields & SFX_LARGE_BLOOD; } - static bool is_sm_slime(unsigned long allFields) { return allFields & SFX_SMALL_SLIME; } - static bool is_lg_slime(unsigned long allFields) { return allFields & SFX_LARGE_SLIME; } - static bool is_ash(unsigned long allFields) { return allFields & SFX_ASH; } - static bool is_bones(unsigned long allFields) { return allFields & SFX_BONES; } - static bool is_rubble(unsigned long allFields) { return allFields & SFX_RUBBLE; } - static bool is_force_cage(unsigned long allFields) { return allFields & BARRIER_CAGE; } - static bool is_road(unsigned long allFields) { return allFields & SPECIAL_ROAD; } - bool is_explored(short x, short y) const; - bool is_force_wall(short x, short y) const; - bool is_fire_wall(short x, short y) const; - bool is_antimagic(short x, short y) const; - bool is_scloud(short x, short y) const; // stinking cloud - bool is_ice_wall(short x, short y) const; - bool is_blade_wall(short x, short y) const; - bool is_sleep_cloud(short x, short y) const; - bool is_block(short x, short y) const; // currently unused - bool is_spot(short x, short y) const; + static bool is_explored(unsigned long allFields) { return test_field(allFields); } + static bool is_force_wall(unsigned long allFields) { return test_field(allFields); } + static bool is_fire_wall(unsigned long allFields) { return test_field(allFields); } + static bool is_antimagic(unsigned long allFields) { return test_field(allFields); } + static bool is_scloud(unsigned long allFields) { return test_field(allFields); } // stinking cloud + static bool is_ice_wall(unsigned long allFields) { return test_field(allFields); } + static bool is_blade_wall(unsigned long allFields) { return test_field(allFields); } + static bool is_sleep_cloud(unsigned long allFields) { return test_field(allFields); } + static bool is_block(unsigned long allFields) { return test_field(allFields); } // currently unused + static bool is_spot(unsigned long allFields) { return test_field(allFields); } + static bool is_web(unsigned long allFields) { return test_field(allFields); } + static bool is_crate(unsigned long allFields) { return test_field(allFields); } + static bool is_barrel(unsigned long allFields) { return test_field(allFields); } + static bool is_fire_barr(unsigned long allFields) { return test_field(allFields); } + static bool is_force_barr(unsigned long allFields) { return test_field(allFields); } + static bool is_quickfire(unsigned long allFields) { return test_field(allFields); } + static bool is_sm_blood(unsigned long allFields) { return test_field(allFields); } + static bool is_med_blood(unsigned long allFields) { return test_field(allFields); } + static bool is_lg_blood(unsigned long allFields) { return test_field(allFields); } + static bool is_sm_slime(unsigned long allFields) { return test_field(allFields); } + static bool is_lg_slime(unsigned long allFields) { return test_field(allFields); } + static bool is_ash(unsigned long allFields) { return test_field(allFields); } + static bool is_bones(unsigned long allFields) { return test_field(allFields); } + static bool is_rubble(unsigned long allFields) { return test_field(allFields); } + static bool is_force_cage(unsigned long allFields) { return test_field(allFields); } + static bool is_road(unsigned long allFields) { return test_field(allFields); } + bool is_explored(short x, short y) const { return test_field(x,y); } + bool is_force_wall(short x, short y) const { return test_field(x,y); } + bool is_fire_wall(short x, short y) const { return test_field(x,y); } + bool is_antimagic(short x, short y) const { return test_field(x,y); } + bool is_scloud(short x, short y) const { return test_field(x,y); } // stinking cloud + bool is_ice_wall(short x, short y) const { return test_field(x,y); } + bool is_blade_wall(short x, short y) const { return test_field(x,y); } + bool is_sleep_cloud(short x, short y) const { return test_field(x,y); } + bool is_block(short x, short y) const { return test_field(x,y); } // currently unused + bool is_spot(short x, short y) const { return test_field(x,y); } bool is_special(short x, short y) const; - bool is_web(short x, short y) const; - bool is_crate(short x, short y) const; - bool is_barrel(short x, short y) const; - bool is_fire_barr(short x, short y) const; - bool is_force_barr(short x, short y) const; - bool is_quickfire(short x, short y) const; - bool is_sm_blood(short x, short y) const; - bool is_med_blood(short x, short y) const; - bool is_lg_blood(short x, short y) const; - bool is_sm_slime(short x, short y) const; - bool is_lg_slime(short x, short y) const; - bool is_ash(short x, short y) const; - bool is_bones(short x, short y) const; - bool is_rubble(short x, short y) const; - bool is_force_cage(short x, short y) const; - bool is_road(short x, short y) const; + bool is_web(short x, short y) const { return test_field(x,y); } + bool is_crate(short x, short y) const { return test_field(x,y); } + bool is_barrel(short x, short y) const { return test_field(x,y); } + bool is_fire_barr(short x, short y) const { return test_field(x,y); } + bool is_force_barr(short x, short y) const { return test_field(x,y); } + bool is_quickfire(short x, short y) const { return test_field(x,y); } + bool is_sm_blood(short x, short y) const { return test_field(x,y); } + bool is_med_blood(short x, short y) const { return test_field(x,y); } + bool is_lg_blood(short x, short y) const { return test_field(x,y); } + bool is_sm_slime(short x, short y) const { return test_field(x,y); } + bool is_lg_slime(short x, short y) const { return test_field(x,y); } + bool is_ash(short x, short y) const { return test_field(x,y); } + bool is_bones(short x, short y) const { return test_field(x,y); } + bool is_rubble(short x, short y) const { return test_field(x,y); } + bool is_force_cage(short x, short y) const { return test_field(x,y); } + bool is_road(short x, short y) const { return test_field(x,y); } bool set_explored(short x, short y, bool b); bool set_force_wall(short x, short y, bool b); bool set_fire_wall(short x, short y, bool b);