mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Added createObject call as wrapper around NewObject netpack
This commit is contained in:
parent
d8879f1e53
commit
6a08a96d0c
@ -187,6 +187,7 @@ public:
|
||||
|
||||
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> & spells) override {};
|
||||
bool removeObject(const CGObjectInstance * obj) override {return false;};
|
||||
void createObject(const int3 & visitablePosition, Obj type, int32_t subtype ) override {};
|
||||
void setOwner(const CGObjectInstance * obj, PlayerColor owner) override {};
|
||||
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs = false) override {};
|
||||
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs = false) override {};
|
||||
|
@ -90,6 +90,7 @@ public:
|
||||
|
||||
virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
|
||||
virtual bool removeObject(const CGObjectInstance * obj)=0;
|
||||
virtual void createObject(const int3 & visitablePosition, Obj type, int32_t subtype = 0) = 0;
|
||||
virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
|
||||
virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=0;
|
||||
virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;
|
||||
|
@ -451,13 +451,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
smp.val = maxMovePoints(false);
|
||||
//Create a new boat for hero
|
||||
NewObject no;
|
||||
no.ID = Obj::BOAT;
|
||||
no.subID = getBoatType().getNum();
|
||||
no.targetPos = boatPos;
|
||||
|
||||
cb->sendAndApply(&no);
|
||||
|
||||
cb->createObject(boatPos, Obj::BOAT, BoatId(EBoatId::CASTLE));
|
||||
boatId = cb->getTopObj(boatPos)->id;
|
||||
}
|
||||
else
|
||||
|
@ -4429,11 +4429,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl
|
||||
if (getTile(hr.tile)->isWater())
|
||||
{
|
||||
//Create a new boat for hero
|
||||
NewObject no;
|
||||
no.ID = Obj::BOAT;
|
||||
no.subID = nh->getBoatType().getNum();
|
||||
no.targetPos = obj->visitablePos();
|
||||
sendAndApply(&no);
|
||||
createObject(obj->visitablePos(), Obj::BOAT, BoatId(EBoatId::CASTLE));
|
||||
|
||||
hr.boatId = getTopObj(hr.tile)->id;
|
||||
}
|
||||
@ -5653,16 +5649,8 @@ bool CGameHandler::buildBoat(ObjectInstanceID objid, PlayerColor playerID)
|
||||
return false;
|
||||
}
|
||||
|
||||
//take boat cost
|
||||
giveResources(playerID, -boatCost);
|
||||
|
||||
//create boat
|
||||
NewObject no;
|
||||
no.ID = Obj::BOAT;
|
||||
no.subID = obj->getBoatType().getNum();
|
||||
no.targetPos = tile;
|
||||
sendAndApply(&no);
|
||||
|
||||
createObject(tile, Obj::BOAT, obj->getBoatType().getNum());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -5803,12 +5791,7 @@ bool CGameHandler::dig(const CGHeroInstance *h)
|
||||
if (h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement
|
||||
COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus());
|
||||
|
||||
//create a hole
|
||||
NewObject no;
|
||||
no.ID = Obj::HOLE;
|
||||
no.targetPos = h->visitablePos();
|
||||
no.subID = 0;
|
||||
sendAndApply(&no);
|
||||
createObject(h->visitablePos(), Obj::HOLE, 0 );
|
||||
|
||||
//take MPs
|
||||
SetMovePoints smp;
|
||||
@ -6875,7 +6858,9 @@ void CGameHandler::spawnWanderingMonsters(CreatureID creatureID)
|
||||
{
|
||||
auto count = cre->getRandomAmount(std::rand);
|
||||
|
||||
auto monsterId = putNewObject(Obj::MONSTER, creatureID, *tile);
|
||||
createObject(*tile, Obj::MONSTER, creatureID);
|
||||
auto monsterId = getTopObj(*tile)->id;
|
||||
|
||||
setObjProperty(monsterId, ObjProperty::MONSTER_COUNT, count);
|
||||
setObjProperty(monsterId, ObjProperty::MONSTER_POWER, (si64)1000*count);
|
||||
}
|
||||
@ -7404,12 +7389,11 @@ scripting::Pool * CGameHandler::getContextPool() const
|
||||
}
|
||||
#endif
|
||||
|
||||
const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos)
|
||||
void CGameHandler::createObject(const int3 & visitablePosition, Obj type, int32_t subtype)
|
||||
{
|
||||
NewObject no;
|
||||
no.ID = ID; //creature
|
||||
no.subID= subID;
|
||||
no.targetPos = pos;
|
||||
no.ID = type;
|
||||
no.subID= subtype;
|
||||
no.targetPos = visitablePosition;
|
||||
sendAndApply(&no);
|
||||
return no.createdObjectID; //id field will be filled during applying on gs
|
||||
}
|
||||
|
@ -153,6 +153,7 @@ public:
|
||||
//do sth
|
||||
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override;
|
||||
bool removeObject(const CGObjectInstance * obj) override;
|
||||
void createObject(const int3 & visitablePosition, Obj type, int32_t subtype ) override;
|
||||
void setOwner(const CGObjectInstance * obj, PlayerColor owner) override;
|
||||
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) override;
|
||||
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override;
|
||||
@ -276,7 +277,6 @@ public:
|
||||
void engageIntoBattle( PlayerColor player );
|
||||
bool dig(const CGHeroInstance *h);
|
||||
void moveArmy(const CArmedInstance *src, const CArmedInstance *dst, bool allowMerging);
|
||||
const ObjectInstanceID putNewObject(Obj ID, int subID, int3 pos);
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ public:
|
||||
|
||||
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override {}
|
||||
bool removeObject(const CGObjectInstance * obj) override {return false;}
|
||||
void createObject(const int3 & visitablePosition, Obj type, int32_t subtype = 0) override {};
|
||||
void setOwner(const CGObjectInstance * objid, PlayerColor owner) override {}
|
||||
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) override {}
|
||||
void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override {}
|
||||
|
Loading…
Reference in New Issue
Block a user