1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Stack artifacts part 2, not working yet.

This commit is contained in:
DjWarmonger 2012-02-04 16:34:29 +00:00
parent b8a5d0d430
commit 2bddf29cbf
12 changed files with 71 additions and 50 deletions

View File

@ -134,7 +134,7 @@ bool CCallback::swapArtifacts(const IArtifactSetBase * src, ui16 pos1, const IAr
const CGHeroInstance * hero1 = dynamic_cast<const CGHeroInstance*>(src); const CGHeroInstance * hero1 = dynamic_cast<const CGHeroInstance*>(src);
const CGHeroInstance * hero2 = dynamic_cast<const CGHeroInstance*>(dest); const CGHeroInstance * hero2 = dynamic_cast<const CGHeroInstance*>(dest);
ExchangeArtifacts ea; ExchangeArtifacts ea(0,0,0,0);
if (hero1 && hero2) if (hero1 && hero2)
{ {

View File

@ -251,14 +251,17 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode *
} }
} }
if (GameConstants::STACK_ARTIFACT && type > BATTLE) if (GameConstants::STACK_ARTIFACT)
{ {
//SDL_Rect rect = genRect(44,44,465,98); if (type > BATTLE) //artifact buttons inactive in battle
//creatureArtifact = new CArtPlace(NULL); {
//creatureArtifact->pos = rect; leftArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, -1), 437, 98, "hsbtns3.def", SDLK_LEFT);
//creatureArtifact->ourOwner = NULL; //hmm? rightArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, +1), 516, 98, "hsbtns5.def", SDLK_RIGHT);
leftArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, -1), 437, 98, "hsbtns3.def", SDLK_LEFT); if (heroOwner)
rightArtRoll = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, +1), 516, 98, "hsbtns5.def", SDLK_RIGHT); passArtToHero = new CAdventureMapButton(std::string(), std::string(), boost::bind (&CCreatureWindow::scrollArt, this, 0), 437, 148, "OVBUTN1.DEF", SDLK_HOME);
}
if (ConstTransitivePtr<CArtifactInstance> art = stack->activeArtifact.artifact)
blitAt(graphics->artDefs->ourImages[art->id].bitmap, 466, 161, *bitmap);
} }
else else
creatureArtifact = NULL; creatureArtifact = NULL;

View File

@ -60,7 +60,7 @@ public:
CSlider * slider; //Abilities CSlider * slider; //Abilities
CAdventureMapButton *dismiss, *upgrade, *ok; CAdventureMapButton *dismiss, *upgrade, *ok;
CAdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection CAdventureMapButton * leftArtRoll, * rightArtRoll; //artifact selection
//TODO: Artifact drop CAdventureMapButton * passArtToHero;
boost::function<void()> dsm; //dismiss button callback boost::function<void()> dsm; //dismiss button callback
boost::function<void()> Upg; //upgrade button callback boost::function<void()> Upg; //upgrade button callback

View File

@ -273,19 +273,18 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState)
{ {
artSelected = true; artSelected = true;
if (art->canBePutAt(ArtifactLocation(myStack, GameConstants::CREATURE_ART))) if (art->canBePutAt(ArtifactLocation(myStack, GameConstants::CREATURE_ART)))
{ { //equip clicked stack
//TODO : move LOCPLINT->cb->swapArtifacts(aoh->getHero(), aoh->commonInfo->src.slotID, myStack, GameConstants::CREATURE_ART);
break; break;
} }
} }
} }
} }
if (!artSelected) if (artSelected || creature)
{ {
owner->highlighted = this;
if(creature) if(creature)
{ {
owner->highlighted = this;
for(size_t i = 0; i<owner->splitButtons.size(); i++) for(size_t i = 0; i<owner->splitButtons.size(); i++)
owner->splitButtons[i]->block(false); owner->splitButtons[i]->block(false);
} }
@ -5071,7 +5070,8 @@ void CArtifactsOfHero::artifactMoved(const ArtifactLocation &src, const Artifact
if(commonInfo->src == src) //artifact was taken from us if(commonInfo->src == src) //artifact was taken from us
{ {
assert(commonInfo->dst == dst || dst.slot == dst.hero->artifactsInBackpack.size() + GameConstants::BACKPACK_START); //assert(commonInfo->dst == dst || dst.slot == dst.hero->artifactsInBackpack.size() + GameConstants::BACKPACK_START);
//FIXME: assertion fails for stack artifacts
commonInfo->reset(); commonInfo->reset();
unmarkSlots(); unmarkSlots();
} }

View File

@ -216,8 +216,9 @@ void EraseArtifact::applyCl( CClient *cl )
void MoveArtifact::applyCl( CClient *cl ) void MoveArtifact::applyCl( CClient *cl )
{ {
INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst); INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst);
if(src.hero->tempOwner != dst.hero->tempOwner) if (src.hero.get() && dst.hero.get())
INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst); if(src.hero->tempOwner != dst.hero->tempOwner)
INTERFACE_CALL_IF_PRESENT(src.hero->tempOwner, artifactMoved, src, dst);
} }
void AssembledArtifact::applyCl( CClient *cl ) void AssembledArtifact::applyCl( CClient *cl )

View File

@ -1277,7 +1277,7 @@ bool CCreatureArtifactInstance::canBePutAt(const ArtifactLocation &al, bool assu
{ {
if (al.stack) if (al.stack)
{ {
return true; //all artifacts should fit on creature return al.stack->isPositionFree(al.slot, assumeDestRemoved);
} }
else if(al.slot >= GameConstants::BACKPACK_START) else if(al.slot >= GameConstants::BACKPACK_START)
{ //TODO backpack limit? { //TODO backpack limit?
@ -1438,10 +1438,9 @@ void CArtifactSet::eraseArtSlot(ui16 slot)
ArtSlotInfo & CCreatureArtifactSet::retreiveNewArtSlot(ui16 slot) ArtSlotInfo & CCreatureArtifactSet::retreiveNewArtSlot(ui16 slot)
{ {
assert(slot); //ke? ArtSlotInfo &ret = slot == GameConstants::CREATURE_ART
ArtSlotInfo &ret = slot <= GameConstants::CREATURE_ART
? activeArtifact ? activeArtifact
: *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - 1), ArtSlotInfo()); : *artifactsInBackpack.insert(artifactsInBackpack.begin() + (slot - GameConstants::CREATURE_ART), ArtSlotInfo());
return ret; return ret;
} }
@ -1479,9 +1478,6 @@ si32 CCreatureArtifactSet::getArtPos(int aid, bool onlyWorn) const
if (aid == activeArtifact.artifact->artType->id ) if (aid == activeArtifact.artifact->artType->id )
return GameConstants::CREATURE_ART; return GameConstants::CREATURE_ART;
if(onlyWorn)
return -1;
for(int i = 0; i < artifactsInBackpack.size(); i++) for(int i = 0; i < artifactsInBackpack.size(); i++)
{ {
if(artifactsInBackpack[i].artifact->artType->id == aid) if(artifactsInBackpack[i].artifact->artType->id == aid)
@ -1498,7 +1494,7 @@ si32 CCreatureArtifactSet::getArtPos(const CArtifactInstance *art) const
for(int i = 0; i < artifactsInBackpack.size(); i++) for(int i = 0; i < artifactsInBackpack.size(); i++)
if(artifactsInBackpack[i].artifact == art) if(artifactsInBackpack[i].artifact == art)
return GameConstants::BACKPACK_START + i; return i + 1;
return -1; return -1;
} }

View File

@ -87,7 +87,7 @@ namespace GameConstants
const ui16 BACKPACK_START = 19; const ui16 BACKPACK_START = 19;
const int ID_CATAPULT = 3, ID_LOCK = 145; const int ID_CATAPULT = 3, ID_LOCK = 145;
const ui16 CREATURE_ART = 0; const ui16 CREATURE_ART = 0; //position in CCreatureArtifactSet
//game modules //game modules
const bool STACK_EXP = true; const bool STACK_EXP = true;

View File

@ -1758,7 +1758,10 @@ struct ExchangeArtifacts : public CPackForServer
{ {
ExchangeArtifacts(){}; ExchangeArtifacts(){};
ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2) ExchangeArtifacts(si32 H1, si32 H2, ui16 S1, ui16 S2)
:hid1(H1),hid2(H2),slot1(S1),slot2(S2){}; :hid1(H1),hid2(H2),slot1(S1),slot2(S2)
{
s1 = s2 = StackLocation(NULL,0);
};
si32 hid1, hid2; si32 hid1, hid2;
StackLocation s1, s2; //for creature stacks StackLocation s1, s2; //for creature stacks
ui16 slot1, slot2; ui16 slot1, slot2;

View File

@ -560,7 +560,10 @@ DLL_LINKAGE CArtifactInstance *ArtifactLocation::getArt()
DLL_LINKAGE const ArtSlotInfo *ArtifactLocation::getSlot() const DLL_LINKAGE const ArtSlotInfo *ArtifactLocation::getSlot() const
{ {
return hero->getSlot(slot); if (hero)
return hero->getSlot(slot);
if (stack)
return stack->getSlot(slot);
} }
DLL_LINKAGE void ChangeStackCount::applyGs( CGameState *gs ) DLL_LINKAGE void ChangeStackCount::applyGs( CGameState *gs )

View File

@ -95,6 +95,8 @@ void registerTypes1(Serializer &s)
s.template registerType<CArtifactInstance>(); s.template registerType<CArtifactInstance>();
s.template registerType<CCombinedArtifactInstance>(); s.template registerType<CCombinedArtifactInstance>();
s.template registerType<CCreatureArtifactInstance>(); s.template registerType<CCreatureArtifactInstance>();
//s.template registerType<ArtifactLocation>();
//s.template registerType<StackLocation>();
} }
template<typename Serializer> template<typename Serializer>

View File

@ -2571,14 +2571,12 @@ bool CGameHandler::moveArtifact(si32 srcHeroID, si32 destHeroID, ui16 srcSlot, u
return true; return true;
} }
bool CGameHandler::moveArtifact(StackLocation s1, StackLocation s2, ui16 srcSlot, ui16 destSlot) bool CGameHandler::moveArtifact(StackLocation s1, StackLocation s2, ui16 srcSlot, ui16 destSlot)
{ {
ArtifactLocation src(s1.getStack(), srcSlot), dst(s2.getStack(), destSlot); ArtifactLocation src(s1.getStack(), srcSlot), dst(s2.getStack(), destSlot);
moveArtifact(src, dst); moveArtifact(src, dst);
return true; return true;
} }
bool CGameHandler::moveArtifact(si32 srcHeroID, StackLocation s2, ui16 srcSlot, ui16 destSlot) bool CGameHandler::moveArtifact(si32 srcHeroID, StackLocation s2, ui16 srcSlot, ui16 destSlot)
{ {
ArtifactLocation src(getHero(srcHeroID), srcSlot); ArtifactLocation src(getHero(srcHeroID), srcSlot);
@ -2595,7 +2593,6 @@ bool CGameHandler::moveArtifact(StackLocation s1, si32 destHeroID, ui16 srcSlot,
moveArtifact(src, dst); moveArtifact(src, dst);
return true; return true;
} }
void CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2) void CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocation &al2)
{ {
MoveArtifact ma; MoveArtifact ma;
@ -2604,8 +2601,6 @@ void CGameHandler::moveArtifact(const ArtifactLocation &al1, const ArtifactLocat
sendAndApply(&ma); sendAndApply(&ma);
} }
/** /**
* Assembles or disassembles a combination artifact. * Assembles or disassembles a combination artifact.
* @param heroID ID of hero holding the artifact(s). * @param heroID ID of hero holding the artifact(s).
@ -4356,27 +4351,32 @@ bool CGameHandler::isAllowedExchange( int id1, int id2 )
return true; return true;
const CGObjectInstance *o1 = getObj(id1), *o2 = getObj(id2); const CGObjectInstance *o1 = getObj(id1), *o2 = getObj(id2);
if (o1 && o2)
if(o1->ID == GameConstants::TOWNI_TYPE)
{ {
const CGTownInstance *t = static_cast<const CGTownInstance*>(o1); if(o1->ID == GameConstants::TOWNI_TYPE)
if(t->visitingHero == o2 || t->garrisonHero == o2) {
const CGTownInstance *t = static_cast<const CGTownInstance*>(o1);
if(t->visitingHero == o2 || t->garrisonHero == o2)
return true;
}
if(o2->ID == GameConstants::TOWNI_TYPE)
{
const CGTownInstance *t = static_cast<const CGTownInstance*>(o2);
if(t->visitingHero == o1 || t->garrisonHero == o1)
return true;
}
if(o1->ID == GameConstants::HEROI_TYPE && o2->ID == GameConstants::HEROI_TYPE
&& distance(o1->pos, o2->pos) < 2) //hero stands on the same tile or on the neighbouring tiles
{
//TODO: it's workaround, we should check if first hero visited second and player hasn't closed exchange window
//(to block moving stacks for free [without visiting] between heroes)
return true; return true;
}
} }
if(o2->ID == GameConstants::TOWNI_TYPE) else //not exchanging between heroes, TODO: more sophisticated logic
{ {
const CGTownInstance *t = static_cast<const CGTownInstance*>(o2); return true;
if(t->visitingHero == o1 || t->garrisonHero == o1)
return true;
} }
if(o1->ID == GameConstants::HEROI_TYPE && o2->ID == GameConstants::HEROI_TYPE
&& distance(o1->pos, o2->pos) < 2) //hero stands on the same tile or on the neighbouring tiles
{
//TODO: it's workaround, we should check if first hero visited second and player hasn't closed exchange window
//(to block moving stacks for free [without visiting] between heroes)
return true;
}
return false; return false;
} }

View File

@ -134,7 +134,20 @@ bool GarrisonHeroSwap::applyGh( CGameHandler *gh )
bool ExchangeArtifacts::applyGh( CGameHandler *gh ) bool ExchangeArtifacts::applyGh( CGameHandler *gh )
{ {
ERROR_IF_NOT_OWNS(hid1);//second hero can be ally ERROR_IF_NOT_OWNS(hid1);//second hero can be ally
return gh->moveArtifact(hid1,hid2,slot1,slot2); if (hid1)
{ //TODO: polymorph
if (hid2)
return gh->moveArtifact(hid1,hid2,slot1,slot2);
else
return gh->moveArtifact(hid1,s2,slot1,slot2);
}
else
{
if (hid2)
return gh->moveArtifact(s1,hid2,slot1,slot2);
else
return gh->moveArtifact(s1,s2,slot1,slot2);
}
} }
bool AssembleArtifacts::applyGh( CGameHandler *gh ) bool AssembleArtifacts::applyGh( CGameHandler *gh )