Пример #1
0
	void doCheck()
	{
		double radius;

		// Get list of lines to check
		vector<MapLine*> check_lines;
		MapLine* line;
		for (unsigned a = 0; a < map->nLines(); a++)
		{
			line = map->getLine(a);

			// Skip if line is 2-sided and not blocking
			if (line->s2() && !theGameConfiguration->lineBasicFlagSet("blocking", line, map->currentFormat()))
				continue;

			check_lines.push_back(line);
		}

		// Go through things
		for (unsigned a = 0; a < map->nThings(); a++)
		{
			MapThing* thing = map->getThing(a);
			ThingType* tt = theGameConfiguration->thingType(thing->getType());

			// Skip if not a solid thing
			if (!tt->isSolid())
				continue;

			radius = tt->getRadius() - 1;

			// Go through lines
			for (unsigned b = 0; b < check_lines.size(); b++)
			{
				line = check_lines[b];

				// Check intersection
				if (MathStuff::boxLineIntersect(thing->xPos() - radius, thing->yPos() - radius,
					thing->xPos() + radius, thing->yPos() + radius,
					line->x1(), line->y1(), line->x2(), line->y2()))
				{
					things.push_back(thing);
					lines.push_back(line);
					break;
				}
			}
		}
	}
Пример #2
0
	bool fixProblem(unsigned index, unsigned fix_type, MapEditor* editor)
	{
		if (index >= things.size())
			return false;

		if (fix_type == 0)
		{
			MapThing* thing = things[index];
			MapLine* line = lines[index];

			// Get nearest line point to thing
			fpoint2_t np = MathStuff::closestPointOnLine(thing->xPos(), thing->yPos(), line->x1(), line->y1(), line->x2(), line->y2());

			// Get distance to move
			double r = theGameConfiguration->thingType(thing->getType())->getRadius();
			double dist = MathStuff::distance(0, 0, r, r);

			editor->beginUndoRecord("Move Thing", true, false, false);

			// Move along line direction
			map->moveThing(thing->getIndex(), np.x - (line->frontVector().x * dist), np.y - (line->frontVector().y * dist));

			editor->endUndoRecord();

			return true;
		}

		return false;
	}