Fix python compilation

This commit is contained in:
Dominic Bolin 2006-04-17 15:23:59 +00:00
parent b5a873b619
commit d992fdcc74
5 changed files with 70 additions and 17 deletions

View file

@ -70,14 +70,22 @@ static PyObject* wrapper_unittype_get_##x( wesnoth_unittype* type, void* /*closu
{ \
return Py_BuildValue("i",type->unit_type_->x()); \
}
#define ut_get_ability( x ) \
static PyObject* wrapper_unittype_get_##x( wesnoth_unittype* type, void* /*closure*/ ) \
{ \
return Py_BuildValue("i",type->unit_type_->has_ability("##x##")); \
}
ut_get( heals )
ut_get( regenerates )
ut_get( is_leader )
ut_get( illuminates )
ut_get( is_skirmisher )
ut_get( teleports )
ut_get( steadfast )
ut_get_ability( heals )
ut_get_ability( regenerates )
ut_get_ability( leadership )
ut_get_ability( illuminates )
ut_get_ability( skirmisher )
ut_get_ability( teleports )
static PyObject* wrapper_unittype_get_steadfast( wesnoth_unittype* type, void* /*closure*/ )
{
return Py_BuildValue("i",type->unit_type_->has_ability_by_id("steadfast"));
}
ut_get( not_living )
ut_get( can_advance )
ut_get( has_zoc )
@ -93,9 +101,9 @@ static PyGetSetDef unittype_getseters[] = {
ut_gs( name )
ut_gs( heals )
ut_gs( regenerates )
ut_gs( is_leader )
ut_gs( leadership )
ut_gs( illuminates )
ut_gs( is_skirmisher )
ut_gs( skirmisher )
ut_gs( teleports )
ut_gs( steadfast )
ut_gs( not_living )
@ -224,12 +232,12 @@ static PyObject* attacktype_get_defense_weight(wesnoth_attacktype* type, void* /
static PyObject* attacktype_get_backstab(wesnoth_attacktype* type, void* /*closure*/)
{
return Py_BuildValue("i",type->attack_type_->backstab());
return Py_BuildValue("i",type->attack_type_->has_special_by_id("backstab"));
}
static PyObject* attacktype_get_slow(wesnoth_attacktype* type, void* /*closure*/)
{
return Py_BuildValue("i",type->attack_type_->slow());
return Py_BuildValue("i",type->attack_type_->has_special_by_id("slow"));
}
static PyObject* attacktype_get_range(wesnoth_attacktype* type, void* /*closure*/)
@ -368,7 +376,7 @@ static PyObject* unit_can_attack(wesnoth_unit* unit, void* /*closure*/)
{
if (!running_instance->is_unit_valid(unit->unit_))
return NULL;
return Py_BuildValue("i",unit->unit_->can_attack());
return Py_BuildValue("i",unit->unit_->attacks_left());
}
static PyObject* unit_hitpoints(wesnoth_unit* unit, void* /*closure*/)
@ -389,7 +397,7 @@ static PyObject* unit_poisoned(wesnoth_unit* unit, void* /*closure*/)
{
if (!running_instance->is_unit_valid(unit->unit_))
return NULL;
return Py_BuildValue("i",unit->unit_->poisoned( ) == true ? 1 : 0);
return Py_BuildValue("i",unit->unit_->get_state("poisoned")=="yes" ? 1 : 0);
}
static PyObject* unit_query_valid(wesnoth_unit* unit, void* /*closure*/)
@ -442,7 +450,8 @@ static PyObject* wrapper_unit_damage_against( wesnoth_unit* unit, PyObject* args
return NULL;
if (!running_instance->is_unit_valid(unit->unit_))
return NULL;
return Py_BuildValue("i",unit->unit_->damage_against(*attack->attack_type_));
static gamemap::location no_loc;
return Py_BuildValue("i",unit->unit_->damage_from(*attack->attack_type_,true,no_loc));
}
static PyMethodDef unit_methods[] = {
@ -853,7 +862,7 @@ static PyObject* wrapper_unit_movement_cost( wesnoth_unit* unit, PyObject* args
wesnoth_location* loc;
if ( !PyArg_ParseTuple( args, "O!O!", &wesnoth_gamemap_type, &map, &wesnoth_location_type, &loc ) )
return NULL;
return Py_BuildValue("i",unit->unit_->movement_cost(*map->map_,map->map_->get_terrain(*loc->location_)));
return Py_BuildValue("i",unit->unit_->movement_cost(map->map_->get_terrain(*loc->location_)));
}
static PyObject* wrapper_unit_defense_modifier( wesnoth_unit* unit, PyObject* args )
@ -862,7 +871,7 @@ static PyObject* wrapper_unit_defense_modifier( wesnoth_unit* unit, PyObject* ar
wesnoth_location* loc;
if ( !PyArg_ParseTuple( args, "O!O!", &wesnoth_gamemap_type, &map, &wesnoth_location_type, &loc ) )
return NULL;
return Py_BuildValue("i",unit->unit_->defense_modifier(*map->map_,map->map_->get_terrain(*loc->location_)));
return Py_BuildValue("i",unit->unit_->defense_modifier(map->map_->get_terrain(*loc->location_)));
}

View file

@ -297,6 +297,13 @@ const std::string& unit::id() const
{
return id_;
}
const unit_type& unit::type() const
{
wassert(gamedata_ != NULL);
std::map<std::string,unit_type>::const_iterator i = gamedata_->unit_types.find(id());
wassert(i != gamedata_->unit_types.end());
return i->second;
}
// the actual name of the unit
const std::string& unit::name() const
{

View file

@ -72,6 +72,7 @@ class unit
// the current type id
const std::string& id() const;
const unit_type& type() const;
// the actual name of the unit
const std::string& name() const;
void rename(const std::string& name);

View file

@ -360,6 +360,21 @@ bool attack_type::apply_modification(const config& cfg,std::string* description,
return true;
}
bool attack_type::has_special_by_id(const std::string& special) const
{
const config* abil = cfg_.child("specials");
if(abil) {
for(config::child_map::const_iterator i = abil->all_children().begin(); i != abil->all_children().end(); ++i) {
for(config::child_list::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
if((**j)["id"] == special) {
return true;
}
}
}
}
return false;
}
unit_movement_type::unit_movement_type(const config& cfg, const unit_movement_type* parent)
: cfg_(cfg), parent_(parent)
@ -1194,7 +1209,25 @@ bool unit_type::has_zoc() const
bool unit_type::has_ability(const std::string& ability) const
{
return std::find(abilities_.begin(),abilities_.end(),ability) != abilities_.end();
const config* abil = cfg_.child("abilities");
if(abil) {
return abil->get_children(ability).size();
}
return false;
}
bool unit_type::has_ability_by_id(const std::string& ability) const
{
const config* abil = cfg_.child("abilities");
if(abil) {
for(config::child_map::const_iterator i = abil->all_children().begin(); i != abil->all_children().end(); ++i) {
for(config::child_list::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
if((**j)["id"] == ability) {
return true;
}
}
}
}
return false;
}
const std::vector<config*>& unit_type::possible_traits() const

View file

@ -58,6 +58,8 @@ public:
const gamemap* map, const gamestatus* game_status,
const std::vector<team>* teams,bool attacker,const attack_type* other_attack) const;
void set_specials_context(const gamemap::location& loc,const unit& un) const;
bool has_special_by_id(const std::string& special) const;
//this function returns a random animation out of the possible
//animations for this attack. It will not return the same attack
//each time.
@ -249,6 +251,7 @@ public:
bool has_zoc() const;
bool has_ability(const std::string& ability) const;
bool has_ability_by_id(const std::string& ability) const;
const std::vector<config*>& possible_traits() const;