mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-24 03:35:27 +00:00

[[The Wesnoth repository started off as CVS in September 2003 on SourceForge. In September 2005 it was converted to Subversion using cvs2svn and hosted at Gna!; the last CVS commit corresponded to Subversion r8374. In March 2013 it was converted to git by ESR using reposurgeon 2.30; the last Subversion commit was r56594. In the process, several small, abandoned experimental branches were removed. For all branches known to have been merged to trunk merge points were found and patched in. Comments have been massaged into git summary + body form; revision references have been lifted to action stamps. Conversion comments are, like this one, enclosed in double square brackets. Typos in change comments have often been quietly fixed. Some abbreviations (notably for mainline campaign names) have been made more uniform than they were in the Subversion comments. Infix "::" to mark a campaign-scenario pair (as in "HttT::12" has sometimes been inserted for clarity and to shorten summary lines. Two branches, website/ and resources/, have been merged to trunk, where their history now appears as that of those two top-level directories rather than as separate branches. Subversion property settings, and the commits in the Subversion history that manipulated them, are almost all gone. A few have been translated to .gitignore files and setting of executable bits. There are a few committers that we have been unable to identify. These are: uso zas uid65860 uid66289 uid67456 uid68698 uid68803 uid68842 uid68850 uid68852 uid69097 uid69206 The uid names seem to have been mechanically generated from Wesnoth forum postings. Committer lines for all of these have been left without a domain name in the email address.]]
144 lines
3.3 KiB
C++
144 lines
3.3 KiB
C++
/*
|
|
Copyright (C) 2003 by David White <davidnwhite@optusnet.com.au>
|
|
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY.
|
|
|
|
See the COPYING file for more details.
|
|
*/
|
|
#ifndef UNIT_H_INCLUDED
|
|
#define UNIT_H_INCLUDED
|
|
|
|
#include "config.hpp"
|
|
#include "map.hpp"
|
|
#include "unit_types.hpp"
|
|
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class unit
|
|
{
|
|
public:
|
|
unit(game_data& data, config& cfg);
|
|
unit(const unit_type* t, int side, bool use_traits=false);
|
|
|
|
//a constructor used when advancing a unit
|
|
unit(const unit_type* t, const unit& u);
|
|
const unit_type& type() const;
|
|
std::string name() const;
|
|
const std::string& description() const;
|
|
int hitpoints() const;
|
|
int max_hitpoints() const;
|
|
int experience() const;
|
|
int max_experience() const;
|
|
bool get_experience(int xp);
|
|
bool advances() const;
|
|
int side() const;
|
|
double alpha() const;
|
|
void make_recruiter();
|
|
bool can_recruit() const;
|
|
int total_movement() const;
|
|
int movement_left() const;
|
|
bool can_attack() const;
|
|
void set_movement(int moves);
|
|
void set_attacked();
|
|
void new_turn();
|
|
void end_turn();
|
|
void new_level();
|
|
|
|
bool gets_hit(int damage);
|
|
void heal();
|
|
void heal(int amount);
|
|
void heal_all();
|
|
|
|
bool invisible(gamemap::TERRAIN terrain) const;
|
|
|
|
bool matches_filter(config& cfg) const;
|
|
|
|
void set_flag(const std::string& flag);
|
|
void remove_flag(const std::string& flag);
|
|
bool has_flag(const std::string& flag) const;
|
|
|
|
void read(game_data& data, config& cfg);
|
|
|
|
void write(config& cfg) const;
|
|
|
|
void assign_role(const std::string& role);
|
|
|
|
const std::vector<attack_type>& attacks() const;
|
|
|
|
int movement_cost(const gamemap& map, gamemap::TERRAIN terrain) const;
|
|
double defense_modifier(const gamemap& map, gamemap::TERRAIN terrain) const;
|
|
int damage_against(const attack_type& attack) const;
|
|
|
|
//gets the unit image that should currently be displayed
|
|
//(could be in the middle of an attack etc)
|
|
const std::string& image() const;
|
|
|
|
void set_defending(bool newval);
|
|
void set_attacking(bool newval, const attack_type* type=NULL, int ms=0);
|
|
|
|
bool facing_left() const;
|
|
void set_facing_left(bool newval);
|
|
|
|
const std::string& traits_description() const;
|
|
|
|
int value() const;
|
|
bool is_guardian() const;
|
|
|
|
void add_modification(const std::string& type, config& modification,
|
|
bool no_add=false);
|
|
|
|
|
|
private:
|
|
const unit_type* type_;
|
|
|
|
bool facingLeft_;
|
|
|
|
enum STATE { STATE_NORMAL, STATE_ATTACKING, STATE_DEFENDING };
|
|
STATE state_;
|
|
const attack_type* attackType_;
|
|
int attackingMilliseconds_;
|
|
|
|
int hitpoints_;
|
|
int maxHitpoints_, backupMaxHitpoints_;
|
|
int experience_;
|
|
int maxExperience_, backupMaxExperience_;
|
|
|
|
int side_;
|
|
|
|
//is set to the number of moves left, and -1 if the unit has attacked
|
|
int moves_;
|
|
int maxMovement_, backupMaxMovement_;
|
|
|
|
std::string description_;
|
|
|
|
bool recruit_;
|
|
|
|
std::string role_;
|
|
|
|
std::set<std::string> statusFlags_;
|
|
|
|
std::vector<attack_type> attacks_;
|
|
std::vector<attack_type> backupAttacks_;
|
|
|
|
config modifications_;
|
|
|
|
std::string traitsDescription_;
|
|
|
|
bool guardian_;
|
|
|
|
void apply_modifications();
|
|
};
|
|
|
|
struct compare_unit_values
|
|
{
|
|
bool operator()(const unit& a, const unit& b) const;
|
|
};
|
|
|
|
#endif
|