示例#1
0
void TWBaseScript::fixup_player_links(void)
{
    int player = StrToObject("Player");
    if (player) {
        ::FixupPlayerLinks(ObjId(), player);
        need_fixup = false;
    } else {
        g_pScriptManager -> SetTimedMessage2(ObjId(), "DelayInit", 1, kSTM_OneShot, "FixupPlayerLinks");
    }
}
示例#2
0
int GetParamObject(const char* pszString, const char* pszParam, int iDefault)
{
	if (!pszString || !pszParam)
		return iDefault;
	char* pszRet = NULL;
	char* pszTemp = reinterpret_cast<char*>(alloca(strlen(pszString)+1));
	if (!pszTemp)
		return 0;
	strcpy(pszTemp, pszString);
	char* pszSep, *pszToken;
	for (pszSep = pszTemp, pszToken = strqsep(&pszSep, g_pszParamDelim, g_pszQuotes);
	     pszToken; pszToken = strqsep(&pszSep, g_pszParamDelim, g_pszQuotes))
	{
		while (isspace(*pszToken)) ++pszToken;
		char* pszStart = strchr(pszToken, '=');
		if (pszStart)
			*pszStart++ = '\0';
		if (!_stricmp(pszToken, pszParam))
		{
			if (!pszStart)
				break;
			while (isspace(*pszStart)) ++pszStart;
			if (*pszStart == '"' || *pszStart == '\'')
			{
				char quote = *pszStart++;
				char* pszEnd = strrchr(pszStart, quote);
				if (!pszEnd)
					pszEnd = pszStart + strlen(pszStart);
				char* pszChar = pszRet = pszStart;
				while (pszStart < pszEnd)
				{
					if (*pszStart == '\\' &&
					    (pszStart[1] == '\\' || pszStart[1] == quote))
					{
						++pszStart;
					}
					*pszChar++ = *pszStart++;
				}
				*pszChar = '\0';
			}
			else
			{
				int iLen = strlen(pszStart);
				pszRet = pszStart;
				pszRet[iLen] = '\0';
			}
			break;
		}
	}
	int iRet = (pszRet) ? StrToObject(pszRet) : iDefault;
	return iRet;
}
示例#3
0
int TWBaseScript::get_linked_object(const int from, const std::string& obj_name, const std::string& link_name, const int fallback)
{
    SInterface<IObjectSystem> ObjectSys(g_pScriptManager);
    SService<IObjectSrv>      ObjectSrv(g_pScriptManager);
    SService<ILinkSrv>        LinkSrv(g_pScriptManager);
    SService<ILinkToolsSrv>   LinkToolsSrv(g_pScriptManager);

    // Can't do anything if there is no archytype name set
    if(!obj_name.empty()) {

        // Attempt to locate the object requested
        int object = StrToObject(obj_name.c_str());
        if(object) {

            // Convert the link to a liny type ID
            long flavourid = LinkToolsSrv -> LinkKindNamed(link_name.c_str());

            if(flavourid) {
                // Does the object have a link of the specified flavour?
                true_bool has_link;
                LinkSrv -> AnyExist(has_link, flavourid, from, 0);

                // Only do anything if there is at least one particle attachment.
                if(has_link) {
                    linkset links;
                    true_bool inherits;

                    // Check all the links of the appropriate flavour, looking for a link either to
                    // the named object, or to an object that inherits from it
                    LinkSrv -> GetAll(links, flavourid, from, 0);
                    while(links.AnyLinksLeft()) {
                        sLink link = links.Get();

                        // If the object is an archetype, check whether the destination inherits from it.
                        if(object < 0) {
                            ObjectSrv -> InheritsFrom(inherits, link.dest, object);

                            // Found a link from a concrete instance of the archetype? Return that object.
                            if(inherits) {
                                return link.dest;
                            }

                        // If the target object is concrete, is the link to that object?
                        } else if(link.dest == object) {
                            return link.dest;
                        }

                        links.NextLink();
                    }

                    if(debug_enabled())
                        debug_printf(DL_WARNING, "Object has no %s link to a object named or inheriting from %s", link_name.c_str(), obj_name.c_str());
                }
            } else {
                debug_printf(DL_ERROR, "Request for non-existent link flavour %s", link_name.c_str());
            }
        } else if(debug_enabled()) {
            debug_printf(DL_WARNING, "Unable to find object named '%s'", obj_name.c_str());
        }
    } else {
        debug_printf(DL_ERROR, "obj_name name is empty.");
    }

    return fallback;
}