bool psTradeProcesses::Load(iResultRow& row) { processId = row.GetUInt32("process_id"); subprocess = row.GetInt("subprocess_number"); name = row["name"]; animation = row["animation"]; workItemId = row.GetUInt32("workitem_id"); equipmentId = row.GetUInt32("equipment_id"); constraints = row["constraints"]; garbageId = row.GetUInt32("garbage_id"); garbageQty = row.GetInt("garbage_qty"); priSkillId = row.GetInt("primary_skill_id"); minPriSkill = row.GetInt("primary_min_skill"); maxPriSkill = row.GetInt("primary_max_skill"); priPracticePts = row.GetInt("primary_practice_points"); priQualFactor = row.GetInt("primary_quality_factor"); secSkillId = row.GetInt("secondary_skill_id"); minSecSkill = row.GetInt("secondary_min_skill"); maxSecSkill = row.GetInt("secondary_max_skill"); secPracticePts = row.GetInt("secondary_practice_points"); secQualFactor = row.GetInt("secondary_quality_factor"); renderEffect = row["render_effect"]; return true; }
bool NPCType::Load(iResultRow &row) { csString parents = row.GetString("parents"); if(!parents.IsEmpty()) // this npctype is a subclass of another npctype { csArray<csString> parent = psSplit(parents,','); for(size_t i = 0; i < parent.GetSize(); i++) { NPCType *superclass = npcclient->FindNPCType(parent[i]); if(superclass) { DeepCopy(*superclass); // This pulls everything from the parent into this one. } else { Error2("Specified parent npctype '%s' could not be found.", parent[i].GetDataSafe()); return false; } } } name = row.GetString("name"); if(name.Length() == 0) { Error1("NPCType has no name attribute. Error in DB"); return false; } ang_vel = row.GetFloat("ang_vel"); csString velStr = row.GetString("vel"); velStr.Upcase(); if(velStr.IsEmpty()) { // Do nothing. Use velSource from constructor default value // or as inherited from superclass. } else if(velStr == "$WALK") { velSource = VEL_WALK; } else if (velStr == "$RUN") { velSource = VEL_RUN; } else if(row.GetFloat("vel")) { velSource = VEL_USER; vel = row.GetFloat("vel"); } collisionPerception = row.GetString("collision"); outOfBoundsPerception = row.GetString("out_of_ounds"); inBoundsPerception = row.GetString("in_bounds"); fallingPerception = row.GetString("falling"); csRef<iDocumentSystem> xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem); csRef<iDocument> doc = xml->CreateDocument(); const char* error = doc->Parse(row.GetString("script")); if(error) { Error3("NPCType script parsing error:%s in %s", error, name.GetData()); return false; } csRef<iDocumentNode> node = doc->GetRoot(); if(!node) { Error2("No XML root in npc type script of %s", name.GetData()); return false; } // Now read in behaviors and reactions csRef<iDocumentNodeIterator> iter = node->GetNodes(); while(iter->HasNext()) { csRef<iDocumentNode> node = iter->Next(); if(node->GetType() != CS_NODE_ELEMENT) continue; // This is a widget so read it's factory to create it. if(strcmp(node->GetValue(), "behavior") == 0) { Behavior *b = new Behavior; if(!b->Load(node)) { Error3("Could not load behavior '%s'. Error in DB XML in node '%s'.", b->GetName(),node->GetValue()); delete b; return false; } behaviors.Add(b); Debug3(LOG_STARTUP,0, "Added behavior '%s' to type %s.\n",b->GetName(),name.GetData() ); } else if(strcmp( node->GetValue(), "react" ) == 0) { Reaction *r = new Reaction; if(!r->Load(node,behaviors)) { Error1("Could not load reaction. Error in DB XML"); delete r; return false; } // check for duplicates and keeps the last one for(size_t i=0; i<reactions.GetSize(); i++) { // Same event with same type if(!strcmp(reactions[i]->GetEventType(),r->GetEventType())&& (reactions[i]->type == r->type)&& (reactions[i]->values == r->values)) { // Check if there is a mach in affected for(size_t k=0; k< r->affected.GetSize(); k++) { for(size_t j=0; j< reactions[i]->affected.GetSize(); j++) { if(!strcmp(r->affected[k]->GetName(),reactions[i]->affected[j]->GetName())) { // Should probably delete and clear out here // to allow for overiding of event,affected pairs. // Though now give error, until needed. Error4("Reaction of type '%s' already connected to '%s' in '%s'", r->GetEventType(),reactions[i]->affected[j]->GetName(), name.GetDataSafe()); return false; // delete reactions[i]; //reactions.DeleteIndex(i); //break; } } } } } reactions.Insert(0,r); // reactions get inserted at beginning so subclass ones take precedence over superclass. } else { Error1("Node under NPCType is not 'behavior' or 'react'. Error in DB XML"); return false; } } return true; // success }
bool LocationType::Load(iResultRow &row, iEngine* engine, iDataConnection* db) { id = row.GetInt("id"); name = row["name"]; if(!name.Length()) { CPrintf(CON_ERROR, "Location Types must all have name attributes.\n"); return false; } // Load all with same master location type Result rs(db->Select("select loc.*,s.name as sector from sc_locations loc, sectors s where loc.loc_sector_id = s.id and type_id = %d and id_prev_loc_in_region <= 0",id)); // Only load locations, regions to be loaded later if(!rs.IsValid()) { Error2("Could not load locations from db: %s",db->GetLastError()); return false; } for(int i=0; i<(int)rs.Count(); i++) { Location* newloc = new Location; newloc->Load(rs[i],engine,db); newloc->type = this; locs.Push(newloc); } // Load region with same master location type Result rs2(db->Select("select loc.*,s.name as sector from sc_locations loc, sectors s where loc.loc_sector_id = s.id and type_id = %d and id_prev_loc_in_region > 0",id)); // Only load regions, locations has been loaded allready csArray<Location*> tmpLocs; if(!rs2.IsValid()) { Error2("Could not load locations from db: %s",db->GetLastError()); return false; } for(int i=0; i<(int)rs2.Count(); i++) { Location* newloc = new Location; newloc->Load(rs2[i],engine,db); newloc->type = this; tmpLocs.Push(newloc); } while(tmpLocs.GetSize()) { Location* curr, *first; curr = first = tmpLocs.Pop(); bool found; first->type = this; first->locs.Push(first); first->region = first; do { found = false; for(size_t i= 0; i<tmpLocs.GetSize(); i++) { if(curr->id == tmpLocs[i]->id_prev_loc_in_region) { curr = tmpLocs[i]; tmpLocs.DeleteIndex(i); curr->type = this; first->locs.Push(curr); curr->region = first; found = true; break; } } } while(found); //when not a closed loop of at least 3 points, delete this //polygon, but continue with rest. if(first->locs.GetSize() <= 2) { Error1("Only two locs for region defined!"); //delete all locations in 'polygon'. When deleting first, //it will recursively delete its polygon locations, in this //case including itself. So remove that reference first first->locs.DeleteIndex(0); delete first; } else if(curr->id != first->id_prev_loc_in_region) { Error1("First and last loc not connected!"); //delete all locations in 'polygon'. When deleting first, //it will recursively delete its polygon locations, in this //case including itself. So remove that reference first first->locs.DeleteIndex(0); delete first; } else { first->type = this; locs.Push(first); first->CalculateBoundingBox(); } } return true; }