1
0
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:
Ivan Savenko 2023-06-20 22:25:49 +03:00
parent d8879f1e53
commit 6a08a96d0c
6 changed files with 15 additions and 34 deletions

View File

@ -187,6 +187,7 @@ public:
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> & spells) override {}; void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> & spells) override {};
bool removeObject(const CGObjectInstance * obj) override {return false;}; 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 setOwner(const CGObjectInstance * obj, PlayerColor owner) override {};
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs = false) 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 {}; void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs = false) override {};

View File

@ -90,6 +90,7 @@ public:
virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0; virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
virtual bool removeObject(const CGObjectInstance * obj)=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 setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;
virtual void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false)=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; virtual void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false)=0;

View File

@ -451,13 +451,7 @@ void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
{ {
smp.val = maxMovePoints(false); smp.val = maxMovePoints(false);
//Create a new boat for hero //Create a new boat for hero
NewObject no; cb->createObject(boatPos, Obj::BOAT, BoatId(EBoatId::CASTLE));
no.ID = Obj::BOAT;
no.subID = getBoatType().getNum();
no.targetPos = boatPos;
cb->sendAndApply(&no);
boatId = cb->getTopObj(boatPos)->id; boatId = cb->getTopObj(boatPos)->id;
} }
else else

View File

@ -4429,11 +4429,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl
if (getTile(hr.tile)->isWater()) if (getTile(hr.tile)->isWater())
{ {
//Create a new boat for hero //Create a new boat for hero
NewObject no; createObject(obj->visitablePos(), Obj::BOAT, BoatId(EBoatId::CASTLE));
no.ID = Obj::BOAT;
no.subID = nh->getBoatType().getNum();
no.targetPos = obj->visitablePos();
sendAndApply(&no);
hr.boatId = getTopObj(hr.tile)->id; hr.boatId = getTopObj(hr.tile)->id;
} }
@ -5653,16 +5649,8 @@ bool CGameHandler::buildBoat(ObjectInstanceID objid, PlayerColor playerID)
return false; return false;
} }
//take boat cost
giveResources(playerID, -boatCost); giveResources(playerID, -boatCost);
createObject(tile, Obj::BOAT, obj->getBoatType().getNum());
//create boat
NewObject no;
no.ID = Obj::BOAT;
no.subID = obj->getBoatType().getNum();
no.targetPos = tile;
sendAndApply(&no);
return true; return true;
} }
@ -5803,12 +5791,7 @@ bool CGameHandler::dig(const CGHeroInstance *h)
if (h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement if (h->diggingStatus() != EDiggingStatus::CAN_DIG) //checks for terrain and movement
COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus()); COMPLAIN_RETF("Hero cannot dig (error code %d)!", h->diggingStatus());
//create a hole createObject(h->visitablePos(), Obj::HOLE, 0 );
NewObject no;
no.ID = Obj::HOLE;
no.targetPos = h->visitablePos();
no.subID = 0;
sendAndApply(&no);
//take MPs //take MPs
SetMovePoints smp; SetMovePoints smp;
@ -6875,7 +6858,9 @@ void CGameHandler::spawnWanderingMonsters(CreatureID creatureID)
{ {
auto count = cre->getRandomAmount(std::rand); 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_COUNT, count);
setObjProperty(monsterId, ObjProperty::MONSTER_POWER, (si64)1000*count); setObjProperty(monsterId, ObjProperty::MONSTER_POWER, (si64)1000*count);
} }
@ -7404,12 +7389,11 @@ scripting::Pool * CGameHandler::getContextPool() const
} }
#endif #endif
const ObjectInstanceID CGameHandler::putNewObject(Obj ID, int subID, int3 pos) void CGameHandler::createObject(const int3 & visitablePosition, Obj type, int32_t subtype)
{ {
NewObject no; NewObject no;
no.ID = ID; //creature no.ID = type;
no.subID= subID; no.subID= subtype;
no.targetPos = pos; no.targetPos = visitablePosition;
sendAndApply(&no); sendAndApply(&no);
return no.createdObjectID; //id field will be filled during applying on gs
} }

View File

@ -153,6 +153,7 @@ public:
//do sth //do sth
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override; void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override;
bool removeObject(const CGObjectInstance * obj) 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 setOwner(const CGObjectInstance * obj, PlayerColor owner) override;
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) 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; void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override;
@ -276,7 +277,6 @@ public:
void engageIntoBattle( PlayerColor player ); void engageIntoBattle( PlayerColor player );
bool dig(const CGHeroInstance *h); bool dig(const CGHeroInstance *h);
void moveArmy(const CArmedInstance *src, const CArmedInstance *dst, bool allowMerging); 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) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -41,6 +41,7 @@ public:
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override {} void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override {}
bool removeObject(const CGObjectInstance * obj) override {return false;} 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 setOwner(const CGObjectInstance * objid, PlayerColor owner) override {}
void changePrimSkill(const CGHeroInstance * hero, PrimarySkill::PrimarySkill which, si64 val, bool abs=false) 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 {} void changeSecSkill(const CGHeroInstance * hero, SecondarySkill which, int val, bool abs=false) override {}