Ejemplo n.º 1
0
void Tribe::AddAsset(Tribe::AssetType type, csString name, gemNPCItem* item, int quantity, int id)
{
    for(size_t i=0; i<assets.GetSize(); i++)
    {
        if(assets[i]->name == name)
        {
            assets[i]->quantity += quantity;
            SaveAsset(assets[i]);
            return;
        }
    }

    // No items like this before in the array
    Asset* asset = new Asset();
    asset->id       = id;
    asset->type     = type;
    asset->name     = name;
    asset->item     = item;
    if(asset->item)
    {
        asset->itemUID  = asset->item->GetUID();
    }
    else
    {
        asset->itemUID = 0;
    }
    asset->quantity = quantity;
    asset->pos      = csVector3(0,0,0);
    asset->status   = Tribe::ASSET_STATUS_NOT_APPLICABLE;
    assets.Push(asset);
    SaveAsset(asset);
}
Ejemplo n.º 2
0
void Tribe::HandlePersistItem(gemNPCItem* item)
{
    csVector3 position;
    iSector*  sector;

    psGameObject::GetPosition(item,position,sector);

    // Check if we have this item as an asset
    Asset* asset = GetAsset(item->GetUID());
    if(asset)
    {
        asset->item = item;
    }
    else
    {
        // TODO: Find buildings and items and add them seperate, for now add as BUILDING.

        asset = GetAsset(Tribe::ASSET_TYPE_BUILDING, item->GetName(), position, sector);
        if(asset)
        {
            asset->item = item;
            asset->itemUID = item->GetUID();
            SaveAsset(asset);
        }
        else
        {
            // Add the new tribe item as an asset.
            asset = AddAsset(Tribe::ASSET_TYPE_BUILDING, item->GetName(), position, sector, Tribe::ASSET_STATUS_CONSTRUCTED);
            asset->item = item;
            asset->itemUID = item->GetUID();
            SaveAsset(asset);
        }
    }
}
Ejemplo n.º 3
0
void Tribe::DeleteAsset(csString name, int quantity)
{
    for(size_t i=0; i<assets.GetSize(); i++)
    {
        if(assets[i]->name == name)
        {
            assets[i]->quantity -= quantity;
            // Remove entry if nothing remains
            if(assets[i]->quantity <= 0)
            {
                // Call SaveAsset with deletion = true to delete the asset
                SaveAsset(assets[i], true);

                assets.DeleteIndex(i);
                return;
            }
            // Asset not deleted so update db
            SaveAsset(assets[i]);
            return;
        }
    }
}
Ejemplo n.º 4
0
void Tribe::Unbuild(NPC* npc, gemNPCItem* building)
{
    NPCDebug(npc, 6, "Unbuilding building %s",building->GetName());

    Asset* buildingAsset = GetAsset(building);
    if(buildingAsset)
    {
        buildingAsset->status = ASSET_STATUS_NOT_USED;
        buildingAsset->quantity = 0;
        SaveAsset(buildingAsset);

        // Check if there is a building spot that need to be downgrades as well
        csVector3 buildingPos = npc->GetTribe()->GetHomePosition();

        buildingPos -= buildingAsset->pos;

        Asset* buildingSpot = GetNearestAsset(Tribe::ASSET_TYPE_BUILDINGSPOT, buildingAsset->name, Tribe::ASSET_STATUS_CONSTRUCTED,
                                              buildingPos, NULL, 5.0, NULL);
        if(buildingSpot)
        {
            buildingSpot->status = Tribe::ASSET_STATUS_NOT_USED;
            SaveAsset(buildingSpot);

            // Now the building asset and the spot is freed inform the server
            npcclient->GetNetworkMgr()->QueueUnbuildCommand(npc->GetActor(), building);
        }
        else
        {
            Error4("NPC %s(%s) Failed to find building spot for building %s",npc->GetName(),ShowID(npc->GetEID()),building->GetName());
        }
    }
    else
    {
        Error4("NPC %s(%s) Failed to find building asset for building %s",npc->GetName(),ShowID(npc->GetEID()),building->GetName());
    }
}
Ejemplo n.º 5
0
void Tribe::Build(NPC* npc, bool pickupable)
{
    Asset* buildingSpot = npc->GetBuildingSpot();

    if(buildingSpot->status == ASSET_STATUS_INCONSTRUCTION)
    {
        csVector3 buildingPos = npc->GetTribe()->GetHomePosition();
        iSector*  buildingSector = npc->GetTribe()->GetHomeSector();

        buildingPos += buildingSpot->pos;

        buildingSpot->status = ASSET_STATUS_CONSTRUCTED;

        // Now ask the server to spawn the building. Upon spawn a persit item will be sent to the client.
        // The new building will be added to assets as part of the HandlePersitItem prosessing.
        npcclient->GetNetworkMgr()->QueueSpawnBuildingCommand(npc->GetActor(), buildingPos, buildingSector, buildingSpot->name, GetID(), pickupable);

        SaveAsset(buildingSpot);
    }
}
Ejemplo n.º 6
0
Tribe::Asset* Tribe::AddAsset(Tribe::AssetType type, csString name, csVector3 position, iSector* sector, Tribe::AssetStatus status)
{
    Asset* asset = new Asset();
    asset->id       = -1;
    asset->type     = type;
    asset->name     = name;
    asset->item     = NULL;
    asset->itemUID  = 0;
    asset->pos      = position;
    if(sector != NULL)
    {
        asset->sectorName = sector->QueryObject()->GetName();
    }
    asset->sector   = sector;
    asset->quantity = 1;
    asset->status   = status;

    assets.Push(asset);
    SaveAsset(asset);

    return asset;
}
Ejemplo n.º 7
0
csRef<iDocument> AssetManager::SaveDoc ()
{
  csRef<iDocumentSystem> docsys;
  docsys.AttachNew (new csTinyDocumentSystem ());
  csRef<iDocument> doc = docsys->CreateDocument ();

  csRef<iDocumentNode> root = doc->CreateRoot ();
  csRef<iDocumentNode> rootNode = root->CreateNodeBefore (CS_NODE_ELEMENT);
  rootNode->SetValue ("dynlevel");

  csRef<iDocumentNode> metaNode = rootNode->CreateNodeBefore (CS_NODE_ELEMENT);
  metaNode->SetValue ("meta");
  metaNode->SetAttribute ("name", projectData->GetName ());
  metaNode->SetAttribute ("short", projectData->GetShortDescription ());
  metaNode->SetAttribute ("description", projectData->GetDescription ());

  for (size_t i = 0 ; i < assets.GetSize () ; i++)
  {
    iAsset* asset = assets[i];
    csRef<iDocumentNode> assetNode = rootNode->CreateNodeBefore (CS_NODE_ELEMENT);
    assetNode->SetValue ("asset");
    if (!asset->GetNormalizedPath ().IsEmpty ())
      assetNode->SetAttribute ("path", asset->GetNormalizedPath ());
    assetNode->SetAttribute ("file", asset->GetFile ());
    if (!asset->GetMountPoint ().IsEmpty ())
      assetNode->SetAttribute ("mount", asset->GetMountPoint ());
    if (asset->IsWritable ())
      assetNode->SetAttribute ("writable", "true");
    if (!asset->GetMountPoint ().IsEmpty ())
      assetNode->SetAttribute ("mount", asset->GetMountPoint ());
  }

  csRef<iDocumentNode> dynworldNode = rootNode->CreateNodeBefore (CS_NODE_ELEMENT);
  dynworldNode->SetValue ("dynworld");
  dynworld->Save (dynworldNode);

  csRef<iDocumentNode> curveNode = rootNode->CreateNodeBefore (CS_NODE_ELEMENT);
  curveNode->SetValue ("curves");
  curvedMeshCreator->Save (curveNode);

  csRef<iDocumentNode> roomNode = rootNode->CreateNodeBefore (CS_NODE_ELEMENT);
  roomNode->SetValue ("rooms");
  roomMeshCreator->Save (roomNode);

  // Now save all assets in their respective files. @@@ In the future this should
  // be modified to only save the new assets and assets that actually came from here.
  for (size_t i = 0 ; i < assets.GetSize () ; i++)
  {
    iAsset* asset = assets[i];
    if (asset->IsWritable () && asset->IsModified ())
    {
      // @@@ Todo: proper error reporting.
      if (!SaveAsset (docsys, asset))
	return 0;
    }
  }

  for (size_t i = 0 ; i < assets.GetSize () ; i++)
  {
    IntAsset* ia = static_cast<IntAsset*> (assets[i]);
    ia->SetModified (false);
    ia->GetModifiedResources ().DeleteAll ();
  }

  if (lockedResources.GetSize () > 0)
  {
    csRef<iDocumentNode> locksNode = rootNode->CreateNodeBefore (CS_NODE_ELEMENT);
    locksNode->SetValue ("locks");
    csSet<csPtrKey<iObject> >::GlobalIterator it = lockedResources.GetIterator ();
    while (it.HasNext ())
    {
      iObject* resource = it.Next ();
      csRef<iDocumentNode> resNode = locksNode->CreateNodeBefore (CS_NODE_ELEMENT);

      csRef<iCelEntityTemplate> tpl = scfQueryInterface<iCelEntityTemplate> (resource);
      if (tpl)
      {
        resNode->SetValue ("template");
	resNode->SetAttribute ("name", resource->GetName ());
	continue;
      }

      csRef<iDynamicFactory> df = scfQueryInterface<iDynamicFactory> (resource);
      if (df)
      {
        resNode->SetValue ("dynfact");
	resNode->SetAttribute ("name", resource->GetName ());
	continue;
      }

      csRef<iQuestFactory> qf = scfQueryInterface<iQuestFactory> (resource);
      if (qf)
      {
        resNode->SetValue ("quest");
	resNode->SetAttribute ("name", resource->GetName ());
	continue;
      }

      csRef<iLightFactory> lf = scfQueryInterface<iLightFactory> (resource);
      if (lf)
      {
	resNode->SetValue ("light");
	resNode->SetAttribute ("name", resource->GetName ());
	continue;
      }

      printf ("WHAT!\n"); fflush (stdout);
      CS_ASSERT (false);
    }
  }

  generallyModified = false;

  return doc;
}
Ejemplo n.º 8
0
void Tribe::RemoveAsset(Tribe::Asset* asset)
{
    SaveAsset(asset,true); // Deleation = true
    assets.Delete(asset);
}