{-# LANGUAGE OverloadedStrings #-}-- | Factions taking part in the game: e.g., two human players controlling-- the hero faction battling the monster and the animal factions.moduleGame.LambdaHack.Common.Faction(FactionId,FactionDict,Faction(..),Diplomacy(..),Outcome(..),Status(..),isHumanFact,usesAIFact,isSpawnFact,isSummonFact,isAtWar,isAllied)whereimportData.BinaryimportqualifiedData.EnumMap.StrictasEMimportData.MaybeimportData.Text(Text)importGame.LambdaHack.Common.ActorimportqualifiedGame.LambdaHack.Common.ColorasColorimportqualifiedGame.LambdaHack.Common.KindasKindimportGame.LambdaHack.Common.MiscimportGame.LambdaHack.Content.FactionKindimportGame.LambdaHack.Content.StrategyKind-- | All factions in the game, indexed by faction identifier.typeFactionDict=EM.EnumMapFactionIdFactiondataFaction=Faction{gkind::!(Kind.IdFactionKind)-- ^ the kind of the faction,gname::!Text-- ^ individual name,gconfig::!Text-- ^ raw name specified in config,gAiLeader::!(Maybe(Kind.IdStrategyKind))-- ^ AI for the leaders;-- Nothing means human-controlled,gAiMember::!(Maybe(Kind.IdStrategyKind))-- ^ AI to use for other actors;-- Nothing means human-controlled,gdipl::!Dipl-- ^ diplomatic mode,gquit::!(MaybeStatus)-- ^ cause of game end/exit,gleader::!(MaybeActorId),gcolor::!Color.Color-- ^ color of actors or their frames,ginitial::!Int-- ^ number of initial actors,gentry::!LevelId-- ^ level where initial actors start}deriving(Show,Eq)-- | Diplomacy states. Higher overwrite lower in case of assymetric content.dataDiplomacy=Unknown|Neutral|Alliance|Warderiving(Show,Eq,Ord)typeDipl=EM.EnumMapFactionIdDiplomacy-- | Outcome of a game.dataOutcome=Killed-- ^ the faction was eliminated|Defeated-- ^ the faction lost the game in another way|Camping-- ^ game is supended|Conquer-- ^ the player won by eliminating all rivals|Escape-- ^ the player escaped the dungeon alive|Restart-- ^ game is restartedderiving(Show,Eq,Ord)-- | Current game status.dataStatus=Status{stOutcome::Outcome-- ^ current game outcome,stDepth::Int-- ^ depth of the final encounter,stInfo::Text-- ^ extra information}deriving(Show,Eq,Ord)-- | Tell whether the faction is controlled (at least partially) by a human.isHumanFact::Faction->BoolisHumanFactfact=isNothing(gAiLeaderfact)||isNothing(gAiMemberfact)-- | Tell whether the faction uses AI to control any of its actors.usesAIFact::Faction->BoolusesAIFactfact=isJust(gAiLeaderfact)||isJust(gAiMemberfact)-- | Tell whether the faction can spawn actors.isSpawnFact::Kind.COps->Faction->BoolisSpawnFactKind.COps{cofact=Kind.Ops{okind}}fact=letkind=okind(gkindfact)inmaybeFalse(>0)$lookup"spawn"$ffreqkind-- | Tell whether actors of the faction can be summoned by items, etc..isSummonFact::Kind.COps->Faction->BoolisSummonFactKind.COps{cofact=Kind.Ops{okind}}fact=letkind=okind(gkindfact)inmaybeFalse(>0)$lookup"summon"$ffreqkind-- | Check if factions are at war. Assumes symmetry.isAtWar::Faction->FactionId->BoolisAtWarfactfid=War==EM.findWithDefaultUnknownfid(gdiplfact)-- | Check if factions are allied. Assumes symmetry.isAllied::Faction->FactionId->BoolisAlliedfactfid=Alliance==EM.findWithDefaultUnknownfid(gdiplfact)instanceBinaryFactionwhereputFaction{..}=doputgkindputgnameputgconfigputgAiLeaderputgAiMemberputgdiplputgquitputgleaderputgcolorputginitialputgentryget=dogkind<-getgname<-getgconfig<-getgAiLeader<-getgAiMember<-getgdipl<-getgquit<-getgleader<-getgcolor<-getginitial<-getgentry<-getreturnFaction{..}instanceBinaryDiplomacywhereputUnknown=putWord80putNeutral=putWord81putAlliance=putWord82putWar=putWord83get=dotag<-getWord8casetagof0->returnUnknown1->returnNeutral2->returnAlliance3->returnWar_->fail"no parse (Diplomacy)"instanceBinaryOutcomewhereputKilled=putWord80putDefeated=putWord81putCamping=putWord82putConquer=putWord83putEscape=putWord84putRestart=putWord85get=dotag<-getWord8casetagof0->returnKilled1->returnDefeated2->returnCamping3->returnConquer4->returnEscape5->returnRestart_->fail"no parse (Outcome)"instanceBinaryStatuswhereputStatus{..}=doputstOutcomeputstDepthputstInfoget=dostOutcome<-getstDepth<-getstInfo<-getreturnStatus{..}