int csPixelShaderParser::GetArguments (const csString &str, csString &dest, csString &src1, csString &src2, csString &src3, csString &src4) { size_t start = str.FindFirst (' '); if (start == (size_t)-1) return 0; int argument = 0; size_t len = str.Length (); while(argument < 5 && start < len) { size_t end = str.FindFirst (',', start + 1); if(end == (size_t)-1) end = str.Length (); if(end - start < 1) break;; csString reg; str.SubString (reg, start, end - start); reg.Trim (); switch(argument) { default: break; case 0: dest = reg; break; case 1: src1 = reg; break; case 2: src2 = reg; break; case 3: src3 = reg; break; case 4: src4 = reg; break; } argument ++; start = end + 1; } return argument; }
bool LoadPrerequisiteXML(csRef<psQuestPrereqOp>& prerequisite, psQuest * self, csString script) { csRef<iDocumentSystem> xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem); csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse( script ); if ( error ) { Error3("%s\n%s",error, script.GetDataSafe() ); return false; } csRef<iDocumentNode> root = doc->GetRoot(); if(!root) { Error1("No XML root in prerequisite script"); return false; } csRef<iDocumentNode> topNode = root->GetNode("pre"); if (topNode) { return LoadPrerequisiteXML(topNode,self,prerequisite); } else { Error3("Could not find <pre> tag in prerequisite script '%s' for quest '%s'!", script.GetData(),(self?self->GetName():"(null)")); return false; } return true; }
void SpellManager::SaveSpell(Client* client, csString spellName) { psSpell* spell = client->GetCharacterData()->GetSpellByName(spellName); if(spell) { psserver->SendSystemInfo(client->GetClientNum(), "You know the %s spell already!",spellName.GetData()); return; } spell = cacheManager->GetSpellByName(spellName); if(!spell) { psserver->SendSystemInfo(client->GetClientNum(), "%s isn't a defined spell!",spellName.GetData()); return; } client->GetCharacterData()->AddSpell(spell); psServer::CharacterLoader.SaveCharacterData(client->GetCharacterData(),client->GetActor()); SendSpellBook(NULL,client); psserver->SendSystemInfo(client->GetClientNum(), "%s added to your spell book!",spellName.GetData()); }
void pawsExchangeWindow::StartExchange( csString& player, bool withPlayer ) { csString text; if(!player.IsEmpty()) { text.Format("Trading with %s",player.GetData()); } int width; Clear(); Show(); pawsTextBox* textBox = dynamic_cast <pawsTextBox*> (FindWidget("other_player")); if (textBox != NULL) textBox->SetText( text ); if (withPlayer) width = 350; else width = 175; SetRelativeFrameSize(GetActualWidth(width), defaultFrame.Height()); // Autoshow the inventory pawsWidget* widget = PawsManager::GetSingleton().FindWidget("SmallInventoryWindow"); if (widget) { wasSmallInventoryOpen = widget->IsVisible(); widget->Show(); } }
bool ZoneHandler::ForceLoadWindowWidget(bool enable, csString loadWindowName) { if(enable) { //check first if the window name is valid. shouldn't end up here if(loadWindowName.IsEmpty()) { return false; } else //if it's valid we load it and set it as load window for now { PawsManager::GetSingleton().LoadWidget(loadWindowName.GetData()); //request the load window to update the new window if(loadWindow) loadWindow->PublishMOTD(); return FindLoadWindow(true, loadWindowName.GetData()); } } else //restore the pointers to the normal window and removes the specified window from the memory { //restore the ties to the default load window bool result = FindLoadWindow(true); //as we have reloaded the load window we can remove the widget we don't need anymore if(loadWindowName.Length()) PawsManager::GetSingleton().RemoveWidget(loadWindowName.GetData(), false); return result; } return true; }
void HandleAnswer(const csString & answer) { PendingQuestion::HandleAnswer(answer); if ( dynamic_cast<psItem*>(item) == NULL ) { Error2("Item held in PendingLootPrompt with id %u has been lost",id); return; } gemActor* looter = gemSupervisor->FindPlayerEntity(looterID); gemActor* roller = gemSupervisor->FindPlayerEntity(rollerID); gemActor* getter = (answer == "yes") ? looter : roller ; // If the getter left the world, default to the other player if (!getter /*|| !getter->InGroup()*/ ) { getter = (answer == "yes") ? roller : looter ; // If the other player also vanished, get rid of the item and be done with it... if (!getter /*|| !getter->InGroup()*/ ) { cacheManager->RemoveInstance(item); return; } } // Create the loot message csString lootmsg; lootmsg.Format("%s was %s a %s by roll winner %s", lootername.GetData(), (getter == looter) ? "allowed to loot" : "stopped from looting", item->GetName(), rollername.GetData() ); // Attempt to give to getter bool dropped = getter->GetCharacterData()->Inventory().AddOrDrop(item); if (!dropped) lootmsg.Append(", but can't hold anymore"); // Send out the loot message psSystemMessage loot(getter->GetClientID(), MSG_LOOT, lootmsg.GetData() ); getter->SendGroupMessage(loot.msg); psLootEvent evt( looteeID, looteename, getter->GetCharacterData()->GetPID(), lootername, item->GetUID(), item->GetName(), item->GetStackCount(), (int)item->GetCurrentStats()->GetQuality(), 0 ); evt.FireEvent(); }
bool pawsNumbersPromptWindow::TextIsValidForOutput(const csString & text) { if (text.Length() == 0) return false; int number = atoi(text.GetData()); return TextIsValidForEditing(text) && (number >= 0) && (number >= minNumber); }
void psWorld::GetAllRegionNames(csString &str) { str.Clear(); for(unsigned i=0; i < regions->GetSize(); i++) { str.Append(regions->Get(i)); str.Append("|"); } }
//----------------------------------------------------------------------------- bool psNPCLoader::SaveToFile(int id, csString &filename) { filename.Insert(0,"/this/"); psCharacterLoader loader; npc = loader.LoadCharacterData(id,false); if(!npc) { CPrintf(CON_ERROR, "Error: Couldn't load NPC with id: %i\n",id); return false; } //*npc = *character; // removed npcID = id; area = npc->GetCharName(); csRef<iDocumentSystem> xml; xml.AttachNew(new csTinyDocumentSystem); csRef<iDocument> doc = xml->CreateDocument(); csRef<iDocumentNode> root = doc->CreateRoot(); npcRoot = root->CreateNodeBefore(CS_NODE_ELEMENT); npcRoot->SetValue("npc"); WriteBasicInfo(); WriteDescription(); WriteLocation(); WriteStats(); WriteMoney(); WriteEquipment(); WriteFactions(); WriteSkills(); WriteMerchantInfo(); WriteTrainerInfo(); WriteKnowledgeAreas(); WriteSpecificKnowledge(); csRef<iVFS> vfs = csQueryRegistry<iVFS> (psserver->GetObjectReg()); if(!vfs) return false; csString error = doc->Write(vfs, filename); if(!error.IsEmpty()) { CPrintf(CON_ERROR, "Error writing to file %s: %s\n",filename.GetData(), error.GetData()); return false; } return true; }
csString psOperProfile::Dump(double totalConsumption, const csString & unitName) { double perc = consumption/totalConsumption*100; if (perc > 0) return csString().Format( "count=%-5u perc=%.1lf %s=%-2i avg-%s=%.3f max=%.3f Name=%s\n", unsigned(count), perc, unitName.GetData(), int(consumption), unitName.GetData(), consumption/count, maxCons, desc.GetData()); else return ""; }
static inline void TestTarget(csString& targetDesc, int32_t targetType, enum TARGET_TYPES type, const char* desc) { if (targetType & type) { if (targetDesc.Length() > 0) { targetDesc.Append((targetType > (type * 2)) ? ", " : ", or "); } targetDesc.Append(desc); } }
// converts hexadecimal string to color in current pixel format int ParseColor(const csString &str, iGraphics2D* g2d) { int r, g, b; if(str.Length() != 6) return false; r = HexToDec8(str.GetAt(0), str.GetAt(1)); g = HexToDec8(str.GetAt(2), str.GetAt(3)); b = HexToDec8(str.GetAt(4), str.GetAt(5)); return g2d->FindRGB(r, g, b); }
bool psCharAppearance::Dequip(csString& slotname, csString& mesh, csString& part, csString& subMesh, csString& texture) { //look Equip() for more informations on this: bracers must be managed separately if (slotname == "bracers") { for(unsigned int position = 0; position < bracersSlotCount; position++) Dequip(BracersSlots[position], mesh, part, subMesh, texture); return true; } if ( slotname == "helm" ) { ShowHair(true); } if ( mesh.Length() ) { ClearEquipment(slotname); Detach(slotname); } // This is a part mesh (ie Mesh) set default mesh for that part. if ( subMesh.Length() ) { DefaultMesh(part); } if ( part.Length() ) { if ( texture.Length() ) { ChangeMaterial(part, texture); } else { DefaultMaterial(part); } DefaultMaterial(part); } ClearEquipment(slotname); return true; }
bool AssetManager::LoadAsset (const csString& normpath, const csString& file, const csString& mount, iCollection* collection) { csRef<iString> path; if (!normpath.IsEmpty ()) { csRef<scfStringArray> fullPath = ConstructPath (); path = FindAsset (fullPath, normpath, file); if (!path) return Error ("Cannot find asset '%s' in the asset path!\n", normpath.GetData ()); } csString rmount; if (mount.IsEmpty ()) { rmount.Format ("/assets/__mnt_%d__/", mntCounter); mntCounter++; } else { rmount = mount; } if (path) { vfs->Mount (rmount, path->GetData ()); printf ("Mounting '%s' to '%s'\n", path->GetData (), rmount.GetData ()); fflush (stdout); } vfs->PushDir (rmount); // If the file doesn't exist we don't try to load it. That's not an error // as it might be saved later. bool exists = vfs->Exists (file); vfs->PopDir (); if (exists) { if (!LoadLibrary (rmount, file, collection)) return false; } else { Warn ("Warning! File '%s/%s' does not exist!\n", (!path) ? rmount.GetData () : path->GetData (), file.GetData ()); } //if (!path.IsEmpty ()) //vfs->Unmount (rmount, path); return true; }
void psCommandManager::BuildXML(int securityLevel, csString &dest, bool subscribe) { CommandGroup* grp = commandGroups.Get(securityLevel, NULL); if(!grp) return; dest.AppendFmt("<subscribe value='%s' />", subscribe ? "true":"false"); for(size_t z = 0; z < grp->commands.GetSize(); z++) { csString cmd(grp->commands[z].GetData()); if(cmd.GetAt(0) == '/') // Make a list of the commands, but leave out the specials dest.AppendFmt("<command name='%s' />", cmd.GetData()); } }
static inline bool AddToPathEnv (csString dir, csString& pathEnv) { // check if installdir is in the path. bool gotpath = false; size_t dlen = dir.Length(); // csGetInstallDir() might return "" (current dir) if (dlen != 0) { ToLower (dir); if (!pathEnv.IsEmpty()) { csString mypath (pathEnv); ToLower (mypath); const char* ppos = strstr (mypath.GetData(), dir); while (!gotpath && ppos) { const char* npos = strchr (ppos, ';'); size_t len = npos ? npos - ppos : strlen (ppos); if ((len == dlen) || (len == dlen+1)) { if (ppos[len] == '\\') len--; if (!strncmp (ppos, dir, len)) { // found it gotpath = true; } } ppos = npos ? strstr (npos+1, dir) : 0; } } if (!gotpath) { // put CRYSTAL path into PATH environment. csString newpath; newpath.Append (dir); newpath.Append (";"); newpath.Append (pathEnv); pathEnv = newpath; return true; } } return false; }
void ProximityList::DebugDumpContents(csString& out) { size_t x; csString temp; temp.AppendFmt("I represent client %d\n",clientnum); temp.AppendFmt("I am publishing updates to:\n"); for (x = 0; x < objectsThatWatchMe.GetSize(); x++ ) { temp.AppendFmt( "\tClient %d (%s), range %1.2f min_range %.2f\n", objectsThatWatchMe[x].client, ((gemObject*)(objectsThatWatchMe[x].object))->GetName(), objectsThatWatchMe[x].dist, objectsThatWatchMe[x].min_dist); } if (clientnum) { temp.Append( "I am listening to:\n"); for (x = 0; x < objectsThatIWatch.GetSize(); x++ ) { gemObject * obj = objectsThatIWatch[x]; temp.AppendFmt("\t%-3d %s\n", obj->GetEID().Unbox(), obj->GetName()); } } else { temp.Append("I am not a human player, so I don't subscribe to other entities.\n"); } out.Append(temp); }
void psServerStatusRunEvent::ReportClient(Client * curr, ClientStatusLogger & clientLogger, csString & reportString) { if (curr->IsSuperClient() || !curr->GetActor()) return; const psCharacter *chr = curr->GetCharacterData(); // log this client's info with the clientLogger clientLogger.LogClientInfo(curr); psGuildInfo *guild = curr->GetActor()->GetGuild(); csString guildTitle; csString guildName; if (guild && guild->id && !guild->IsSecret()) { psGuildLevel *level = curr->GetActor()->GetGuildLevel(); if (level) { guildTitle = EscpXML(level->title); } guildName = EscpXML(guild->name); } reportString.AppendFmt("<player name=\"%s\" characterID=\"%u\" guild=\"%s\" title=\"%s\" security=\"%d\" kills=\"%u\" deaths=\"%u\" suicides=\"%u\" pos_x=\"%.2f\" pos_y=\"%.2f\" pos_z=\"%.2f\" sector=\"%s\" />\n", EscpXML(curr->GetName()).GetData(), chr->GetPID().Unbox(), guildName.GetDataSafe(), guildTitle.GetDataSafe(), curr->GetSecurityLevel(), chr->GetKills(), chr->GetDeaths(), chr->GetSuicides(), chr->location.loc.x, chr->location.loc.y, chr->location.loc.z, EscpXML(chr->location.loc_sector->name).GetData()); }
csRef<iDocument> ParseFile(iObjectRegistry* object_reg, const csString & name) { csRef<iVFS> vfs; csRef<iDocumentSystem> xml; csRef<iDocument> doc; const char* error; vfs = csQueryRegistry<iVFS > ( object_reg); assert(vfs); csRef<iDataBuffer> buff = vfs->ReadFile(name); if (buff == NULL) { //Error2("Could not find file: %s", name.GetData()); return NULL; } xml = csQueryRegistry<iDocumentSystem> (object_reg); if (!xml.IsValid()) xml.AttachNew(new csTinyDocumentSystem); assert(xml); doc = xml->CreateDocument(); assert(doc); error = doc->Parse( buff ); if ( error ) { Error3("Parse error in %s: %s", name.GetData(), error); return NULL; } return doc; }
void pawsControlWindow::AddWindow(csString wndName, csString btnName) { WBName newName; pawsButton* btn = (pawsButton*)FindWidget(btnName.GetData()); if (!btn) { printf("Couldn't find button %s!\n",btnName.GetData()); return; } newName.buttonName = btnName; newName.windowName = wndName; newName.id = btn->GetID(); wbs.Push(newName); }
void pawsNpcDialogWindow::NpcSays(csString &inText,GEMClientActor* actor) { //this is used only when using the chat bubbles interface if(!useBubbles) { return; } clickedOnResponseBubble = false; //display npc response if(IsVisible() && actor && psengine->GetCharManager()->GetTarget() == actor) { dynamic_cast<pawsMultiLineTextBox*>(speechBubble->FindWidget("BubbleText"))->SetText(inText.GetData()); speechBubble->Show(); FindWidget("Bubble1")->Hide(); FindWidget("Bubble2")->Hide(); FindWidget("Bubble3")->Hide(); FindWidget("LeftArrow")->Hide(); FindWidget("RightArrow")->Hide(); FindWidget("FreeBubble")->Hide(); ticks = csGetTicks(); timeDelay = (csTicks)(2000 + 50*strlen(inText.GetData()) + 2000); // add 2 seconds for network delay timeDelay = timeDelay>14000?14000:timeDelay; // clamp to 14000 max Show(); //show the npc dialog } }
unsigned int psEffectManager::RenderEffect(const csString & effectName, iSector * sector, const csVector3 & pos, iMeshWrapper * attachTarget, const csVector3 & up, const unsigned int uniqueIDOverride, const float* scale) { #ifndef DONT_DO_EFFECTS // check if it's a single effect psEffect * currEffect = FindEffect(effectName); if (currEffect != 0) { currEffect = currEffect->Clone(); if (scale != NULL) { if (!currEffect->SetFrameParamScalings(scale)) { Error2("Received scale factor for effect %s that don't use param scaling",effectName.GetDataSafe()); } } unsigned int uniqueID = currEffect->Render(sector, pos, 0, attachTarget, up.Unit(), uniqueIDOverride); actualEffects.Put(uniqueID, currEffect); return uniqueID; } Error2("Failed to find effect with name: %s",effectName.GetDataSafe()); #endif return 0; }
FeederHeightSourceType ParseFormatString (const csString& format) { if (format.IsEmpty ()) { return HEIGHT_SOURCE_IMAGE; } static const char* formatStrings[] = { "image", "raw8", "raw16le", "raw16be", "raw32le", "raw32be", "rawfloatle", "rawfloatbe" }; for (size_t i = 0; i < sizeof(formatStrings) / sizeof(char*); ++i) { if (format == formatStrings[i]) { return (FeederHeightSourceType)i; } } return HEIGHT_SOURCE_IMAGE; }
bool pawsStyles::LoadStyles(const csString &fileName) { csRef<iVFS> vfs = csQueryRegistry<iVFS > (objectReg); assert(vfs); csRef<iDataBuffer> buff = vfs->ReadFile(fileName); if(buff == NULL) { Error2("Could not find file: %s", fileName.GetData()); return false; } csRef<iDocumentSystem> xml; xml.AttachNew(new csTinyDocumentSystem); assert(xml); csRef<iDocument> doc = xml->CreateDocument(); assert(doc); const char* error = doc->Parse(buff); if(error) { Error3("Parse error in %s: %s", fileName.GetData(), error); return false; } csRef<iDocumentNode> root = doc->GetRoot(); if(root == NULL) return false; csRef<iDocumentNode> topNode = root->GetNode("styles"); if(topNode == NULL) { Error2("Missing <styles> tag in %s", fileName.GetData()); return false; } csRef<iDocumentNodeIterator> iter = topNode->GetNodes("style"); while(iter->HasNext()) { csRef<iDocumentNode> styleNode = iter->Next(); csString name = styleNode->GetAttributeValue("name"); if(styles.In(csString(name))) { // This is not an error anymore. Custom skins can and should supercede standard styles. //Error2("Warning: PAWS style '%s' defined more than once", name.GetData()); } else styles.Put(csString(name), styleNode); } InheritStyles(); return true; }
csString Tribe::GetBuffer(const csString &bufferName) { csString value = tribeBuffer.Get(bufferName,""); RDebug(this, 5, "Get Buffer(%s) return: '%s'",bufferName.GetDataSafe(),value.GetDataSafe()); return value; }
bool pawsNumbersPromptWindow::TextIsValidForEditing(const csString & text) { if (text.Length() > (unsigned int)maxDigits) return false; for (size_t i=0; i < text.Length(); i++) if (!isdigit(text.GetAt(i)) ) return false; if ( (text.GetData() != NULL) && (atoi(text.GetData()) > maxNumber) ) return false; return true; }
void Profiler::WriteLogEntry (const csString& entry, bool flush /* = false */) { if (logfile) { logfile->Write (entry.GetDataSafe (), entry.Length ()); if (flush) logfile->Flush (); } if (nativeLogfile) { fprintf (nativeLogfile, "%s", entry.GetDataSafe ()); if (flush) fflush (nativeLogfile); } }
csRef<iImage> BaseMapGen::LoadImage (const csString& filename, int format) { csPrintf ("Trying to load '%s'... \t", filename.GetData()); fflush (stdout); csRef<iImage> image; csRef<iImageIO> imageio = csQueryRegistry<iImageIO> (object_reg); csRef<iVFS> VFS = csQueryRegistry<iVFS> (object_reg); csRef<iDataBuffer> buf = VFS->ReadFile (filename.GetData(), false); if (!buf) { Report ("Failed to load image file '%s'!", filename.GetData()); return GenerateErrorTexture (32, 32); } image = imageio->Load (buf, format); image.IsValid() ? csPrintf ("success.\n") : csPrintf ("failed.\n"); return image; }
void Client::GetTargetTypeName(int32_t targetType, csString& targetDesc) const { targetDesc.Clear(); TestTarget(targetDesc, targetType, TARGET_NONE, "the surrounding area"); TestTarget(targetDesc, targetType, TARGET_ITEM, "items"); TestTarget(targetDesc, targetType, TARGET_SELF, "yourself"); TestTarget(targetDesc, targetType, TARGET_FRIEND, "living friends"); TestTarget(targetDesc, targetType, TARGET_FOE, "living enemies"); TestTarget(targetDesc, targetType, TARGET_DEAD, "the dead"); }
void ZoneHandler::MovePlayerTo(const csVector3 &Pos, float yrot, const csString &newSector, const csVector3 &Vel) { if(!celclient->IsReady()) return; iSector* sector = psengine->GetEngine()->FindSector(newSector); if(sector != NULL) { Notify9(LOG_LOAD, "Setting position of player %f %f %f rot %f in sector '%s' velocity: %f %f %f", Pos.x, Pos.y, Pos.z, yrot, newSector.GetData(), Vel.x, Vel.y, Vel.z); celclient->GetMainPlayer()->SetPosition(Pos, yrot, sector); // set new position celclient->GetMainPlayer()->SetVelocity(Vel); } else { Error2("Couldn't find sector '%s'", newSector.GetData()); } }