Пример #1
0
bool Tribe::Load(iResultRow &row)
{
    id                              = row.GetInt("id");
    name                            = row["name"];
    // Add tribal recipe
    tribalRecipe = new RecipeTreeNode(recipeManager->GetRecipe(row.GetInt("tribal_recipe")),0);

    homePos                         = csVector3(row.GetFloat("home_x"),row.GetFloat("home_y"),row.GetFloat("home_z"));
    homeRadius                      = row.GetFloat("home_radius");
    homeSectorName                  = row["home_sector_name"];
    maxSize                         = row.GetInt("max_size");
    wealthResourceName              = row["wealth_resource_name"];
    wealthResourceNick              = row["wealth_resource_nick"];
    wealthResourceArea              = row["wealth_resource_area"];

    wealthGatherNeed                = row["wealth_gather_need"];

    wealthResourceGrowth            = row.GetFloat("wealth_resource_growth");
    wealthResourceGrowthActive      = row.GetFloat("wealth_resource_growth_active");
    wealthResourceGrowthActiveLimit = row.GetInt("wealth_resource_growth_active_limit");

    reproductionCost                = row.GetInt("reproduction_cost");
    npcIdleBehavior                 = row["npc_idle_behavior"];

    return true;
}
Пример #2
0
void Tribe::LoadAsset(iResultRow &row)
{

    Asset* asset = new Asset();
    asset->id = row.GetInt("id");
    asset->name = row["name"];
    asset->type = (AssetType)(row.GetInt("type"));
    csVector3 coords;
    coords[0] = row.GetFloat("coordX");
    coords[1] = row.GetFloat("coordY");
    coords[2] = row.GetFloat("coordZ");
    asset->pos = coords;
    asset->item = NULL;
    asset->itemUID = row.GetInt("itemID");
    asset->sectorName = row["sector_name"];
    // Try to find the sector. Will probably fail at this point.
    if(!asset->sectorName.IsEmpty())
    {
        asset->sector = npcclient->GetEngine()->FindSector(asset->sectorName);
    }
    else
    {
        asset->sector = NULL;
    }
    asset->status = (AssetStatus)(row.GetInt("status"));
    asset->quantity = row.GetInt("quantity");

    assets.Push(asset);
}
Пример #3
0
bool Tribe::LoadMemory(iResultRow &row)
{
    Memory* memory = new Memory;

    memory->id   = row.GetInt("id");
    memory->name = row["name"];
    memory->pos = csVector3(row.GetFloat("loc_x"),row.GetFloat("loc_y"),row.GetFloat("loc_z"));
    memory->radius = row.GetFloat("radius");
    memory->sectorName = row["sector_name"];
    // Try to find the sector. Will probably fail at this point.
    memory->sector = npcclient->GetEngine()->FindSector(memory->sectorName);
    memory->npc = NULL; // Not a private memory

    memories.PushBack(memory);

    return true;
}
Пример #4
0
bool psTradePatterns::Load(iResultRow& row)
{
    id              = row.GetUInt32("id");
    patternName     = row["pattern_name"];
    groupPatternId   = row.GetUInt32("group_id");
    designItemId    = row.GetUInt32("designitem_id");
    KFactor         = row.GetFloat("k_factor");

    return true;
}
Пример #5
0
bool psTradeTransformations::Load(iResultRow& row)
{
    id              = row.GetUInt32("id");
    patternId       = row.GetUInt32("pattern_id");
    processId       = row.GetUInt32("process_id");
    resultId        = row.GetUInt32("result_id");
    resultQty       = row.GetInt("result_qty");
    itemId          = row.GetUInt32("item_id");
    itemQty         = row.GetInt("item_qty");
    transPoints     = row.GetInt("trans_points");
    penaltyPct     = row.GetFloat("penalty_pct");
    return true;
}
Пример #6
0
bool Location::Load(iResultRow &row, iEngine* engine, iDataConnection* /*db*/)
{
    id         = row.GetInt("id");
    name       = row["name"];
    pos.x      = row.GetFloat("x");
    pos.y      = row.GetFloat("y");
    pos.z      = row.GetFloat("z");
    rot_angle  = row.GetFloat("angle");;
    radius     = row.GetFloat("radius");
    sectorName = row["sector"];
    // Cache sector if engine is available.
    if(engine)
    {
        sector     = engine->FindSector(sectorName);
    }
    else
    {
        sector = NULL;
    }

    id_prev_loc_in_region = row.GetInt("id_prev_loc_in_region");

    return true;
}
Пример #7
0
bool psRaceInfo::Load(iResultRow &row)
{
    uid  = row.GetUInt32("id");
    name = row["name"];
    psserver->GetCacheManager()->AddCommonStringID(name);
    initialCP = row.GetUInt32("initial_cp");
    race = row.GetUInt32("race");
    helmGroup = row["helm"];
    BracerGroup = row["bracer"];
    BeltGroup = row["belt"];
    CloakGroup = row["cloak"];
    MounterAnim = row["cstr_mounter_animation"];
    psserver->GetCacheManager()->AddCommonStringID(MounterAnim);
    sex = row["sex"];
    scale = row.GetFloat("scale");
    speedModifier = row.GetFloat("speed_modifier");

    gender = psserver->GetCacheManager()->ConvertGenderString(row["sex"]);

    iResultSet* rs = db->Select("SELECT * FROM race_spawns WHERE raceid = %lu", race);

    if(!rs || rs->Count() == 0)
    {
        Error2("Race spawn points for race %d not found.", race);
        return false;
    }

    for(unsigned int i = 0 ; i < rs->Count() ; i++)
    {
        psRaceStartingLocation startingLoc;
        //prepare x,y,z and rotation of the spawn point
        startingLoc.x = (*rs)[i].GetFloat("x");
        startingLoc.y = (*rs)[i].GetFloat("y");
        startingLoc.z = (*rs)[i].GetFloat("z");
        startingLoc.yrot = (*rs)[i].GetFloat("yrot");
        //set a range used to select a random point within it from the x and z
        startingLoc.range = (*rs)[i].GetFloat("range");

        psSectorInfo* secinfo=psserver->GetCacheManager()->GetSectorInfoByID((*rs)[i].GetUInt32("sector_id"));
        if(secinfo==NULL)
        {
            Error3("Unresolvable sector id %lu in start_sector_id field of race info for race %u.  Failing!",
                   (*rs)[i].GetUInt32("sector_id"),race);
            return false;
        }

        startingLoc.sector_name = secinfo->name;

        startingLocations.Push(startingLoc);
    }

    rs->Release();

    size.x = row.GetFloat("size_x");
    size.y = row.GetFloat("size_y");
    size.z = row.GetFloat("size_z");

    // Z size and X size (width and length) need to be equal because the collision reaction system
    // does not know how to cope with rotations. An ellipsoid would be more ideal.
    size.z = size.x = csMax(size.x, size.z);

    baseRegen[PSRACEINFO_STAMINA_PHYSICAL_STILL] = row.GetFloat("base_physical_regen_still");
    baseRegen[PSRACEINFO_STAMINA_PHYSICAL_WALK]  = row.GetFloat("base_physical_regen_walk");
    baseRegen[PSRACEINFO_STAMINA_MENTAL_STILL]   = row.GetFloat("base_mental_regen_still");
    baseRegen[PSRACEINFO_STAMINA_MENTAL_WALK]    = row.GetFloat("base_mental_regen_walk");

    mesh_name = row["cstr_mesh"];
    if(!mesh_name)
    {
        Error2("Invalid 'cstr_mesh' for race '%s'\n", name.GetData());
    }
    psserver->GetCacheManager()->AddCommonStringID(mesh_name);

    base_texture_name = row["cstr_base_texture"];
    psserver->GetCacheManager()->AddCommonStringID(base_texture_name);

    // Load starting stats
    SetBaseAttribute(PSITEMSTATS_STAT_STRENGTH      ,row.GetUInt32("start_str"));
    SetBaseAttribute(PSITEMSTATS_STAT_ENDURANCE     ,row.GetUInt32("start_end"));
    SetBaseAttribute(PSITEMSTATS_STAT_AGILITY       ,row.GetUInt32("start_agi"));
    SetBaseAttribute(PSITEMSTATS_STAT_INTELLIGENCE  ,row.GetUInt32("start_int"));
    SetBaseAttribute(PSITEMSTATS_STAT_WILL          ,row.GetUInt32("start_will"));
    SetBaseAttribute(PSITEMSTATS_STAT_CHARISMA      ,row.GetUInt32("start_cha"));

    // Load natural armor
    natural_armor_id = row.GetUInt32("armor_id");

    // Load natural claws/weapons
    natural_weapon_id = row.GetUInt32("weapon_id");

    return true;
}
Пример #8
0
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
}