void EQWHTTPHandler::ProcessAndSend(const std::string &str) { std::string::size_type len = str.length(); std::string::size_type start = 0; std::string::size_type pos, end; while((pos = str.find("<?", start)) != std::string::npos) { //send all the crap leading up to the script block if(pos != start) { ProcessText(str.c_str() + start, pos-start); } //look for the end of this script block... end = str.find("?>", pos+2); if(end == std::string::npos) { //terminal ?> not found... should issue a warning or something... std::string scriptBody = str.substr(pos+2); ProcessScript(scriptBody); start = len; break; } else { //script only consumes some of this buffer... std::string scriptBody = str.substr(pos+2, end-pos-2); ProcessScript(scriptBody); start = end + 2; } } //send whatever is left over if(start != len) ProcessText(str.c_str() + start, len-start); }
MESSAGE_STRUC::MESSAGE_STRUC(int scrpt,MsgType mtype,VoiceType vox,ItemBasePtr about,AirStrucPtr to)//RJS 02Apr99 { messagetype = mtype; caller = NULL; target = about; callee = to; voiceindex = vox; decisionhandler = NULL; //DeadCode AMM 20Oct100 if (_Replay.Playback) //DeadCode AMM 20Oct100 { //DeadCode AMM 20Oct100 messagetype = MsgType(MSG_LP | MSG_BLOCKCHATTER); //DeadCode AMM 20Oct100 scrpt = 0; //DeadCode AMM 20Oct100 } ProcessScript(scrpt); ProcessUserMessage(); }
MESSAGE_STRUC::MESSAGE_STRUC(int scrpt,MsgType mtype,MobileItemPtr from,ItemBasePtr about,AirStrucPtr to,const TARGET_INDEXES& tindex) { messagetype = mtype; caller = *from; target = about; callee = to; targetinfo = tindex; decisionhandler = NULL; //DeadCode AMM 20Oct100 if (_Replay.Playback) //DeadCode AMM 20Oct100 { //DeadCode AMM 20Oct100 messagetype = MsgType(MSG_LP | MSG_BLOCKCHATTER); //DeadCode AMM 20Oct100 scrpt = 0; //DeadCode AMM 20Oct100 } SetVoiceType(); ProcessScript(scrpt); ProcessUserMessage(); //DeadCode RJS 29Sep00 SetVoiceType(); }
bool CDialogLoaderMK2::LoadScript(const string& stripPath, const string& filename, TDialogScriptMap& outScriptMap) { XmlNodeRef rootNode = GetISystem()->LoadXmlFromFile(filename); if (!rootNode) { GameWarning("[DIALOG] CDialogLoaderMK2::LoadScripts: Cannot find/load file '%s'", filename.c_str()); return false; } if (rootNode->isTag("DialogScript") == false) { GameWarning("[DIALOG] CDialogLoaderMK2::LoadScripts: File '%s' not a dialog script.", filename.c_str()); return false; } string scriptName = PathUtil::ToUnixPath(filename); // now remove prefix if (CryStringUtils::stristr(scriptName.c_str(), stripPath.c_str()) == scriptName.c_str()) scriptName = scriptName.Mid(stripPath.length()); PathUtil::RemoveExtension(scriptName); scriptName.replace('/', '.'); // Make nice uppercase name, if storedId and filename match case-insensitive const char* storedId = rootNode->getAttr("Name"); if (storedId!=0 && stricmp(storedId, scriptName.c_str()) == 0) { scriptName.assign(storedId); } CDialogScript* pScript = new CDialogScript(scriptName); bool bOK = ProcessScript(pScript, rootNode); if (bOK) { // try to complete the script if (pScript->Complete() == true) { // add it to the map std::pair<TDialogScriptMap::iterator, bool> inserted = outScriptMap.insert(TDialogScriptMap::value_type(pScript->GetID(), pScript)); if (inserted.second == false) { bOK = false; GameWarning("[DIALOG] CDialogLoaderMK2::ProcessScript '%s': Script already defined. Discarded", scriptName.c_str()); } } // completion not successful -> discard else { bOK = false; GameWarning("[DIALOG] CDialogLoaderMK2::ProcessScript '%s': Cannot complete Script. Discarded.", scriptName.c_str()); } } // discard pScript if (bOK == false) { delete pScript; } return bOK; }
int CDialogLoader::LoadFromTable(XmlNodeRef tableNode, const string& groupName, TDialogScriptMap& outScriptMap) { unsigned char nCellIndexToType[MAX_CELL_COUNT]; memset(nCellIndexToType, ATTR_SKIP, sizeof(nCellIndexToType) ); IMScript theScript; int nNumGoodScripts = 0; int nRowIndex = 0; int nChilds = tableNode->getChildCount(); for (int i=0; i<nChilds; ++i) { XmlNodeRef rowNode = tableNode->getChild(i); if (!rowNode || !rowNode->isTag("Row")) continue; ++nRowIndex; // skip first row as it should only contain column description if (nRowIndex == 1) { FillMapping(rowNode, nCellIndexToType); continue; } IMScriptLine scriptLine; bool bLineValid = false; int nColCount = rowNode->getChildCount(); int nCellIndex = 0; for (int j=0; j<nColCount; ++j) { XmlNodeRef cellNode = rowNode->getChild(j); if (!cellNode || !cellNode->isTag("Cell")) continue; int tmpIndex = 0; if (cellNode->getAttr("ss:Index", tmpIndex)) { nCellIndex = tmpIndex-1; } if (nCellIndex < 0 || nCellIndex >= MAX_CELL_COUNT) break; XmlNodeRef cellDataNode = cellNode->findChild("Data"); if (!cellDataNode) { ++nCellIndex; continue; } unsigned char nCellType = nCellIndexToType[nCellIndex]; const char* content = cellDataNode->getContent(); // nRowIndex and nCellIndex should be correct now [1-based, not 0-based!] switch (nCellType) { case ATTR_SKIP: break; case ATTR_DIALOG: if (theScript.IsValid()) { const bool ok = ProcessScript(theScript, groupName, outScriptMap); if (ok) ++nNumGoodScripts; theScript.Reset(); } theScript.name = content; break; case ATTR_ACTOR: scriptLine.actor = content; bLineValid = true; break; case ATTR_AUDIO: if (bLineValid) { if(content == 0) scriptLine.audioID = INVALID_AUDIO_CONTROL_ID; else gEnv->pAudioSystem->GetAudioTriggerID(content, scriptLine.audioID); } break; case ATTR_ANIM: if (bLineValid) scriptLine.anim = content; break; case ATTR_FACIAL: if (bLineValid) { size_t n = strcspn(content, ":; "); if (n == strlen(content)) { scriptLine.facial = content; scriptLine.facialWeight = 0.5f; scriptLine.facialFadeTime = 0.5f; } else { scriptLine.facial.assign ( content, n ); float w = 0.5f; float t = 0.5f; int nGood = sscanf(content+n+1, "%f%*[:; ]%f",&w,&t); if (nGood != 1 && nGood != 2) { GameWarning("[DIALOG] CDialogLoader::LoadFromTable: DialogScript '%s' has invalid Facial Expression Content '%s'. Using weight=%f fadetime=%f.", groupName.c_str(), content,w,t); } scriptLine.facialWeight = w; scriptLine.facialFadeTime = t; } } break; case ATTR_LOOKAT: if (bLineValid) scriptLine.lookat = content; break; case ATTR_DELAY: if (bLineValid) { float val = 0.0f; int n = sscanf(content,"%f", &val); if (n == 1) { scriptLine.delay = val; } } break; default: break; } ++nCellIndex; } if (scriptLine.IsValid()) { theScript.lines.push_back(scriptLine); } } if (theScript.IsValid()) { const bool ok = ProcessScript(theScript, groupName, outScriptMap); if (ok) ++nNumGoodScripts; } return nNumGoodScripts; }
/*********************************************************** do all check to be done when idle ***********************************************************/ void ExternalPlayer::Process(double tnow, float tdiff, ScriptEnvironmentBase* scripthandler) { if(_playingscript) { // process script if(!ProcessScript(tnow, tdiff, scripthandler)) { // if not moved - move with attached actor if(_attachedactor) { boost::shared_ptr<PhysicalObjectHandlerBase> physo = _character->GetPhysicalObject(); boost::shared_ptr<PhysicalObjectHandlerBase> attchedphys = _attachedactor->GetPhysicalObject(); if(physo && attchedphys) { physo->RotateYAxis(attchedphys->GetLastRotation()); float addspeedX=0, addspeedY=0, addspeedZ=0; attchedphys->GetLastMove(addspeedX, addspeedY, addspeedZ); physo->Move(addspeedX, addspeedY, addspeedZ); } } } //still update dead recon _dr.Update(tnow, tdiff); return; } //update display and animation _character->Process(tnow, tdiff); if(_shouldupdate) { boost::shared_ptr<PhysicalObjectHandlerBase> physo = _character->GetPhysicalObject(); // calculate prediction float predicted_posX, predicted_posY, predicted_posZ; physo->GetPosition(predicted_posX, predicted_posY, predicted_posZ); predicted_posX += (_velocityX*tdiff); predicted_posY += (_velocityY*tdiff); predicted_posZ += (_velocityZ*tdiff); float predicted_rotation = physo->GetRotationYAxis() + (_velocityR*tdiff); // calculate dead reckon _dr.Update(tnow, tdiff); //// do interpolation X { float diffX = (_dr._predicted_posX - predicted_posX); if(fabs(diffX) > 8) predicted_posX = _dr._predicted_posX; else predicted_posX += diffX / 40; } //// do interpolation Y { float diffY = (_dr._predicted_posY - predicted_posY); if(fabs(diffY) > 8) predicted_posY = _dr._predicted_posY; else predicted_posY += diffY / 40; } //// do interpolation Z { float diffZ = (_dr._predicted_posZ - predicted_posZ); if(fabs(diffZ) > 8) predicted_posZ = _dr._predicted_posZ; else predicted_posZ += diffZ / 40; } //// do interpolation rotation { float diffR = (_dr._predicted_rotation - predicted_rotation); if(fabs(diffR) > 20) predicted_rotation = _dr._predicted_rotation; else predicted_rotation += diffR / 5; } physo->MoveTo(predicted_posX, predicted_posY, predicted_posZ); LbaQuaternion Q(predicted_rotation, LbaVec3(0,1,0)); physo->RotateTo(Q); } }
wxString CslGameRedEclipse::GameStart(CslServerInfo *info,wxUint32 mode,wxString& error) { wxString address,password,path,script; wxString bin=m_clientSettings.Binary; wxString opts=m_clientSettings.Options; wxString preScript=m_clientSettings.PreScript; wxString postScript=m_clientSettings.PostScript; if (m_clientSettings.Binary.IsEmpty() || !::wxFileExists(m_clientSettings.Binary)) { error=_("Client binary for game Red Eclipse not found!\nCheck your settings."); return wxEmptyString; } if (m_clientSettings.GamePath.IsEmpty() || !::wxDirExists(m_clientSettings.GamePath)) { error=_("Game path for game Red Eclipse not found!\nCheck your settings."); return wxEmptyString; } if (m_clientSettings.ConfigPath.IsEmpty() || !::wxDirExists(m_clientSettings.ConfigPath)) { error=_("Config path for game Red Eclipse not found!\nCheck your settings."); return wxEmptyString; } path=m_clientSettings.ConfigPath; #ifdef __WXMSW__ //binary must be surrounded by quotes if the path contains spaces bin=wxT("\"")+m_clientSettings.Binary+wxT("\""); // use Prepend() and do not use opts+= here, since -h<path> must be before -r opts.Prepend(wxT("\"-h")+path.RemoveLast()+wxT("\" ")); #else CmdlineEscapeSpaces(bin); CmdlineEscapeSpaces(path); // use Prepend() and do not use opts+= here, since -h<path> must be before -r opts.Prepend(wxT("-h")+path+wxT(" ")); #endif //__WXMSW__ ProcessScript(*info,mode,preScript); ProcessScript(*info,mode,postScript); if (!preScript.IsEmpty()) { preScript<<wxT(";"); CmdlineEscapeQuotes(preScript); } if (!postScript.IsEmpty()) { postScript.Prepend(wxT(";")); CmdlineEscapeQuotes(postScript); } address=info->Host; password<<wxT("\""); password<<(mode==CslServerInfo::CSL_CONNECT_PASS ? info->Password : mode==CslServerInfo::CSL_CONNECT_ADMIN_PASS ? info->PasswordAdmin : wxString(wxEmptyString)); password<<wxT("\""); CmdlineEscapeQuotes(password); if (GetDefaultGamePort()!=info->GamePort || mode==CslServerInfo::CSL_CONNECT_PASS) address<<wxString::Format(wxT(" %d %d"),info->GamePort,info->InfoPort); script=wxString::Format(wxT("%sconnect %s %s%s"), preScript.c_str(), address.c_str(),password.c_str(), postScript.c_str()); #ifdef __WXMSW__ opts<<wxT(" \"-x")<<script<<wxT("\""); #else opts<<wxT(" -x")<<CmdlineEscapeSpaces(script); #endif bin<<wxT(" ")<<opts; LOG_DEBUG("start client: %s\n",U2A(bin)); return bin; }