コード例 #1
0
ファイル: eventsave.cpp プロジェクト: noccy80/warzone2100
// save a list of triggers
static bool eventSaveTriggerList(ACTIVE_TRIGGER *psList, QString tname, WzConfig &ini)
{
    int numTriggers = 0, context = 0;

    for (ACTIVE_TRIGGER *psCurr = psList; psCurr != NULL; psCurr = psCurr->psNext)
    {
        if (!eventGetContextIndex(psCurr->psContext, &context))
        {
            debug(LOG_FATAL, "Could not find context");
            return false;
        }
        ini.beginGroup(tname + "_" + QString::number(numTriggers));
        ini.setValue("time", QVariant(psCurr->testTime));
        ini.setValue("context", QVariant(context));
        ini.setValue("type", QVariant(psCurr->type));
        ini.setValue("trigger", QVariant(psCurr->trigger));
        ini.setValue("event", QVariant(psCurr->event));
        ini.setValue("offset", QVariant(psCurr->offset));
        ini.endGroup();
        numTriggers++;
    }
    ini.setValue("general/num" + tname, QVariant(numTriggers));
    return true;
}
コード例 #2
0
// save a list of triggers
static BOOL eventSaveTriggerList(ACTIVE_TRIGGER *psList, char *pBuffer, UDWORD *pSize)
{
	ACTIVE_TRIGGER		*psCurr;
	UDWORD				size;
	char				*pPos;
	SDWORD				numTriggers, context;

	size = 0;
	pPos = pBuffer;

	// reserve some space for the number of triggers
	if (pBuffer != NULL)
	{
		pPos += sizeof(SDWORD);
	}
	size += sizeof(SDWORD);

	numTriggers = 0;
	for(psCurr = psList; psCurr != NULL; psCurr = psCurr->psNext)
	{
		numTriggers += 1;

		if (pBuffer != NULL)
		{
			*((UDWORD*)pPos) = psCurr->testTime;
			endian_udword((UDWORD*)pPos);

			pPos += sizeof(UDWORD);
			if (!eventGetContextIndex(psCurr->psContext, &context))
			{
				debug( LOG_FATAL, "eventSaveTriggerList: couldn't find context" );
				abort();
				return false;
			}
			*((SWORD*)pPos) = (SWORD)context;
			endian_sword((SWORD*)pPos);
			pPos += sizeof(SWORD);
			*((SWORD*)pPos) = psCurr->type;
			endian_sword((SWORD*)pPos);
			pPos += sizeof(SWORD);
			*((SWORD*)pPos) = psCurr->trigger;
			endian_sword((SWORD*)pPos);
			pPos += sizeof(SWORD);
			*((UWORD*)pPos) = psCurr->event;
			endian_uword((UWORD*)pPos);
			pPos += sizeof(UWORD);
			*((UWORD*)pPos) = psCurr->offset;
			endian_uword((UWORD*)pPos);
			pPos += sizeof(UWORD);
		}
		size += sizeof(UDWORD) + sizeof(SWORD)*3 + sizeof(UWORD)*2;
	}
	if (pBuffer != NULL)
	{
		*((SDWORD*)pBuffer) = numTriggers;
		endian_sdword((SDWORD*)pBuffer);
	}

	*pSize = size;

	return true;
}