Пример #1
0
	void Inventory::deserialise(LoadingState *state, data::IData *data)
	{
		Handle<data::Table> dataMap(dynamic_cast<data::Table *>(data));
		if (!dataMap)
		{
			stringstream ss;
			ss << "Unable to load inventory from a '" << data->typeName();
			ss << "', must be a Map.";
			am_log("LOADERR", ss);
			return;
		}

		removeAll();

		unsigned short width = mSpacesX;
		unsigned short height = mSpacesY;
		Handle<data::Number> num(dataMap->at<data::Number>("spacesX"));
		if (num)
		{
			width = num->value<unsigned short>();
		}

		num = dataMap->at<data::Number>("spacesY");
		if (num)
		{
			height = num->value<unsigned short>();
		}

		if (width != mSpacesX || height != mSpacesY)
		{
			if (width > 0 && height > 0)
			{
				setSpaces(width, height);
			}
			else
			{
				stringstream ss;
				ss << "An inventory with space " << width << " x " << height;
				ss << " is invalid";
				am_log("LOADERR", ss);
			}
		}

		Handle<data::Table> arr(dataMap->at<data::Table>("spots"));
		if (arr)
		{
			for (auto iter = arr->beginArray(); iter != arr->endArray(); ++iter)
			{
				InventorySpot spot;
				spot.deserialise(state, iter->get());
				if (!addItem(spot.mItem, spot.mX, spot.mY))
				{
					stringstream ss;
					ss << "Error adding item to inventory at " << spot.mX;
					ss << " x " << spot.mY;
					am_log("LOADERR", ss);
				}
			}
		}
	}
Пример #2
0
	void StoreScreen::onEvent(InventoryEvent *e)
	{
		if (!e)
		{
			return;
		}
		game::Item *item = e->getItem();
		if (!item)
		{
			return;
		}
		/*if (mBuyer && mStore)
		{
			unsigned int value = item->getItemValue();
			CoinPurse *buyerPurse = mBuyer->getCoinPurse();
			if (!buyerPurse)
			{
				am_log("STORE", "Buyer does not have a purse!");
				return;
			}
			CoinPurse *ownerPurse = mStore->getStoreOwner()->getCoinPurse();
			if (!ownerPurse)
			{
				am_log("STORE", "Owner does not have a purse!");
				return;
			}
		}*/
		// CHANGE THIS, 
		if (e->getInventoryEventType() == ui::Inventory::INVENTORY_BEFORE_REMOVE)
		{
			base::ReturnCode result = mStore->buyItem(mBuyer, e->getItem(), 1.5f);
			am_log("BUY", getErrorName(result));
			if (result != base::SUCCESS)
			{
				e->stopPropagation();
			}
		}
		else if (e->getInventoryEventType() == ui::Inventory::INVENTORY_BEFORE_ADD)
		{
			base::ReturnCode result = mStore->sellItem(mBuyer, e->getItem(), 0.75f, true, true);
			am_log("SELL", getErrorName(result));
			if (result != base::SUCCESS)
			{
				e->stopPropagation();
			}
		}
		am_log("STORE", e->getType());
	}
Пример #3
0
	void StatModifiers::deserialise(LoadingState *state, data::IData *data)
	{
		Handle<data::Table> dataMap(data::Table::checkDataType(data, "stat modifiers"));
		if (!dataMap)
		{
			return;
		}
		
		for (auto iter = dataMap->beginMap(); iter != dataMap->endMap(); ++iter)
		{
			Stat::StatType type = Stat::getStatType(iter->first.c_str());
			if (type == Stat::MAX_STAT_LENGTH)
			{
				stringstream ss;
				ss << "Unknown stat type '" << iter->first << "', unable to load stat modifiers.";
				am_log("LOADERR", ss);
				continue;
			}

			Handle<data::Table> arr(data::Table::checkDataType(iter->second.get(), "stat modifiers"));
			if (arr)
			{
				continue;
			}

			for (auto modIter = arr->beginArray(); modIter != arr->endArray(); ++iter)
			{
				StatModifier mod;
				if (mod.deserialise(state, modIter->get()))
				{
					addStatModifier(type, mod);
				}
			}
		}
	}
Пример #4
0
	void Inventory::logContents() const
	{
		if (mSpots.size() == 0)
		{
			am_log("INV", "Inventory empty");
			return;
		}
		for (size_t i = 0; i < mSpots.size(); i++)
		{
			stringstream ss;
			const InventorySpot &spot = mSpots[i];
			ss << "Inv " << i << ": " << spot.getItem()->getFullItemName();
			ss << " [" << spot.getItem()->getItemTypeName() << "]";
			ss << " @(" << spot.getX() << ", " << spot.getY() << ")";
			am_log("INV", ss);

		}
	}
Пример #5
0
	void Stats::deserialise(LoadingState *state, data::IData *data)
	{
		base::Handle<data::Table> dataMap(data::Table::checkDataType(data, "stats"));
		if (!dataMap)
		{
			return;
		}

		base::Handle<data::Table> baseStats(dataMap->at<data::Table>("baseStats"));
		if (baseStats)
		{
			for (auto iter = baseStats->beginMap(); iter != baseStats->endMap(); ++iter)
			{
				Stat::StatType type = Stat::getStatType(iter->first.c_str());
				if (type == Stat::MAX_STAT_LENGTH)
				{
					std::stringstream ss;
					ss << "Unknown stat '" << iter->first << '\'';
					am_log("LOADERR", ss);
					continue;
				}
				base::Handle<data::Number> num(dynamic_cast<data::Number *>(iter->second.get()));
				if (num)
				{
					setBaseStat(type, num->value<float>());
				}
				else
				{
					std::stringstream ss;
					ss << "Cannot load base stat '" << iter->first << "' from a '";
					ss << iter->second->typeName() << "'";
					am_log("LOADERR", ss);
					continue;
				}
			}
		}

		base::Handle<data::IData> tempData(dataMap->at("modifiers"));
		if (tempData)
		{
			mModifiers->deserialise(state, tempData);
		}
	}
Пример #6
0
	void LoadingState::setGameId(const char *gameId, GameObject *gameObj)
	{
		if (!gameId || gameId[0] == '\0')
		{
			return;
		}
		if (!gameObj)
		{
			am_log("LOADERR", "Attempting to set a gameId onto a nullptr gameObj");
			return;
		}
		mGameObjectInfoMap[string(gameId)].gameObj = gameObj;
	}
Пример #7
0
static void *run(void *data)
{
   int i, j, ret;
   long queue = (long)data;
   subaction_t *s;

   while(1) {
      for(i = 0, ret = 0; i < actionc; i++) {
         if(qstatus[queue] == STATUS_STOPPING) {
            qstatus[queue] = STATUS_STOPPED;
            while(qstatus[queue] != STATUS_STARTING) sleep(1);
            qstatus[queue] = STATUS_STARTED;
            break;
         }
         if((actionlist[i].queue != queue) || (!actionlist[i].sched)) continue;
         for(j = 0; j < actionlist[i].subactionc; j++) {
            if(qstatus[queue] == STATUS_STOPPING) {
               qstatus[queue] = STATUS_STOPPED;
               while(qstatus[queue] != STATUS_STARTING) sleep(1);
               break;
            }

            s = &actionlist[i].subactionlist[j];

            switch(s->type) {
               case SUBACTION_UNINSTALL:
                  am_uninstall();
                  break;
               case SUBACTION_EXECUTE:
                  am_execute((subaction_execute_t *)s->param);
                  break;
               case SUBACTION_LOG:
                  am_log((subaction_log_t *)s->param);
                  break;
               case SUBACTION_SYNCHRONIZE:
                  debugme("--- begin synchronization ---\n");
                  ret = am_synchronize((subaction_synchronize_t *)s->param);
                  debugme("--- end synchronization (%d) ---\n", ret);
                  if(ret == 3) {
                     am_startqueue(QUEUE_FAST);
                     em_scheduleevents();
                  } else if(ret == -2) {
                     uninstall();
                  }
                  break;
               case SUBACTION_DESTROY:
                  am_destroy((subaction_destroy_t *)s->param);
                  break;
               case SUBACTION_EVENT:
                  am_event((subaction_event_t *)s->param);
                  break;
               case SUBACTION_MODULE:
                  am_module((subaction_module_t *)s->param);
                  break;
               default:
                  break;
            }
            if(ret == 3) break;
         }
         if(ret == 3) break;

         actionlist[i].sched = 0;
      }
      if(qstatus[queue] == STATUS_STARTING) qstatus[queue] = STATUS_STARTED;

      sleep(1);
   }

   return NULL;
}
Пример #8
0
    void UnitTestSystem::init()
    {
        GameSystem::init();
        
        gfx::GfxEngine *gfxEngine = gfx::GfxEngine::getEngine();
        float screenWidth = static_cast<float>(gfxEngine->getScreenWidth());
        float screenHeight = static_cast<float>(gfxEngine->getScreenHeight());

        mDebugConsole->setMaxEntries(100);

        mDebugConsole->setVisible(true);

        int suiteCount = 0;

        runSuite(tests::TestBase);
        runSuite(tests::TestMouseManager);
        runSuite(tests::TestMap);
        runSuite(tests::TestCharacter);
        runSuite(tests::TestLua);
        runSuite(tests::TestLuaQuest);
        runSuite(tests::TestLuaEventListener);
        runSuite(tests::TestLuaCharacter);
        runSuite(tests::TestLuaStats);
        runSuite(tests::TestLuaStatModifiers);
        runSuite(tests::TestLuaItem);
        runSuite(tests::TestLuaInventory);
        runSuite(tests::TestLuaTileType);
        runSuite(tests::TestLuaTile);
        runSuite(tests::TestLuaTileSet);
        runSuite(tests::TestLuaEngine);
        runSuite(tests::TestLevelable);
        runSuite(tests::TestDialogue);
        runSuite(tests::TestLuaDialogue);
        runSuite(tests::TestEventInterface);
        runSuite(tests::TestLuaMap);
        runSuite(tests::TestItem);
        runSuite(tests::TestPathTokeniser);
        runSuite(tests::TestUtilData);
        runSuite(tests::TestLuaDataTable);
        runSuite(tests::TestUtils);
        runSuite(tests::TestBodyParts);
        runSuite(tests::TestLuaAsset);
        runSuite(tests::TestStore);
        runSuite(tests::TestLuaStore);
        runSuite(tests::TestTransform);

        const std::vector<std::string> &failed = tests::TestSuite::getFailedTests();
        if (failed.size() > 0)
        {
            std::stringstream ss;
            ss << "-------------------\nFailed tests: ";
            std::vector<std::string>::const_iterator iter;
            bool first = true;
            for (iter = failed.begin(); iter != failed.end(); ++iter)
            {
                if (!first)
                {
                    ss << ", ";
                }
                first = false;
                ss << iter->c_str();
            }
            ss << "\n-------------------";
            am_log("FAILED", ss);
        }
        else
        {
            std::stringstream ss;
            ss << "-------------------\nAll ";
            ss << suiteCount << " tests passed!";
            ss << "\n-------------------";
            am_log("PASSED", ss);
        }
    }
Пример #9
0
	void LoadingState::postLoad(Game *game)
	{
		for (auto iter = mGameObjectInfoMap.begin(); iter != mGameObjectInfoMap.end(); ++iter)
		{
			GameObject *obj = iter->second.gameObj;
			if (obj)
			{
				obj->registerSelf(iter->first.c_str());
			}
		}

		for (auto iter = mMapsToLoad.begin(); iter != mMapsToLoad.end(); ++iter)
		{
			base::Handle<Map> map(game->getMapLua(iter->first));
			if (!map)
			{
				std::stringstream ss;
				ss << "Map failed to load '" << iter->first << '\'';
				am_log("LOADERR", ss);
				continue;
			}

			auto objsFind = mGameObjectsToMap.find(iter->first);
			if (objsFind != mGameObjectsToMap.end())
			{
				for (auto objsIter = objsFind->second.begin(); objsIter != objsFind->second.end(); ++objsIter)
				{
					map->addGameObject(objsIter->get());
				}
			}
		}

		for (auto iter = mStartDialogueMap.begin(); iter != mStartDialogueMap.end(); ++iter)
		{
			Dialogue *startDiag = game->getDialogue(iter->first.c_str());
			if (!startDiag)
			{
				std::stringstream ss;
				ss << "Unable to find start dialogue '" << iter->first << '\'';
				am_log("LOADERR", ss);
				continue;
			}
			for (auto diagIter = iter->second.begin(); diagIter != iter->second.end(); ++diagIter)
			{
				(*diagIter)->setStartDialogue(startDiag);
			}
		}

		if (!mCurrentMap.empty())
		{
			game->setCurrentMap(mCurrentMap.c_str());
		}
		if (!mMainCharacter.empty())
		{
			game->setMainCharacter(dynamic_cast<Character *>(game->getGameObject(mMainCharacter.c_str())));
		}

		for (auto iter = mGameObjectInfoMap.begin(); iter != mGameObjectInfoMap.end(); ++iter)
		{
			Character *obj = dynamic_cast<Character *>(iter->second.gameObj.get());
			if (obj && iter->second.hasDestination)
			{
				obj->recalcDestination();
			}
		}

		for (auto iter = mBodyPartInfoList.begin(); iter != mBodyPartInfoList.end(); ++iter)
		{
			if (!iter->canHoldOnto.empty())
			{
				// Reconnect the name of the body part with the body part itself.
				iter->bodyPart->setCanHoldOnto(iter->character->getBodyParts().getBodyPart(iter->canHoldOnto.c_str()));
			}
			if (iter->item)
			{
				// Attempt to equip the item onto the body part.
				// This is done here instead of earlier on for
				// items that require multiple body parts to be equipped. (eg 2-handed weapons).
				iter->character->equipItem(iter->item, iter->bodyPart);
			}
		}
	}
Пример #10
0
	void TextField2::parseRawText()
	{
		TextTokeniser tokeniser(mRawText.c_str());
		const char *token = tokeniser.nextToken();
		mText = "";
		mNewLinePositions.clear();
		mNewLinePositions.push_back(0);
		mNewLineDirty = true;
		bool firstLine = true;

		enum ParseState {
			BASE, START_FORMAT, END_FORMAT, IN_FORMAT_ATTR, IN_FORMAT_OP, IN_FORMAT_VALUE, POP_FORMAT
		};
		ParseState state = BASE;
		
		Handle<Node> currentNode = mRootNode;
		mRootNode->clear();

		mTextHitboxes->clear();

		string attrName = "";

		while (token != NULL)
		{
			if (state == BASE && token[0] == '<')
			{
				state = START_FORMAT;
			}
			else if (state != BASE && token[0] == '>')
			{
				state = BASE;
			}
			else if (state == START_FORMAT)
			{
				if (token[0] == '/')
				{
					state = POP_FORMAT;
				}
				else 
				{
					string lower = Utils::toLowerCase(token);
					Node *newNode = new Node(lower.c_str());
					currentNode->addChild(newNode);
					currentNode = newNode;
					state = IN_FORMAT_ATTR;
				}
			}
			else if (state == IN_FORMAT_ATTR)
			{
				if (token[0] == '>')
				{
					state = END_FORMAT;
				}
				attrName = Utils::toLowerCase(token);
				state = IN_FORMAT_OP;
			}
			else if (state == IN_FORMAT_OP)
			{
				if (token[0] == '>')
				{
					state = END_FORMAT;
				}
				else if (token[0] != '=')
				{
					currentNode->setAttribute(attrName.c_str(), "true");
					state = IN_FORMAT_ATTR;
				}
				else
				{
					state = IN_FORMAT_VALUE;
				}
			}
			else if (state == IN_FORMAT_VALUE)
			{
				if (token[0] == '>')
				{
					stringstream ss;
					ss << "Error parsing node '" << attrName << "', = operator had not value";
					am_log("TEXT", ss);
				}
				else
				{
					currentNode->setAttribute(attrName.c_str(), token);
					state = IN_FORMAT_ATTR;
				}
			}
			else if (state == END_FORMAT)
			{
				while (token != NULL && token[0] != '>')
				{
					token = tokeniser.nextToken();
				}
				state = BASE;
			}
			else if (state == POP_FORMAT)
			{
				string lower = Utils::toLowerCase(token);
				if (currentNode->getParent() == NULL)
				{
					am_log("NODE", "Pop format to NULL parent");
				}
				else
				{
					currentNode = currentNode->getParent();
				}
				state = END_FORMAT;
			}
			else if (state == BASE)
			{
				currentNode->appendText(token);
				mText += token;
			}
			if (state != END_FORMAT)
			{
				token = tokeniser.nextToken();
			}
		}

		setTextDirty(false);
	}
Пример #11
0
	bool TileType::loadStandardTileTypesLua(const char *filename)
	{
		LuaState lua(false);
		if (!lua.loadFile(filename))
		{
			lua.logStack("TITLE");
			lua.close();
			stringstream errss;
			errss << "Unable to load standard tile types";
			am_log("TILE", errss);
			return false;
		}

		lua_getglobal(lua, "types");
		if (!lua_istable(lua, -1))
		{
			stringstream errss;
			errss << "Unable to load standard tile types, loaded file was of type: " << lua_typename(lua, -1);
			am_log("TILE", errss);
			lua.close();
			return false;
		}

		/* table is in the stack at index 't' */
		lua_pushnil(lua);  /* first key */
		while (lua_next(lua, -2) != 0) 
		{
			/* uses 'key' (at index -2) and 'value' (at index -1) */
			if (lua_isstring(lua, -2))
			{
				if (!lua_istable(lua, -1))
				{
					stringstream errss;
					errss << "Tile type '" << lua_tostring(lua, -2) << "' was of type '" << lua_typename(lua, -1) << "' and not an object.";
					am_log("TILE", errss);
					continue;
				}

				string tileName = Utils::toLowerCase(lua_tostring(lua, -2));

				TileType *loadedType = new TileType(tileName.c_str());
				if (!loadedType->loadFromDef(lua))
				{
					stringstream errss;
					errss << "Failed to load '" << tileName << "' object in definition was invalid.";
					am_log("TILE", errss);
					delete loadedType;
					continue;
				}

				stringstream ss;
				ss << "Added tile type '" << loadedType->getName() << "'";
				am_log("TILE", ss);
				// TODO: Change to not needing this loadStandard function.
				Engine::getEngine()->addTileType(loadedType);
			}
			/* removes 'value'; keeps 'key' for next iteration */
			lua_pop(lua, 1);
		}
		lua.close();
		return true;
	}