void SharedTangibleObjectTemplate::parseVariableData(const String& varName, LuaObject* data) {
	lua_State* state = data->getLuaState();
	TemplateManager* templateManager = TemplateManager::instance();

	if (varName == "certificationsRequired") {
		LuaObject certifications(state);
		certificationsRequired.removeAll();
		for (int i = 1; i <= certifications.getTableSize(); ++i) {
			certificationsRequired.add(certifications.getStringAt(i));
		}

		certifications.pop();
	} else if (varName == "structureFootprintFileName") {
		structureFootprint = templateManager->loadStructureFootprint(Lua::getStringParameter(state));
	} else if (varName == "targetable") {
		targetable = Lua::getByteParameter(state);
	} else if (varName == "playerUseMask") {
		playerUseMask = Lua::getShortParameter(state);
	} else if (varName == "useCount") {
		useCount = Lua::getIntParameter(state);
	} else if (varName == "factoryCrateSize") {
		factoryCrateSize = Lua::getIntParameter(state);
	} else if (varName == "maxCondition") {
		maxCondition = Lua::getIntParameter(state);
	} else if (varName == "level") {
		level = Lua::getIntParameter(state);
	} else if (varName == "optionsBitmask") {
		optionsBitmask = Lua::getIntParameter(state);
	} else if (varName == "pvpStatusBitmask") {
		pvpStatusBitmask = Lua::getIntParameter(state);
	} else if (varName == "sliceable") {
		sliceable = Lua::getIntParameter(state);
	} else if (varName == "faction") {
		String factionString = Lua::getStringParameter(state);
		faction = factionString.toLowerCase().hashCode();
	} else if (varName == "playerRaces") {
		LuaObject races(state);

		// Inherited lists need to be tossed if a new list is about to be created
		if (playerRaces->size() != 0) {
			playerRaces->removeAll();
		}

		for (int i = 1; i <= races.getTableSize(); ++i) {
			String race = races.getStringAt(i);

			if (!playerRaces->contains(race.hashCode())) {
				playerRaces->add(race.hashCode());
			}


		}

		races.pop();
	} else if (varName == "skillMods") {
		skillMods.removeAll();

		LuaObject smods(state);
		for (int i = 1; i <= smods.getTableSize(); ++i) {
			lua_rawgeti(state, -1, i);
			LuaObject mod(state);

			String modName = mod.getStringAt(1);
			int modValue = mod.getIntAt(2);

			skillMods.put(modName, modValue);

			mod.pop();
		}
		smods.pop();
	} else if (varName == "numberExperimentalProperties") {
		LuaObject numberExperimentalPropertiesList(state);
		numberExperimentalProperties->removeAll();
		for (int i = 1; i <= numberExperimentalPropertiesList.getTableSize(); ++i) {
			numberExperimentalProperties->add(numberExperimentalPropertiesList.getIntAt(i));
		}

		numberExperimentalPropertiesList.pop();
	} else if (varName == "experimentalProperties") {
		LuaObject experimentalPropertiesList(state);
		experimentalProperties->removeAll();
		for (int i = 1; i <= experimentalPropertiesList.getTableSize(); ++i) {
			experimentalProperties->add(experimentalPropertiesList.getStringAt(i));
		}

		experimentalPropertiesList.pop();
	} else if (varName == "experimentalWeights") {
		LuaObject experimentalWeightsList(state);
		experimentalWeights->removeAll();
		for (int i = 1; i <= experimentalWeightsList.getTableSize(); ++i) {
			experimentalWeights->add(experimentalWeightsList.getIntAt(i));
		}

		experimentalWeightsList.pop();
	} else if (varName == "experimentalGroupTitles") {
		LuaObject experimentalGroupTitlesList(state);
		experimentalGroupTitles->removeAll();
		for (int i = 1; i <= experimentalGroupTitlesList.getTableSize(); ++i) {
			experimentalGroupTitles->add(experimentalGroupTitlesList.getStringAt(i));
		}

		experimentalGroupTitlesList.pop();
	} else if (varName == "experimentalSubGroupTitles") {
		LuaObject experimentalSubGroupTitlesList(state);
		experimentalSubGroupTitles->removeAll();
		for (int i = 1; i <= experimentalSubGroupTitlesList.getTableSize(); ++i) {
			experimentalSubGroupTitles->add(experimentalSubGroupTitlesList.getStringAt(i));
		}

		experimentalSubGroupTitlesList.pop();
	} else if (varName == "experimentalMin") {
		LuaObject experimentalMinList(state);
		experimentalMin->removeAll();
		for (int i = 1; i <= experimentalMinList.getTableSize(); ++i) {
			experimentalMin->add(experimentalMinList.getFloatAt(i));
		}

		experimentalMinList.pop();
	} else if (varName == "experimentalMax") {
		LuaObject experimentalMaxList(state);
		experimentalMax->removeAll();
		for (int i = 1; i <= experimentalMaxList.getTableSize(); ++i) {
			experimentalMax->add(experimentalMaxList.getFloatAt(i));
		}

		experimentalMaxList.pop();
	} else if (varName == "experimentalPrecision") {
		LuaObject experimentalPrecisionList(state);
		experimentalPrecision->removeAll();
		for (int i = 1; i <= experimentalPrecisionList.getTableSize(); ++i) {
			experimentalPrecision->add(experimentalPrecisionList.getIntAt(i));
		}
		experimentalPrecisionList.pop();
	} else if (varName == "experimentalCombineType") {
		LuaObject experimentalCombineList(state);
		experimentalCombineType->removeAll();
		for (int i = 1; i <= experimentalCombineList.getTableSize(); ++i) {
			experimentalCombineType->add(experimentalCombineList.getIntAt(i));
		}
		experimentalCombineList.pop();
	} else {
		data->pop();
	}

}
示例#2
0
文件: ddicrawler.cpp 项目: mtassin/4e
static T_Status Crawl_Data(bool use_cache, T_Glyph_Ptr email, T_Glyph_Ptr password,
                            T_Filename output_folder, bool is_clear)
{
    T_Status                status;
    T_WWW                   internet = NULL;
    bool                    is_exists;
    T_Glyph_Ptr             path_ptr;
    T_Filename              folder;
    T_XML_Document          doc_languages = NULL;
    T_XML_Document          doc_wepprops = NULL;
    T_XML_Document          doc_sources = NULL;
    C_Pool                  pool(10000000,10000000);
    C_DDI_Deities           deities(&pool);
    C_DDI_Skills            skills(&pool);
    C_DDI_Rituals           rituals(&pool);
    C_DDI_Items             items(&pool);
    C_DDI_Classes           classes(&pool);
    C_DDI_Races             races(&pool);
    C_DDI_Paragons          paragons(&pool);
    C_DDI_Epics             epics(&pool);
    C_DDI_Feats             feats(&pool);
    C_DDI_Powers            powers(&pool);
    C_DDI_Monsters          monsters(&pool);
    C_DDI_Backgrounds       backgrounds(&pool);
    vector<C_DDI_Common *>  list;
    vector<C_DDI_Single_Common *>   singles;

    /* Add all of our downloader classes to the list
    */
    list.push_back(&deities);
    list.push_back(&skills);
    list.push_back(&rituals);
    list.push_back(&items);
    list.push_back(&classes);
    list.push_back(&races);
    list.push_back(&paragons);
    list.push_back(&epics);
    list.push_back(&feats);
    list.push_back(&powers);
//Monsters aren't supported yet...
#ifdef NOTYET
    list.push_back(&monsters);
#endif
    list.push_back(&backgrounds);

    /* Find a temporary folder to use
    */
    Get_Temporary_Folder(folder);
    path_ptr = folder + strlen(folder);

    /* Search for the folder and create it if it doesn't exist
    */
    is_exists = FileSys_Does_Folder_Exist(folder);
    if (!is_exists) {
        status = FileSys_Create_Directory(folder);
        if (x_Trap_Opt(!x_Is_Success(status))) {
            Log_Message("Couldn't create temporary folder.");
            x_Status_Return(LWD_ERROR);
            }
        }

    /* If we're not using cached copies, log in to D&D insider (if we don't
        have a username and password, this just establishes the connection)
    */
    if (!use_cache) {
        Log_Message("Connecting to server...\n", true);

        /* Open a connection to the server first
        */
        status = WWW_HTTP_Open(&internet,LOGIN_URL,NULL,NULL,NULL);
        if (x_Trap_Opt(!x_Is_Success(status))) {
            Log_Message("Couldn't open connection to login server!\n", true);
            goto cleanup_exit;
            }

        status = Login(internet, email, password, true);
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }

    /* If we're not using the cache, we want to make sure we have fresh copies
        of everything, so delete the files in our temporary folder
    */
    if (!use_cache) {
        strcpy(path_ptr,"*.*");
        FileSys_Delete_Files(folder);
        *path_ptr = '\0';
        }

    /* Create XML documents for deities languages - the crawlers can add their
        own entries for these during processing
    */
    status = Create_Document(&doc_languages, &l_language_root, "language",
                                DTD_Get_Data());
    if (!x_Is_Success(status))
        goto cleanup_exit;
    status = Create_Document(&doc_wepprops, &l_wepprop_root, "weapon property",
                                DTD_Get_Augmentation());
    if (!x_Is_Success(status))
        goto cleanup_exit;
    status = Create_Document(&doc_sources, &l_source_root, "source",
                                DTD_Get_Augmentation());
    if (!x_Is_Success(status))
        goto cleanup_exit;

    /* First, download all the index pages if we need to
    */
    if (!use_cache) {
        for (ddi_iter it = list.begin(); it != list.end(); ++it) {
            status = (*it)->Download_Index(folder, internet);
            if (x_Trap_Opt(!x_Is_Success(status)))
                goto cleanup_exit;
            }
        for (single_iter it = singles.begin(); it != singles.end(); ++it) {
            status = (*it)->Download(folder, internet);
            if (x_Trap_Opt(!x_Is_Success(status)))
                goto cleanup_exit;
            }
        }

    /* Read them in
    */
    for (ddi_iter it = list.begin(); it != list.end(); ++it) {
        status = (*it)->Read_Index(folder);
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }
    for (single_iter it = singles.begin(); it != singles.end(); ++it) {
        status = (*it)->Read(folder);
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }

    /* Now download the rest of the content all at once
        NOTE: As of March 2011, there's no further content for download unless
            you have a password.
    */
    if (!use_cache && l_is_password) {
        for (ddi_iter it = list.begin(); it != list.end(); ++it) {
            status = (*it)->Download_Content(folder, internet);
            if (x_Trap_Opt(!x_Is_Success(status)))
                goto cleanup_exit;
            }

        /* It's possible that some downloads were screwed up due to the
            servers acting weirdly. If so, they were added to a failed list,
            so try them again
        */
        Retry_Failed_Downloads(internet);
        }

    /* Read it in and process it
    */
    for (ddi_iter it = list.begin(); it != list.end(); ++it) {
        status = (*it)->Read_Content(folder);
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }

    /* Process all our stuff
    */
    for (ddi_iter it = list.begin(); it != list.end(); ++it) {
        status = (*it)->Process();
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }
    for (single_iter it = singles.begin(); it != singles.end(); ++it) {
        status = (*it)->Process();
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }

    /* Post-process all our stuff - this requires it to have been output first,
        and puts finishing touches on everything
    */
    for (ddi_iter it = list.begin(); it != list.end(); ++it) {
        status = (*it)->Post_Process(folder);
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }
    for (single_iter it = singles.begin(); it != singles.end(); ++it) {
        status = (*it)->Post_Process(folder);
        if (x_Trap_Opt(!x_Is_Success(status)))
            goto cleanup_exit;
        }

    /* Output our languages to the temporary folder, so we can append
        extensions to them later
    */
    status = Finish_Document(doc_languages, folder, LANGUAGE_FILENAME);
    if (!x_Is_Success(status))
        goto cleanup_exit;

    /* Now append any fixup extensions that are needed to compensate for the
        data being terrible
    */
    Append_Extensions(folder, output_folder);

    /* Load the old "powers" XML document and try and copy any wizard powers
        out of it
    */
//We don't need to do this any more, but keep the code around just in case...
//    Fixup_Wizard_Powers(output_folder);

    /* Sources and weapon properties don't need any extensions, so they can go
        directly into the output folder - plus they're augmentation files,
        which aren't messed with anyway
    */
    status = Finish_Document(doc_sources, output_folder, SOURCE_FILENAME);
    if (!x_Is_Success(status))
        goto cleanup_exit;
    status = Finish_Document(doc_wepprops, output_folder, WEPPROP_FILENAME);
    if (!x_Is_Success(status))
        goto cleanup_exit;

    /* wrapup everything
    */
cleanup_exit:
    l_language_root = NULL;
    if (doc_languages != NULL)
        XML_Destroy_Document(doc_languages);
    l_wepprop_root = NULL;
    if (doc_wepprops != NULL)
        XML_Destroy_Document(doc_wepprops);
    l_source_root = NULL;
    if (doc_sources != NULL)
        XML_Destroy_Document(doc_sources);
    if (internet != NULL)
        WWW_Close_Server(internet);

    /* Delete everything in our folder if required
    */
    if (is_clear) {
        strcpy(path_ptr,"*.*");
        FileSys_Delete_Files(folder);
        *path_ptr = '\0';
        }

    x_Status_Return(status);
}