1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

New objects are now created and initialized on server and sent to client

This commit is contained in:
Ivan Savenko
2024-07-12 16:51:27 +00:00
parent d2839c8e52
commit b07408e984
14 changed files with 95 additions and 87 deletions

View File

@@ -1421,7 +1421,6 @@ void HeroRecruited::applyGs(CGameState * gs) const
h->setOwner(player);
h->pos = tile;
h->initObj(gs->getRandomGenerator());
if(h->id == ObjectInstanceID())
{
@@ -1475,59 +1474,13 @@ void GiveHero::applyGs(CGameState * gs) const
void NewObject::applyGs(CGameState *gs)
{
TerrainId terrainType = ETerrainId::NONE;
newObject->id = ObjectInstanceID(static_cast<si32>(gs->map->objects.size()));
if (!gs->isInTheMap(targetPos))
{
logGlobal->error("Attempt to create object outside map at %s!", targetPos.toString());
return;
}
const TerrainTile & t = gs->map->getTile(targetPos);
terrainType = t.terType->getId();
auto handler = VLC->objtypeh->getHandlerFor(ID, subID);
CGObjectInstance * o = handler->create(gs->callback, nullptr);
handler->configureObject(o, gs->getRandomGenerator());
assert(o->ID == this->ID);
if (ID == Obj::MONSTER) //probably more options will be needed
{
//CStackInstance hlp;
auto * cre = dynamic_cast<CGCreature *>(o);
//cre->slots[0] = hlp;
assert(cre);
cre->notGrowingTeam = cre->neverFlees = false;
cre->character = 2;
cre->gainedArtifact = ArtifactID::NONE;
cre->identifier = -1;
cre->addToSlot(SlotID(0), new CStackInstance(subID.getNum(), -1)); //add placeholder stack
}
assert(!handler->getTemplates(terrainType).empty());
if (handler->getTemplates().empty())
{
logGlobal->error("Attempt to create object (%d %d) with no templates!", ID, subID.getNum());
return;
}
if (!handler->getTemplates(terrainType).empty())
o->appearance = handler->getTemplates(terrainType).front();
else
o->appearance = handler->getTemplates().front();
o->id = ObjectInstanceID(static_cast<si32>(gs->map->objects.size()));
o->pos = targetPos + o->getVisitableOffset();
gs->map->objects.emplace_back(o);
gs->map->addBlockVisTiles(o);
o->initObj(gs->getRandomGenerator());
gs->map->objects.emplace_back(newObject);
gs->map->addBlockVisTiles(newObject);
gs->map->calculateGuardingGreaturePositions();
createdObjectID = o->id;
logGlobal->debug("Added object id=%d; address=%x; name=%s", o->id, (intptr_t)o, o->getObjectName());
logGlobal->debug("Added object id=%d; address=%x; name=%s", newObject->id, (intptr_t)newObject, newObject->getObjectName());
}
void NewArtifact::applyGs(CGameState *gs)