コード例 #1
0
void CreateRandomAvoidsSet()
{
	cout << "Generating avoids" << endl;
	int counter = 0;
	int* output_seq_of_locations = (int*)malloc(100 * sizeof(int));
	int outsize;
	int numRobots = WORKSPACE_INFO->numOfRobots;
	avoidsArr = (AvoidPositions*)malloc((numRobots - 1) * sizeof(AvoidPositions));
	sizeof_avoids = 0;
	while (counter < (numRobots - 1))
	{
		int st = GetStartLocation(counter);
		int g = GetEndLocation(counter);
		cout << st << endl;
		cout << g << endl;
		output_seq_of_locations = (int*)malloc(1000 * sizeof(int));
		GenerateMotionPlanFor(*WORKSPACE_INFO, st, g, WORKSPACE_INFO->obstacles.locations, WORKSPACE_INFO->obstacles.size, avoidsArr, sizeof_avoids, output_seq_of_locations, &outsize);
		cout << "Trajectory Length = " << outsize << endl;
		cout << "Trajectory: " << endl;
		for (int count = 0; count < outsize; count++)
		{
			cout << output_seq_of_locations[count] << " ";
		}
		cout << endl;
		avoidsArr[counter].size = outsize;
		for (int i = 0; i < outsize; i++)
		{
			avoidsArr[counter].PositionsOccupied[i] = output_seq_of_locations[i];
		}
		sizeof_avoids++;
		counter++;
	}
	cout << "------------" << endl;
}
コード例 #2
0
//=================================================================================================
cstring Quest_Orcs::FormatString(const string& str)
{
	if(str == "target_loc")
		return GetTargetLocationName();
	else if(str == "target_dir")
		return GetTargetLocationDir();
	else if(str == "naszego_miasta")
		return LocationHelper::IsCity(GetStartLocation()) ? game->txQuest[72] : game->txQuest[73];
	else
	{
		assert(0);
		return nullptr;
	}
}
コード例 #3
0
//=================================================================================================
void Quest_SpreadNews::Start()
{
	type = QuestType::Mayor;
	quest_id = Q_SPREAD_NEWS;
	start_loc = W.GetCurrentLocationIndex();
	Vec2 pos = GetStartLocation().pos;
	bool sorted = false;
	const vector<Location*>& locations = W.GetLocations();
	for(uint i = 0, count = locations.size(); i < count; ++i)
	{
		if(!locations[i] || locations[i]->type != L_CITY)
			break;
		if(i == start_loc)
			continue;
		Location& loc = *locations[i];
		float dist = Vec2::Distance(pos, loc.pos);
		bool ok = false;
		if(entries.size() < 5)
			ok = true;
		else
		{
			if(!sorted)
			{
				std::sort(entries.begin(), entries.end(), SortEntries);
				sorted = true;
			}
			if(entries.back().dist > dist)
			{
				ok = true;
				sorted = false;
				entries.pop_back();
			}
		}
		if(ok)
		{
			Entry& e = Add1(entries);
			e.location = i;
			e.given = false;
			e.dist = dist;
		}
	}
}
コード例 #4
0
int main()
{
	int count;
	int* output_seq_of_locations = (int*)malloc(100 * sizeof(int));
	int output_size = 0;
	srand(time(NULL));

	//Initialize the workspace
	WORKSPACE_INFO = ParseWorkspaceConfig("C:\\Workspace\\Drona\\Src\\Workspaces\\Exp1\\Workspace.xml");

	int exp = 3;

	cout << "--------------------------------" << endl;
	cout << "Num Robots: " << WORKSPACE_INFO->numOfRobots << endl;
	CreateRandomAvoidsSet();
	exp = 5;
	while (exp > 0)
	{
		cout << "Experiment " << exp << endl;
		int st = GetStartLocation(WORKSPACE_INFO->numOfRobots - 1);
		int g = GetEndLocation(WORKSPACE_INFO->numOfRobots -1);
		cout << st << endl;
		cout << g << endl;
		output_seq_of_locations = (int*)malloc(1000 * sizeof(int));
		GenerateMotionPlanFor(*WORKSPACE_INFO, st, g, WORKSPACE_INFO->obstacles.locations, WORKSPACE_INFO->obstacles.size, avoidsArr, sizeof_avoids, output_seq_of_locations, &output_size);
		cout << "Trajectory Length = " << output_size << endl;
		cout << "Trajectory: " << endl;
		for (count = 0; count < output_size; count++)
		{
			cout << output_seq_of_locations[count] << " ";
		}
		cout << endl;
		free(output_seq_of_locations);
		exp--;
		cout << "--------------------------------" << endl;
	}
	return 0;
}
コード例 #5
0
//=================================================================================================
void Quest_Orcs::SetProgress(int prog2)
{
	switch(prog2)
	{
	case Progress::TalkedWithGuard:
		{
			if(prog != Progress::None)
				return;
			if(QM.RemoveQuestRumor(R_ORCS))
				game->gui->journal->AddRumor(Format(game->txQuest[189], GetStartLocationName()));
			QM.quest_orcs2->orcs_state = Quest_Orcs2::State::GuardTalked;
		}
		break;
	case Progress::NotAccepted:
		{
			if(QM.RemoveQuestRumor(R_ORCS))
				game->gui->journal->AddRumor(Format(game->txQuest[190], GetStartLocationName()));
			// mark guard to remove
			Unit*& u = QM.quest_orcs2->guard;
			if(u)
			{
				u->auto_talk = AutoTalkMode::No;
				u->temporary = true;
				u = nullptr;
			}
			QM.quest_orcs2->orcs_state = Quest_Orcs2::State::GuardTalked;
		}
		break;
	case Progress::Started:
		{
			OnStart(game->txQuest[191]);
			// remove rumor from pool
			QM.RemoveQuestRumor(R_ORCS);
			// mark guard to remove
			Unit*& u = QM.quest_orcs2->guard;
			if(u)
			{
				u->auto_talk = AutoTalkMode::No;
				u->temporary = true;
				u = nullptr;
			}
			// generate location
			Location& tl = *W.CreateLocation(L_DUNGEON, GetStartLocation().pos, 64.f, HUMAN_FORT, SG_ORCS, false);
			tl.SetKnown();
			tl.st = 8;
			tl.active_quest = this;
			target_loc = tl.index;
			location_event_handler = this;
			at_level = tl.GetLastLevel();
			dungeon_levels = at_level + 1;
			levels_cleared = 0;
			whole_location_event_handler = true;
			item_to_give[0] = Item::Get("q_orkowie_klucz");
			spawn_item = Quest_Event::Item_GiveSpawned2;
			unit_to_spawn = UnitData::Get("q_orkowie_gorush");
			spawn_unit_room = RoomTarget::Prison;
			unit_dont_attack = true;
			unit_to_spawn2 = g_spawn_groups[SG_ORCS].GetSpawnLeader(10);
			unit_spawn_level2 = -3;
			QM.quest_orcs2->orcs_state = Quest_Orcs2::State::Accepted;
			// questowe rzeczy
			msgs.push_back(Format(game->txQuest[192], GetStartLocationName(), W.GetDate()));
			msgs.push_back(Format(game->txQuest[193], GetStartLocationName(), GetTargetLocationName(), GetTargetLocationDir()));
		}
		break;
	case Progress::ClearedLocation:
		// oczyszczono lokacjê
		{
			OnUpdate(Format(game->txQuest[194], GetTargetLocationName(), GetStartLocationName()));
		}
		break;
	case Progress::Finished:
		// ukoñczono - nagroda
		{
			state = Quest::Completed;

			Team.AddReward(4000, 12000);
			OnUpdate(game->txQuest[195]);
			W.AddNews(Format(game->txQuest[196], GetTargetLocationName(), GetStartLocationName()));

			if(QM.quest_orcs2->orcs_state == Quest_Orcs2::State::OrcJoined)
			{
				QM.quest_orcs2->orcs_state = Quest_Orcs2::State::CompletedJoined;
				QM.quest_orcs2->days = Random(30, 60);
				GetTargetLocation().active_quest = nullptr;
				target_loc = -1;
			}
			else
				QM.quest_orcs2->orcs_state = Quest_Orcs2::State::Completed;
		}
		break;
	}

	prog = prog2;
}
コード例 #6
0
//=================================================================================================
void Quest_Goblins::SetProgress(int prog2)
{
	prog = prog2;
	switch(prog2)
	{
	case Progress::NotAccepted:
		// nie zaakceptowano
		{
			if(QM.RemoveQuestRumor(R_GOBLINS))
				game->gui->journal->AddRumor(Format(game->txQuest[211], GetStartLocationName()));
		}
		break;
	case Progress::Started:
		// zaakceptowano
		{
			OnStart(game->txQuest[212]);
			// usuñ plotkê
			QM.RemoveQuestRumor(R_GOBLINS);
			// dodaj lokalizacje
			target_loc = W.GetNearestLocation(GetStartLocation().pos, 1 << L_FOREST, true);
			Location& target = GetTargetLocation();
			target.SetKnown();
			target.reset = true;
			target.active_quest = this;
			target.st = 7;
			spawn_item = Quest_Event::Item_OnGround;
			item_to_give[0] = Item::Get("q_gobliny_luk");
			// questowe rzeczy
			msgs.push_back(Format(game->txQuest[217], GetStartLocationName(), W.GetDate()));
			msgs.push_back(Format(game->txQuest[218], GetTargetLocationName(), GetTargetLocationDir()));
			// encounter
			Encounter* e = W.AddEncounter(enc);
			e->check_func = CzyMajaStaryLuk;
			e->dialog = GameDialog::TryGet("q_goblins_encounter");
			e->dont_attack = true;
			e->group = SG_GOBLINS;
			e->location_event_handler = nullptr;
			e->pos = GetStartLocation().pos;
			e->quest = static_cast<Quest*>(this);
			e->chance = 10000;
			e->range = 32.f;
			e->text = game->txQuest[219];
			e->timed = false;
			e->st = 6;
		}
		break;
	case Progress::BowStolen:
		// gobliny ukrad³y ³uk
		{
			Team.RemoveQuestItem(Item::Get("q_gobliny_luk"));
			OnUpdate(game->txQuest[220]);
			W.RemoveEncounter(enc);
			enc = -1;
			GetTargetLocation().active_quest = nullptr;
			W.AddNews(game->txQuest[221]);
			Team.AddExp(1000);
		}
		break;
	case Progress::TalkedAboutStolenBow:
		// poinformowano o kradzie¿y
		{
			state = Quest::Failed;
			OnUpdate(game->txQuest[222]);
			goblins_state = State::Counting;
			days = Random(15, 30);
		}
		break;
	case Progress::InfoAboutGoblinBase:
		// pos³aniec dostarczy³ info o bazie goblinów
		{
			state = Quest::Started;
			target_loc = W.GetRandomSpawnLocation(GetStartLocation().pos, SG_GOBLINS);
			Location& target = GetTargetLocation();
			target.state = LS_KNOWN;
			target.st = 10;
			target.reset = true;
			target.active_quest = this;
			done = false;
			spawn_item = Quest_Event::Item_GiveSpawned;
			unit_to_spawn = g_spawn_groups[SG_GOBLINS].GetSpawnLeader(11);
			unit_spawn_level = -3;
			item_to_give[0] = Item::Get("q_gobliny_luk");
			at_level = target.GetLastLevel();
			OnUpdate(Format(game->txQuest[223], target.name.c_str(), GetTargetLocationDir(), GetStartLocationName()));
			goblins_state = State::MessengerTalked;
		}
		break;
	case Progress::GivenBow:
		// oddano ³uk
		{
			state = Quest::Completed;
			const Item* item = Item::Get("q_gobliny_luk");
			DialogContext::current->pc->unit->RemoveItem(item, 1);
			DialogContext::current->talker->AddItem(item, 1, true);
			Team.AddReward(500, 2500);
			OnUpdate(game->txQuest[224]);
			goblins_state = State::GivenBow;
			GetTargetLocation().active_quest = nullptr;
			target_loc = -1;
			W.AddNews(game->txQuest[225]);
		}
		break;
	case Progress::DidntTalkedAboutBow:
		// nie chcia³eœ powiedzieæ o ³uku
		{
			OnUpdate(game->txQuest[226]);
			goblins_state = State::MageTalkedStart;
		}
		break;
	case Progress::TalkedAboutBow:
		// powiedzia³eœ o ³uku
		{
			state = Quest::Started;
			OnUpdate(game->txQuest[227]);
			goblins_state = State::MageTalked;
		}
		break;
	case Progress::PayedAndTalkedAboutBow:
		// zap³aci³eœ i powiedzia³eœ o ³uku
		{
			DialogContext::current->pc->unit->ModGold(-100);

			state = Quest::Started;
			OnUpdate(game->txQuest[228]);
			goblins_state = State::MageTalked;
		}
		break;
	case Progress::TalkedWithInnkeeper:
		// pogadano z karczmarzem
		{
			goblins_state = State::KnownLocation;
			Location& target = *W.CreateLocation(L_DUNGEON, W.GetWorldPos(), 128.f, THRONE_FORT, SG_GOBLINS, false);
			target.st = 12;
			target.SetKnown();
			target.active_quest = this;
			target_loc = target.index;
			done = false;
			unit_to_spawn = UnitData::Get("q_gobliny_szlachcic2");
			spawn_unit_room = RoomTarget::Throne;
			callback = DodajStraznikow;
			unit_dont_attack = true;
			unit_auto_talk = true;
			unit_event_handler = this;
			item_to_give[0] = nullptr;
			spawn_item = Quest_Event::Item_DontSpawn;
			at_level = target.GetLastLevel();
			OnUpdate(Format(game->txQuest[229], target.name.c_str(), GetTargetLocationDir(), GetStartLocationName()));
		}
		break;
	case Progress::KilledBoss:
		// zabito szlachcica
		{
			state = Quest::Completed;
			OnUpdate(game->txQuest[230]);
			GetTargetLocation().active_quest = nullptr;
			QM.EndUniqueQuest();
			W.AddNews(game->txQuest[231]);
			Team.AddLearningPoint();
			Team.AddExp(15000);
		}
		break;
	}
}
コード例 #7
0
//=================================================================================================
void Quest_SpreadNews::SetProgress(int prog2)
{
	switch(prog2)
	{
	case Progress::Started:
		// told info to spread by player
		{
			OnStart(game->txQuest[213]);
			QM.quests_timeout2.push_back(this);

			prog = Progress::Started;

			Location& loc = GetStartLocation();
			bool is_city = LocationHelper::IsCity(loc);
			msgs.push_back(Format(game->txQuest[3], is_city ? game->txForMayor : game->txForSoltys, loc.name.c_str(), W.GetDate()));
			msgs.push_back(Format(game->txQuest[17], Upper(is_city ? game->txForMayor : game->txForSoltys), loc.name.c_str(), FormatString("targets")));
		}
		break;
	case Progress::Deliver:
		// player told news to mayor
		{
			uint count = 0;
			for(vector<Entry>::iterator it = entries.begin(), end = entries.end(); it != end; ++it)
			{
				if(W.GetCurrentLocationIndex() == it->location)
				{
					it->given = true;
					++count;
				}
				else if(it->given)
					++count;
			}

			Location& loc = *W.GetCurrentLocation();
			cstring msg = Format(game->txQuest[18], LocationHelper::IsCity(loc) ? game->txForMayor : game->txForSoltys, loc.name.c_str());

			if(count == entries.size())
			{
				prog = Progress::Deliver;
				OnUpdate({ msg, Format(game->txQuest[19], GetStartLocationName()) });
			}
			else
				OnUpdate(msg);

			RemoveElementTry(QM.quests_timeout2, static_cast<Quest*>(this));
		}
		break;
	case Progress::Timeout:
		// player failed to spread news in time
		{
			prog = Progress::Timeout;
			state = Quest::Failed;
			((City&)GetStartLocation()).quest_mayor = CityQuestState::Failed;

			OnUpdate(game->txQuest[20]);
		}
		break;
	case Progress::Finished:
		// player spread news to all mayors, end of quest
		{
			prog = Progress::Finished;
			state = Quest::Completed;
			((City&)GetStartLocation()).quest_mayor = CityQuestState::None;
			Team.AddReward(500, 2000);

			OnUpdate(game->txQuest[21]);
		}
		break;
	}
}
コード例 #8
0
FVector FNavigationPath::GetPathFindingStartLocation() const
{
	return SourceActor != NULL ? (SourceActorAsNavAgent != NULL ? SourceActorAsNavAgent->GetNavAgentLocation() : SourceActor->GetActorLocation()) : GetStartLocation();
}
コード例 #9
0
ファイル: Quest.cpp プロジェクト: lcs2/carpg
//=================================================================================================
cstring Quest::GetStartLocationName() const
{
	return GetStartLocation().name.c_str();
}
コード例 #10
0
ファイル: Quest.cpp プロジェクト: lcs2/carpg
//=================================================================================================
cstring Quest_Dungeon::GetTargetLocationDir() const
{
	return GetLocationDirName(GetStartLocation().pos, GetTargetLocation().pos);
}