Exemplo n.º 1
0
// OfferLinkingBook ---------------------------------------------------------------
// ----------
void plAvatarMgr::OfferLinkingBook(plKey hostKey, plKey guestKey, plMessage *linkMsg, plKey replyKey)
{
    if(hostKey != nil && guestKey != nil)
    {
        const plArmatureMod *hostAv = FindAvatar(hostKey);
        const plArmatureMod *guestAv = FindAvatar(guestKey);

        hsAssert(hostAv && guestAv, "Offering linking book: host or guest missing.");

        if(hostAv && guestAv)
        {

            // make the host brain
            plAvBrainCoop * brainH = new plAvBrainCoop(plAvBrainGeneric::kExitNormal, 3.0, 3.0, plAvBrainGeneric::kMoveRelative, guestKey);

            plAnimStage *hostOffer = new plAnimStage("BookOffer", plAnimStage::kNotifyAdvance);     // autoforward, autoadvance
            // repeats until the guest brain tells us that it's done
            plAnimStage *hostIdle = new plAnimStage("BookOfferIdle", plAnimStage::kNotifyEnter, plAnimStage::kForwardAuto, plAnimStage::kBackNone,
                                                    plAnimStage::kAdvanceNone, plAnimStage::kRegressNone, -1);

            plAnimStage *hostFinish = new plAnimStage("BookOfferFinish", plAnimStage::kNotifyAdvance);  // autoforward, autoadvance
            
            brainH->AddStage(hostOffer);
            brainH->AddStage(hostIdle);
            brainH->AddStage(hostFinish);

            uint32_t hostID = brainH->GetInitiatorID();
            uint32_t hostSerial = brainH->GetInitiatorSerial();


            // make the guest brain
            plAvBrainCoop * brainG = new plAvBrainCoop(plAvBrainGeneric::kExitNormal, 3.0, 3.0, plAvBrainGeneric::kMoveRelative,
                                                       hostID, (uint16_t)hostSerial, hostKey);

            plAnimStage *guestAccept = new plAnimStage("BookAccept", plAnimStage::kNotifyAdvance);
            plAnimStage *guestAcceptIdle = new plAnimStage("BookAcceptIdle", plAnimStage::kNotifyEnter, plAnimStage::kForwardAuto, plAnimStage::kBackNone,
                                                           plAnimStage::kAdvanceNone, plAnimStage::kRegressNone, -1);
            
            brainG->AddStage(guestAccept);
            brainG->AddStage(guestAcceptIdle);
            plCoopCoordinator *coord = new plCoopCoordinator(hostKey, guestKey, brainH, brainG, "Convergence", 1, 1, linkMsg, true);


            plAvCoopMsg *coMg = new plAvCoopMsg(hostKey, coord);
            coMg->SetBCastFlag(plMessage::kNetPropagate);
            coMg->SetBCastFlag(plMessage::kNetForce);

            coMg->Send();
            brainH->SetRecipient(replyKey);
            brainG->SetRecipient(replyKey);

        }
    }
}
Exemplo n.º 2
0
void plAvatarMgr::IFinishLoadingAvatar(plLoadAvatarMsg *cloneMsg)
{
    plKey avatarKey = cloneMsg->GetCloneKey();
    plUoid playerUoid = avatarKey->GetUoid();
    const plArmatureMod *armature = FindAvatar(avatarKey);

    // we're going to re-send the clone message to the loaded avatar so he can get
    // any necessary details from it.
    cloneMsg->ClearReceivers();     // don't want it coming back to us
    cloneMsg->Ref();                // or going away

    if(armature)
    {
        cloneMsg->AddReceiver(armature->GetKey());
        cloneMsg->Send();
    } else {
        IDeferInit(avatarKey, cloneMsg);        // we'll send this message when the armature mod loads.
    }

    if( cloneMsg->GetIsPlayer() )
    {
        // notify everyone who cares that a new player has arrived
        // *** might want to move this to the human brain so we can make sure the 
        // *** avatar is sufficiently initialized before anyone accesses him
        bool isLocal = cloneMsg->GetOriginatingPlayerID() == plNetClientMgr::GetInstance()->GetPlayerID();
        plPlayerPageMsg* pageM = new plPlayerPageMsg;
        pageM->SetBCastFlag(plMessage::kBCastByExactType);
        pageM->fLocallyOriginated = isLocal;
        pageM->fPlayer = avatarKey;
        pageM->fUnload = false;
        pageM->fClientID = cloneMsg->GetOriginatingPlayerID();
        pageM->Send();
    }

    // This can probably be replaced by the plPlayerPageMsg:
    // ...keeping for the moment for compatibility
    plMemberUpdateMsg* mu = new plMemberUpdateMsg;
    mu->Send();
}
Exemplo n.º 3
0
bool CPlayers::LoadPlayers () {
	if (FileExists (param.config_dir, "players") == false) {
		SetDefaultPlayers ();
		Message ("file 'players' does not exist, set default players");
		return false;
	}

	CSPList list(MAX_PLAYERS);
	if (list.Load (param.config_dir, "players") == false) {
		SetDefaultPlayers ();
		Message ("could not load players list, set default players");
		return false;
	}

	g_game.start_player = 0;
	g_game.start_character = 0;
	plyr.resize(list.Count());
	for (size_t i=0; i<list.Count(); i++) {
		const string& line = list.Line(i);
		plyr[i].name = SPStrN (line, "name", "unknown");
		plyr[i].funlocked = SPStrN (line, "unlocked");
		plyr[i].avatar = FindAvatar(SPStrN(line, "avatar"));
		plyr[i].ctrl = NULL;
		int active = SPIntN (line, "active", 0);
		int ch = SPIntN(line, "character", 0);
		if (ch > 0) plyr[i].character = ch;
		if (active > 0) {
			g_game.start_player = i;
			if (ch > 0) g_game.start_character = ch;
		}
	}
	if (plyr.empty()) {
		SetDefaultPlayers ();
		Message ("player file doesn't contain a player, set default players");
		return false;
	}
	return true;
}
Exemplo n.º 4
0
// ISENDDEFERREDINIT
void plAvatarMgr::ISendDeferredInit(plKey avatarSOKey)
{
    // get armaturemod
    const plArmatureMod * armature = FindAvatar(avatarSOKey);

    if(armature)
    {
        DeferredInits::iterator i = fDeferredInits.find(avatarSOKey);
        bool found = (i != fDeferredInits.end());

        if(i != fDeferredInits.end())
        {
            plMessage * initMsg = (*i).second;
            hsAssert(initMsg, "Tried to init avatar, but found nil initialization message.");
            
            if(initMsg)
            {
                initMsg->AddReceiver(armature->GetKey());
                initMsg->Send();
            }
        }
    }
}
Exemplo n.º 5
0
void CPlayers::SetDefaultPlayers () {
	plyr.push_back(TPlayer("Racer", FindAvatar("avatar01.png")));
	plyr.push_back(TPlayer("Bunny", FindAvatar("avatar02.png")));
}
Exemplo n.º 6
0
void CPlayers::AddPlayer (const string& name, const string& avatar) {
	plyr.push_back(TPlayer(name, FindAvatar(avatar)));
}