Esempio n. 1
0
/**
 * @brief Converts a vector to an angle vector
 * @param[in] value1
 * @param[in] angles Target vector for pitch, yaw, roll
 * @sa anglemod
 */
void VecToAngles (const vec3_t value1, vec3_t angles)
{
	float yaw, pitch;

	/* only check the first two values for being zero */
	if (Vector2Empty(value1)) {
		yaw = 0;
		if (value1[2] > 0)
			pitch = 90.0;
		else
			pitch = 270.0;
	} else {
		const float forward = sqrt(value1[0] * value1[0] + value1[1] * value1[1]);
		if (!equal(value1[0], 0.0))
			yaw = (int) (atan2(value1[1], value1[0]) * todeg);
		else if (value1[1] > 0)
			yaw = 90.0;
		else
			yaw = -90.0;
		if (yaw < 0.0)
			yaw += 360.0;

		pitch = (int) (atan2(value1[2], forward) * todeg);
		if (pitch < 0)
			pitch += 360.0;
	}

	/* up and down */
	angles[PITCH] = -pitch;
	/* left and right */
	angles[YAW] = yaw;
	/* tilt left and right */
	angles[ROLL] = 0;
}
Esempio n. 2
0
/**
 * @brief Handled after the end of the load of the node from the script (all data and/or child are set)
 */
void uiImageNode::onLoaded (uiNode_t* node)
{
	/* update the size when its possible */
	if (Vector2Empty(node->box.size)) {
		if (EXTRADATA(node).texl[0] != 0 || EXTRADATA(node).texh[0]) {
			node->box.size[0] = EXTRADATA(node).texh[0] - EXTRADATA(node).texl[0];
			node->box.size[1] = EXTRADATA(node).texh[1] - EXTRADATA(node).texl[1];
		} else if (node->image) {
			const image_t* image = UI_LoadImage(node->image);
			if (image) {
				node->box.size[0] = image->width;
				node->box.size[1] = image->height;
			}
		}
	}
#ifdef DEBUG
	if (Vector2Empty(node->box.size)) {
		if (node->onClick || node->onRightClick || node->onMouseEnter || node->onMouseLeave || node->onWheelUp || node->onWheelDown || node->onWheel || node->onMiddleClick) {
			Com_DPrintf(DEBUG_CLIENT, "Node '%s' is an active image without size\n", UI_GetPath(node));
		}
	}
#endif
}
Esempio n. 3
0
/**
 * @brief Get the noticePosition from a window node.
 * @param node A window node
 * @return A position, else nullptr if no notice position
 */
vec_t* UI_WindowNodeGetNoticePosition(uiNode_t* node)
{
	if (Vector2Empty(EXTRADATA(node).noticePos))
		return nullptr;
	return EXTRADATA(node).noticePos;
}
Esempio n. 4
0
static void SCP_ParseMission (const char *name, const char **text)
{
	const char *errhead = "SCP_ParseMission: unexpected end of file (mission ";
	staticMission_t *ms;
	const value_t *vp;
	const char *token;
	int i;
	size_t writtenBytes;

	token = Com_Parse(text);
	if (token[0] == '\0' || text[0] == '\0') {
		Com_Printf("SCP_ParseMission: mission def \"%s\" without name ignored\n", name);
		return;
	}

	/* search for missions with same name */
	for (i = 0; i < scd->numMissions; i++)
		if (Q_streq(token, scd->missions[i].id))
			break;

	if (i < scd->numMissions) {
		Com_Printf("SCP_ParseMission: mission def \"%s\" with same name found, second ignored\n", token);
		return;
	}

	if (scd->numMissions >= MAX_STATIC_MISSIONS) {
		Com_Printf("SCP_ParseMission: Too many missions, ignore '%s'\n", token);
		return;
	}

	/* initialize the menu */
	ms = &scd->missions[scd->numMissions];
	OBJZERO(*ms);

	Q_strncpyz(ms->id, token, sizeof(ms->id));

	/* get it's body */
	token = Com_Parse(text);

	if (text[0] == '\0' || !Q_streq(token, "{")) {
		Com_Printf("SCP_ParseMission: mission def \"%s\" without body ignored\n", ms->id);
		return;
	}

	do {
		token = Com_EParse(text, errhead, ms->id);
		if (text[0] == '\0')
			break;
		if (token[0] == '}')
			break;

		for (vp = mission_vals; vp->string; vp++)
			if (Q_streq(token, vp->string)) {
				/* found a definition */
				token = Com_EParse(text, errhead, ms->id);
				if (text[0] == '\0')
					return;

				if (vp->ofs) {
					Com_ParseValue(ms, token, vp->type, vp->ofs, vp->size, &writtenBytes);
				} else {
					Com_Printf("SCP_ParseMission: unknown token '%s'\n", token);
				}
				break;
			}

		if (!vp->string) {
			if (Q_streq(token, "city")) {
				const city_t *city;
				token = Com_EParse(text, errhead, ms->id);
				if (text[0] == '\0')
					return;
				city = CP_GetCity(token);
				if (city == NULL)
					Com_Printf("SCP_ParseMission: unknown city \"%s\" ignored (mission %s)\n", token, ms->id);
				else
					Vector2Copy(city->pos, ms->pos);
			} else {
				Com_Printf("SCP_ParseMission: unknown token \"%s\" ignored (mission %s)\n", token, ms->id);
			}
		}

	} while (*text);

	mapDef_t *mapDef = cgi->Com_GetMapDefinitionByID(ms->id);
	if (mapDef == NULL) {
		Com_Printf("SCP_ParseMission: invalid mapdef for '%s'\n", ms->id);
		return;
	}

	if (Vector2Empty(ms->pos)) {
		if (!CP_GetRandomPosOnGeoscapeWithParameters(ms->pos, mapDef->terrains, mapDef->cultures, mapDef->populations, NULL)) {
			Com_Printf("SCP_ParseMission: could not find a valid position for '%s'\n", ms->id);
			return;
		}
	}

	scd->numMissions++;
}