예제 #1
0
파일: entitiesdef.c 프로젝트: kevlund/ufoai
/**
 * @brief tests if a value string matches the type for this key. Also checks the value against the
 * range, if one was defined.
 * @return ED_OK or ED_ERROR
 * @sa ED_GetLastError
 * @note abstract (radiant) keys may not have types. keys used here must be declared in entities.ufo in
 * an optional or mandatory block.
 */
int ED_Check (const char *classname, const char *key, const char *value)
{
	const entityKeyDef_t *kd = ED_GetKeyDef(classname, key, 0);
	if (!kd)
		return ED_ERROR;

	return ED_CheckKey(kd, value);
}
예제 #2
0
파일: entitiesdef.c 프로젝트: kevlund/ufoai
/**
 * @brief checks if the default block entries meet the type and range definitions.
 * @return ED_ERROR or ED_OK
 * @sa CheckLastError
 */
static int ED_CheckDefaultTypes (void)
{
	const entityDef_t *ed;
	const entityKeyDef_t *kd;
	for (ed = entityDefs; ed->numKeyDefs; ed++)
		for (kd = ed->keyDefs; kd->name; kd++)
			if (kd->defaultVal)
				ED_PASS_ERROR_EXTRAMSG(ED_CheckKey(kd, kd->defaultVal),
					" while checking default block entry agrees with type")

	return ED_OK;
}
예제 #3
0
/**
 * @brief Perform an entity check
 */
void CheckEntities (void)
{
	Check_InitEntityDefs();

	for (int i = 0; i < num_entities; i++) {
		entity_t* e = &entities[i];
		const char* name = ValueForKey(e, "classname");
		const entityDef_t* ed = ED_GetEntityDef(name);
		const epair_t* kvp;
		const entityKeyDef_t* kd;

		if (!ed) { /* check that a definition exists */
			Check_Printf(VERB_CHECK, false, i, -1, "Not defined in entities.ufo: %s\n", name);
			continue;
		}

		/* check alignment of info_.+_start */
		if (Check_IsInfoStart(name) && !Check_InfoStartAligned(ed, e))
			Check_Printf(VERB_CHECK, false, i, -1, "Misaligned %s\n", name);

		if (Q_strstart(name, "func_")) /* func_* entities should have brushes */
			Check_EntityWithBrushes(e, name, i);

		/* check all keys in the entity - make sure they are OK */
		for (kvp = e->epairs; kvp; kvp = kvp->next) {
			kd = ED_GetKeyDefEntity(ed, kvp->key, 0); /* zero means ignore abstract (radiant only) keys */

			if (!kd) { /* make sure it has a definition */
				Check_Printf(VERB_CHECK, false, i, -1, "Not defined in entities.ufo: %s in %s\n", kvp->key, name);
				continue;
			}

			if (ED_CheckKey(kd, kvp->value) == ED_ERROR) { /* check values against type and range definitions in entities.ufo */
				Check_Printf(VERB_CHECK, false, i, -1, "%s\n", ED_GetLastError());
				continue;
			}

			if (Q_streq("target", kvp->key) || Q_streq("targetname", kvp->key)) {
				if (!Check_TargetExists(kvp)) {
					Check_Printf(VERB_CHECK, false, i, -1,
						"%s with %s of %s: no corresponding entity with %s with matching value\n",
						ed->classname, kvp->key, kvp->value, Q_streq("target", kvp->key) ? "targetname" : "target");
				}
			}
		}

		/* check keys in the entity definition - make sure mandatory ones are present */
		for (kd = ed->keyDefs; kd->name; kd++) {
			if (kd->flags & ED_MANDATORY) {
				const char* keyNameInEnt = ValueForKey(e, kd->name);
				if (keyNameInEnt[0] == '\0') {
					const char* defaultVal = kd->defaultVal;
					const bool hasDefault = defaultVal ? true : false;
					Check_Printf(VERB_CHECK, hasDefault, i, -1, "Mandatory key missing from entity: %s in %s", kd->name, name);
					if (defaultVal) {
						Check_Printf(VERB_CHECK, hasDefault, i, -1, ", supplying default: %s", defaultVal);
						SetKeyValue(e, kd->name, defaultVal);
					}
					Check_Printf(VERB_CHECK, hasDefault, i, -1, "\n");
				}
			}
		}
	}
}