예제 #1
0
void
MissionSelector::addCampaignGroup(string handle, vector<string> missions)
{
  Campaign* campaign = mHandleToCampaign[handle];
  if(campaign == NULL) return;
  campaign->addGroup(missions);
}
예제 #2
0
void
MissionSelector::show(bool enableClose)
{
  mCloseButton->setEnabled(enableClose);
  
  Mission* currentMission = rMain()->getMission();
  if(ConfigManager::getPlayer()->getHomeBase() == currentMission) {
    mHomeBaseButton->setVisible(false);
  }
  else {
    mHomeBaseButton->setVisible(true);
  }  

  sort(mCampaigns.begin(), mCampaigns.end(), lessCampaign);
  mCampaignList->removeAllItems();  
  for(vector<Campaign*>::const_iterator iCampaign = mCampaigns.begin(); iCampaign != mCampaigns.end(); ++iCampaign) {
    Campaign* campaign = *iCampaign;
    mCampaignList->addItem(campaign->getName());
  }  

  sort(mMissions.begin(), mMissions.end(), lessEntry);
  updateMissionList();
  
  Dialog::show();
}
예제 #3
0
void
CmpCompleteDlg::Show()
{
    FormWindow::Show();

    Campaign* c = Campaign::GetCampaign();

    if (img_title && c) {
        DataLoader*    loader = DataLoader::GetLoader();
        Starshatter*   stars  = Starshatter::GetInstance();
        CombatEvent*   event  = c->GetLastEvent();
        char           img_name[256];

        if (event) {
            strcpy_s(img_name, event->ImageFile());

            if (!strstr(img_name, ".pcx")) {
                strcat_s(img_name, ".pcx");
            }

            if (loader) {
                loader->SetDataPath(c->Path());
                loader->LoadBitmap(img_name, banner);
                loader->SetDataPath(0);

                Rect tgt_rect;
                tgt_rect.w = img_title->Width();
                tgt_rect.h = img_title->Height();

                img_title->SetTargetRect(tgt_rect);
                img_title->SetPicture(banner);
            }
        }
    }
}
void
MsnSelectDlg::OnDel(AWEvent* event)
{
	const char* cname = 0;

	if (cmb_campaigns)
	cname = cmb_campaigns->GetSelectedItem();
	else if (lst_campaigns)
	cname = lst_campaigns->GetSelectedItem();

	Campaign* c = Campaign::SelectCampaign(cname);
	if (!c) return;

	Mission* m = c->GetMission(mission_id);
	if (!m) return;

	ConfirmDlg* confirm = manager->GetConfirmDlg();
	if (confirm) {
		char msg[256];
		sprintf_s(msg, Game::GetText("MsnSelectDlg.are-you-sure").data(), m->Name());
		confirm->SetMessage(msg);
		confirm->SetTitle(Game::GetText("MsnSelectDlg.confirm-delete"));
		confirm->SetParentControl(btn_del);

		manager->ShowConfirmDlg();
	}

	else {
		OnDelConfirm(event);
	}
}
void
MsnSelectDlg::OnEdit(AWEvent* event)
{
	const char* cname = 0;

	if (cmb_campaigns)
	cname = cmb_campaigns->GetSelectedItem();
	else if (lst_campaigns)
	cname = lst_campaigns->GetSelectedItem();

	Campaign* c = Campaign::SelectCampaign(cname);
	if (!c) return;

	Mission*    m     = c->GetMission(mission_id);
	if (!m) return;

	MsnEditDlg* editor = manager->GetMsnEditDlg();

	if (editor) {
		edit_mission = m;

		editor->SetMissionInfo(c->GetMissionInfo(mission_id));
		editor->SetMission(m);
		manager->ShowMsnEditDlg();
	}
}
예제 #6
0
void Functions::getNearestObject(Aurora::NWScript::FunctionContext &ctx) {
	Campaign *campaign = _game->getCampaigns().getCurrentCampaign();
	if (!campaign)
		return;

	DragonAge::Object *target = DragonAge::ObjectContainer::toObject(getParamObject(ctx, 0));
	if (!target)
		return;

	// Bitfield of type(s) to check for
	const uint32 type = ctx.getParams()[1].getInt();
	// We want the nth nearest object
	size_t count = MAX<int32>(ctx.getParams()[2].getInt(), 0);

	if (count == 0)
		return;

	Aurora::NWScript::Variable::Array &result = ctx.getReturn().getArray();

	// TODO: nCheckLiving
	// TODO: nCheckPerceived

	const bool includeSelf = ctx.getParams()[5].getInt() != 0;
	if (includeSelf) {
		result.push_back(boost::make_shared<Aurora::NWScript::Variable>(target));
		count--;
	}

	if (count == 0)
		return;

	Aurora::NWScript::ObjectSearch *search = campaign->findObjects();
	Aurora::NWScript::Object       *object = 0;

	std::list<Object *> objects;
	while ((object = search->next())) {
		// Needs to be a valid object and not the target
		DragonAge::Object *daObject = DragonAge::ObjectContainer::toObject(object);
		if (!daObject || (daObject == target))
			continue;

		// Ignore invalid object types
		const uint32 objectType = (uint32) daObject->getType();
		if (objectType >= kObjectTypeMAX)
			continue;

		if (type & objectType)
			objects.push_back(daObject);
	}

	delete search;

	objects.sort(ObjectDistanceSort(*target));

	for (std::list<Object *>::iterator it = objects.begin(); it != objects.end() && count > 0; ++it, count--)
		result.push_back(boost::make_shared<Aurora::NWScript::Variable>(*it));
}
예제 #7
0
void Functions::getHero(Aurora::NWScript::FunctionContext &ctx) {
	ctx.getReturn() = (Aurora::NWScript::Object *) 0;

	Campaign *campaign = _game->getCampaigns().getCurrentCampaign();
	if (!campaign)
		return;

	ctx.getReturn() = (Aurora::NWScript::Object *) campaign->getPC();
}
void
CombatAction::FailAction()
{
	Campaign* campaign = Campaign::GetCampaign();
	if (campaign)
	time = (int) campaign->GetTime();

	count  = 0;
	status = FAILED;
}
예제 #9
0
void Functions::getArea(Aurora::NWScript::FunctionContext &ctx) {
	ctx.getReturn() = (Aurora::NWScript::Object *) 0;

	const DragonAge::Object *object = DragonAge::ObjectContainer::toObject(getParamObject(ctx, 0));
	if (!object)
		return;

	Campaign *campaign = _game->getCampaigns().getCurrentCampaign();
	if (!campaign)
		return;

	ctx.getReturn() = (Aurora::NWScript::Object *) campaign->getCurrentArea();
}
void
CombatAction::FireAction()
{
	Campaign* campaign = Campaign::GetCampaign();
	if (campaign)
	time = (int) campaign->GetTime();

	if (count >= 1)
	count--;

	if (count < 1)
	status = COMPLETE;
}
void
MsnSelectDlg::OnCampaignSelect(AWEvent* event)
{
	const char* selected_campaign = 0;

	if (cmb_campaigns)
	selected_campaign = cmb_campaigns->GetSelectedItem();
	else if (lst_campaigns)
	selected_campaign = lst_campaigns->GetSelectedItem();

	Campaign* c = Campaign::SelectCampaign(selected_campaign);

	if (c) {
		campaign = c;

		if (cmb_campaigns) {
			cmb_campaigns->ClearItems();

			ListIter<MissionInfo> iter = campaign->GetMissionList();
			while (++iter) {
				cmb_campaigns->AddItem(iter->name);
			}
		}

		else if (lst_missions) {
			lst_missions->ClearItems();

			ListIter<MissionInfo> iter = campaign->GetMissionList();
			while (++iter) {
				lst_missions->AddItem(iter->name);
			}

			lst_missions->ScrollTo(0);
		}

		if (btn_accept)
		btn_accept->SetEnabled(false);

		if (description)
		description->SetText(Game::GetText("MsnSelectDlg.choose"));

		int id = c->GetCampaignId();
		editable = (id >= Campaign::MULTIPLAYER_MISSIONS &&
		id <= Campaign::CUSTOM_MISSIONS);

		if (btn_new)  btn_new->SetEnabled(editable);
		if (btn_edit) btn_edit->SetEnabled(false);
		if (btn_del)  btn_del->SetEnabled(false);
	}
}
예제 #12
0
CampaignMapEntryEditor::CampaignMapEntryEditor(Campaign& campaign, CampaignMapEntry& mapEntry) : entry(mapEntry), campaign(campaign)
{
	StringTable& table=*Toolkit::getStringTable();
	title = new Text(0, 18, ALIGN_FILL, ALIGN_SCREEN_CENTERED, "menu", table.getString("[editing map]"));
	mapsUnlockedBy = new CheckList(10, 80, 150, 300, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", false);
	mapsUnlockedByLabel = new Text(10, 50, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", table.getString("[unlocked by]"));
	nameEditorLabel = new Text(405, 80, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", table.getString("[map name]"));
	nameEditor=new TextInput(420, 105, 180, 25, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", entry.getMapName());
	isUnlockedLabel = new Text(430, 140, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", table.getString("[unlocked at start]"));
	isUnlocked = new OnOffButton(405, 140, 20, 20, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, entry.isUnlocked(), ISLOCKED);
	descriptionEditorLabel = new Text(405, 170, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", table.getString("[map description]"));
	descriptionEditor = new TextArea(420, 195, 180, 225, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "standard", false, entry.getDescription().c_str());
	ok = new TextButton(260, 430, 180, 40, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "menu", table.getString("[ok]"), OK);
	cancel = new TextButton(450, 430, 180, 40, ALIGN_SCREEN_CENTERED, ALIGN_SCREEN_CENTERED, "menu", table.getString("[Cancel]"), CANCEL);

	std::set<std::string> unlockedBy;
	for(unsigned n=0; n<entry.getUnlockedByMaps().size(); ++n)
	{
		unlockedBy.insert(entry.getUnlockedByMaps()[n]);
	}
	for(unsigned n=0; n<campaign.getMapCount(); ++n)
	{
		if(campaign.getMap(n).getMapName() != entry.getMapName())
		{
			if(unlockedBy.find(campaign.getMap(n).getMapName())==unlockedBy.end())
			{
				mapsUnlockedBy->addItem(campaign.getMap(n).getMapName(), false);
			}
			else
			{
				mapsUnlockedBy->addItem(campaign.getMap(n).getMapName(), true);
			}
		}
	}
	addWidget(title);
	addWidget(mapsUnlockedBy);
	addWidget(mapsUnlockedByLabel);
	addWidget(nameEditorLabel);
	addWidget(nameEditor);
	addWidget(isUnlockedLabel);
	addWidget(isUnlocked);
	addWidget(descriptionEditorLabel);
	addWidget(descriptionEditor);
	addWidget(ok);
	addWidget(cancel);
}
void
MsnSelectDlg::OnDelConfirm(AWEvent* event)
{
	const char* cname = 0;

	if (cmb_campaigns)
	cname = cmb_campaigns->GetSelectedItem();
	else if (lst_campaigns)
	cname = lst_campaigns->GetSelectedItem();

	Campaign* c = Campaign::SelectCampaign(cname);
	if (!c) return;

	edit_mission = 0;
	c->DeleteMission(mission_id);
	Show();
}
예제 #14
0
void
CmpLoadDlg::MoveTo(const Rect& r)
{
	FormWindow::MoveTo(r);

	Campaign* campaign = Campaign::GetCampaign();

	if (campaign && img_title && campaign->GetImage(3)) {
		Bitmap* bmp = campaign->GetImage(3);

		Rect tgt_rect;
		tgt_rect.w = img_title->Width();
		tgt_rect.h = img_title->Height();

		img_title->SetTargetRect(tgt_rect);
		img_title->SetPicture(*bmp);
	}
}
예제 #15
0
void
StarServer::UpdateWorld()
{
    long   new_time      = real_time;
    double delta         = new_time - frame_time;
    seconds       = max_frame_length;
    gui_seconds   = delta * 0.001;

    if (frame_time == 0)
    gui_seconds = 0;

    time_comp = 1;

    if (delta < max_frame_length * 1000)
    seconds = delta * 0.001;

    frame_time = new_time;

    Galaxy* galaxy = Galaxy::GetInstance();
    if (galaxy) galaxy->ExecFrame();

    Campaign* campaign = Campaign::GetCampaign();
    if (campaign) campaign->ExecFrame();

    if (paused) {
        if (world)
        world->ExecFrame(0);
    }

    else {
        game_time += (DWORD) (seconds * 1000);

        Drive::StartFrame();

        if (world)
        world->ExecFrame(seconds);
    }

    static DWORD refresh_time = 0;
    if (RealTime() - refresh_time > 1000) {
        refresh_time = RealTime();
        RedrawWindow(hwnd, 0, 0, RDW_ERASE|RDW_INVALIDATE);
    }
}
예제 #16
0
void Functions::getObjectByTag(Aurora::NWScript::FunctionContext &ctx) {
	ctx.getReturn() = (Aurora::NWScript::Object *) 0;

	Campaign *campaign = _game->getCampaigns().getCurrentCampaign();
	if (!campaign)
		return;

	const Common::UString &tag = ctx.getParams()[0].getString();
	if (tag.empty())
		return;

	int nth = ctx.getParams()[1].getInt();

	Aurora::NWScript::ObjectSearch *search = campaign->findObjectsByTag(tag);
	while (nth-- > 0)
		search->next();

	ctx.getReturn() = search->get();
	delete search;
}
예제 #17
0
void Campaigns::loadCampaign(const Campaign &campaign) {
	unload(false);

	try {
		_currentCampaign = getCampaign(campaign.getUID());
		if (!_currentCampaign)
			throw Common::Exception("Campaign does not exist in this context");

		_currentCampaign->load();

	} catch (Common::Exception &e) {
		unload(false);

		e.add("Failed loading campaign \"%s\" (\"%s\")",
		      campaign.getUID().c_str(), campaign.getName().getString().c_str());
		throw e;
	}

	_hasCampaign = true;
}
예제 #18
0
void Functions::UT_getNearestObjectByTag(Aurora::NWScript::FunctionContext &ctx) {
	ctx.getReturn() = (Aurora::NWScript::Object *) 0;

	Campaign *campaign = _game->getCampaigns().getCurrentCampaign();
	if (!campaign)
		return;

	DragonAge::Object *target = DragonAge::ObjectContainer::toObject(getParamObject(ctx, 0));
	if (!target)
		return;

	const Common::UString &tag = ctx.getParams()[1].getString();
	if (tag.empty())
		return;

	const bool includeSelf = ctx.getParams()[2].getInt() != 0;
	if (includeSelf && (target->getTag() == tag)) {
		ctx.getReturn() = (Aurora::NWScript::Object *) target;
		return;
	}

	Aurora::NWScript::ObjectSearch *search = campaign->findObjectsByTag(tag);
	Aurora::NWScript::Object       *object = 0;

	std::list<Object *> objects;
	while ((object = search->next())) {
		// Needs to be a valid object and not the target
		DragonAge::Object *daObject = DragonAge::ObjectContainer::toObject(object);
		if (!daObject || (daObject == target))
			continue;

		objects.push_back(daObject);
	}

	delete search;

	objects.sort(ObjectDistanceSort(*target));

	if (!objects.empty())
		ctx.getReturn() = (Aurora::NWScript::Object *) *objects.begin();
}
예제 #19
0
void CampaignBuilder::setPlayerPos(Campaign& campaign, Vec2 pos, ViewId playerViewId) {
  switch (getPlayerRole()) {
    case PlayerRole::KEEPER:
      if (campaign.playerPos)
        campaign.clearSite(*campaign.playerPos);
      campaign.playerPos = pos;
      campaign.sites[*campaign.playerPos].dweller =
          Campaign::SiteInfo::Dweller(Campaign::KeeperInfo{playerViewId});
      break;
    case PlayerRole:: ADVENTURER:
      campaign.playerPos = pos;
      break;
  }
}
예제 #20
0
void
DebriefDlg::OnClose(AWEvent* event)
{
    Sim* sim = Sim::GetSim();

    sim->CommitMission();
    sim->UnloadMission();

    NetLobby* lobby = NetLobby::GetInstance();
    if (lobby && lobby->IsHost()) {
        lobby->SelectMission(0);
        lobby->ExecFrame();
    }

    Player* player = Player::GetCurrentPlayer();
    if (player && player->ShowAward()) {
        manager->ShowAwardDlg();
    }

    else {
        Starshatter* stars = Starshatter::GetInstance();

        if (stars) {
            Mouse::Show(false);

            Campaign* campaign = Campaign::GetCampaign();
            if (campaign && campaign->GetCampaignId() < Campaign::SINGLE_MISSIONS)
            stars->SetGameMode(Starshatter::CMPN_MODE);
            else
            stars->SetGameMode(Starshatter::MENU_MODE);
        }

        else {
            Game::Panic("DebriefDlg::OnClose() - Game instance not found");
        }
    }
}
예제 #21
0
VillainPlacement CampaignBuilder::getVillainPlacement(const Campaign& campaign, VillainType type) {
  VillainPlacement ret { [&campaign](int x) { return campaign.sites.getBounds().getXRange().contains(x);}, none };
  switch (campaign.getType()) {
    case CampaignType::FREE_PLAY:
      switch (type) {
        case VillainType::LESSER:
          ret.xPredicate = [](int x) { return x >= 5 && x < 12; };
          break;
        case VillainType::MAIN:
          ret.xPredicate = [](int x) { return (x >= 1 && x < 5) || (x >= 12 && x < 16) ; };
          break;
        case VillainType::ALLY:
          if (campaign.getPlayerRole() == PlayerRole::ADVENTURER)
            ret.firstLocation = *considerStaticPlayerPos(campaign);
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
  return ret;
}
void
MsnSelectDlg::OnNew(AWEvent* event)
{
	const char* cname = 0;

	if (cmb_campaigns)
	cname = cmb_campaigns->GetSelectedItem();
	else if (lst_campaigns)
	cname = lst_campaigns->GetSelectedItem();

	Campaign* c = Campaign::SelectCampaign(cname);
	if (!c) return;

	MissionInfo* info = c->CreateNewMission();
	if (!info || !info->mission)
	return;

	mission_id = info->id;

	MsnEditDlg* editor = manager->GetMsnEditDlg();

	if (editor) {
		edit_mission = info->mission;

		editor->SetMissionInfo(info);
		editor->SetMission(info->mission);
		manager->ShowMsnEditDlg();
	}

	MsnEditNavDlg* navdlg = (MsnEditNavDlg*) manager->GetNavDlg();

	if (navdlg) {
		navdlg->SetMission(info->mission);
		navdlg->SetMissionInfo(info);
	}
}
예제 #23
0
void
CmpLoadDlg::Show()
{
	FormWindow::Show();

	Campaign* campaign = Campaign::GetCampaign();

	if (campaign) {
		Bitmap* bmp = campaign->GetImage(3);
		if (img_title && bmp) {
			Rect tgt_rect;
			tgt_rect.w = img_title->Width();
			tgt_rect.h = img_title->Height();

			img_title->SetTargetRect(tgt_rect);
			img_title->SetPicture(*bmp);
		}

		if (lbl_title)
		lbl_title->SetText(campaign->Name());
	}

	show_time = Game::RealTime();
}
bool
CombatAction::IsAvailable() const
{
	CombatAction* pThis = (CombatAction*) this;

	if (rval < 0) {
		pThis->rval = (int) Random(0, 100);

		if (rval > probability)
		pThis->status = SKIPPED;
	}

	if (status != PENDING)
	return false;

	if (min_rank > 0 || max_rank < 100) {
		Player* player = Player::GetCurrentPlayer();

		if (player->Rank() < min_rank || player->Rank() > max_rank)
		return false;
	}

	Campaign* campaign = Campaign::GetCampaign();
	if (campaign) {
		if (campaign->GetTime() < start_after) {
			return false;
		}

		if (campaign->GetTime() > start_before) {
			pThis->status = FAILED; // too late!
			return false;
		}

		// check requirements against actions in current campaign:
		ListIter<CombatActionReq> iter = pThis->requirements;
		while (++iter) {
			CombatActionReq* r  = iter.value();
			bool             ok = false;

			if (r->action > 0) {
				ListIter<CombatAction> action = campaign->GetActions();
				while (++action) {
					CombatAction* a = action.value();

					if (a->Identity() == r->action) {
						if (r->not) {
							if (a->Status() == r->stat)
							return false;
						}
						else {
							if (a->Status() != r->stat)
							return false;
						}
					}
				}
			}

			// group-based requirement
			else if (r->group_type > 0) {
				if (r->c1) {
					CombatGroup* group = r->c1->FindGroup(r->group_type, r->group_id);

					if (group) {
						int test = 0;
						int comp = 0;

						if (r->intel) {
							test = group->IntelLevel();
							comp = r->intel;
						}

						else {
							test = group->CalcValue();
							comp = r->score;
						}

						switch (r->comp) {
						case CombatActionReq::LT:  ok = (test <  comp); break;
						case CombatActionReq::LE:  ok = (test <= comp); break;
						case CombatActionReq::GT:  ok = (test >  comp); break;
						case CombatActionReq::GE:  ok = (test >= comp); break;
						case CombatActionReq::EQ:  ok = (test == comp); break;
						}
					}

					if (!ok)
					return false;
				}
			}

			// score-based requirement
			else {
				int test = 0;

				if (r->comp <= CombatActionReq::EQ) {  // absolute
					if (r->c1) {
						int test = r->c1->Score();

						switch (r->comp) {
						case CombatActionReq::LT:  ok = (test <  r->score); break;
						case CombatActionReq::LE:  ok = (test <= r->score); break;
						case CombatActionReq::GT:  ok = (test >  r->score); break;
						case CombatActionReq::GE:  ok = (test >= r->score); break;
						case CombatActionReq::EQ:  ok = (test == r->score); break;
						}
					}
				}

				else {                                 // relative
					if (r->c1 && r->c2) {
						int test = r->c1->Score() - r->c2->Score();

						switch (r->comp) {
						case CombatActionReq::RLT: ok = (test <  r->score); break;
						case CombatActionReq::RLE: ok = (test <= r->score); break;
						case CombatActionReq::RGT: ok = (test >  r->score); break;
						case CombatActionReq::RGE: ok = (test >= r->score); break;
						case CombatActionReq::REQ: ok = (test == r->score); break;
						}
					}
				}

				if (!ok)
				return false;
			}

			if (delay > 0) {
				pThis->start_after = (int) campaign->GetTime() + delay;
				pThis->delay       = 0;
				return IsAvailable();
			}
		}
	}

	return true;
}
void
MissionEvent::Execute(bool silent)
{
	Starshatter*   stars    = Starshatter::GetInstance();
	HUDView*       hud      = HUDView::GetInstance();
	Sim*           sim      = Sim::GetSim();
	Ship*          player   = sim->GetPlayerShip();
	Ship*          ship     = 0;
	Ship*          src      = 0;
	Ship*          tgt      = 0;
	Element*       elem     = 0;
	int            pan      = 0;
	bool           end_mission = false;

	if (event_ship.length())
	ship = sim->FindShip(event_ship);
	else
	ship = player;

	if (event_source.length())
	src = sim->FindShip(event_source);

	if (event_target.length())
	tgt = sim->FindShip(event_target);

	if (ship)
	elem = ship->GetElement();

	else if (event_ship.length()) {
		elem = sim->FindElement(event_ship);

		if (elem)
		ship = elem->GetShip(1);
	}

	// expire the delay, if any remains
	delay = 0;

	// fire the event action
	switch (event) {
	case MESSAGE:
		if (event_message.length() > 0) {
			if (ship) {
				RadioMessage* msg = new(__FILE__,__LINE__) RadioMessage(ship, src, event_param[0]);
				msg->SetInfo(event_message);
				msg->SetChannel(ship->GetIFF());
				if (tgt)
				msg->AddTarget(tgt);
				RadioTraffic::Transmit(msg);
			}

			else if (elem) {
				RadioMessage* msg = new(__FILE__,__LINE__) RadioMessage(elem, src, event_param[0]);
				msg->SetInfo(event_message);
				msg->SetChannel(elem->GetIFF());
				if (tgt)
				msg->AddTarget(tgt);
				RadioTraffic::Transmit(msg);
			}
		}

		if (event_sound.length() > 0) {
			pan = event_param[0];
		}
		break;

	case OBJECTIVE: 
		if (elem) {
			if (event_param[0]) {
				elem->ClearInstructions();
				elem->ClearObjectives();
			}

			Instruction* obj = new(__FILE__,__LINE__) Instruction(event_param[0], 0);
			obj->SetTarget(event_target);
			elem->AddObjective(obj);

			if (elem->Contains(player)) {
				HUDView* hud = HUDView::GetInstance();

				if (hud)
				hud->ShowHUDInst();
			}
		}
		break;

	case INSTRUCTION:
		if (elem) {
			if (event_param[0])
			elem->ClearInstructions();

			elem->AddInstruction(event_message);

			if (elem->Contains(player) && event_message.length() > 0) {
				HUDView* hud = HUDView::GetInstance();

				if (hud)
				hud->ShowHUDInst();
			}
		}
		break;

	case IFF:
		if (elem) {
			elem->SetIFF(event_param[0]);
		}

		else if (ship) {
			ship->SetIFF(event_param[0]);
		}
		break;

	case DAMAGE:
		if (ship) {
			ship->InflictDamage(event_param[0]);

			if (ship->Integrity() < 1) {
				NetUtil::SendObjKill(ship, 0, NetObjKill::KILL_MISC);
				ship->DeathSpiral();
				Print("    %s Killed By Scripted Event %d (%s)\n", (const char*) ship->Name(), id, FormatGameTime());
			}
		}
		else {
			Print("   EVENT %d: Could not apply damage to ship '%s' (not found).\n", id, (const char*) event_ship);
		}
		break;

	case JUMP:
		if (ship) {
			SimRegion* rgn = sim->FindRegion(event_target);

			if (rgn && ship->GetRegion() != rgn) {
				if (rgn->IsOrbital()) {
					QuantumDrive* quantum_drive = ship->GetQuantumDrive();
					if (quantum_drive) {
						quantum_drive->SetDestination(rgn, Point(0,0,0));
						quantum_drive->Engage(true); // request immediate jump
					}

					else if (ship->IsAirborne()) {
						ship->MakeOrbit();
					}
				}

				else {
					ship->DropOrbit();
				}
			}

		}
		break;

	case HOLD:
		if (elem)
		elem->SetHoldTime(event_param[0]);
		break;

	case SKIP: {
			for (int i = 0; i < event_nparams; i++) {
				int skip_id = event_param[i];

				ListIter<MissionEvent> iter = sim->GetEvents();
				while (++iter) {
					MissionEvent* e = iter.value();
					if (e->EventID() == skip_id) {
						if (e->status != COMPLETE)
						e->status = SKIPPED;
					}
				}
			}
		}
		break;

	case END_MISSION:
		Print("    END MISSION By Scripted Event %d (%s)\n", id, FormatGameTime());
		end_mission = true;
		break;

		//
		// NOTE: CUTSCENE EVENTS DO NOT APPLY IN MULTIPLAYER
		//
	case BEGIN_SCENE:
		Print("    ------------------------------------\n");
		Print("    Begin Cutscene '%s'\n", event_message.data());
		stars->BeginCutscene();
		break;

	case END_SCENE:
		Print("    End Cutscene '%s'\n", event_message.data());
		Print("    ------------------------------------\n");
		stars->EndCutscene();
		break;

	case CAMERA:
		if (stars->InCutscene()) {
			CameraDirector* cam_dir = CameraDirector::GetInstance();

			if (!cam_dir->GetShip())
			cam_dir->SetShip(player);

			switch (event_param[0]) {
			case 1:  
				if (cam_dir->GetMode() != CameraDirector::MODE_COCKPIT)
				cam_dir->SetMode(CameraDirector::MODE_COCKPIT, event_rect.x);
				break;

			case 2:
				if (cam_dir->GetMode() != CameraDirector::MODE_CHASE)
				cam_dir->SetMode(CameraDirector::MODE_CHASE, event_rect.x);
				break;

			case 3:
				if (cam_dir->GetMode() != CameraDirector::MODE_ORBIT)
				cam_dir->SetMode(CameraDirector::MODE_ORBIT, event_rect.x);
				break;

			case 4:
				if (cam_dir->GetMode() != CameraDirector::MODE_TARGET)
				cam_dir->SetMode(CameraDirector::MODE_TARGET, event_rect.x);
				break;
			}

			if (event_target.length()) {
				::Print("Mission Event %d: setting camera target to %s\n", id, (const char*) event_target);
				Ship* s_tgt = 0;
				
				if (event_target.indexOf("body:") < 0)
				s_tgt = sim->FindShip(event_target);

				if (s_tgt) {
					::Print("   found ship %s\n", s_tgt->Name());
					cam_dir->SetViewOrbital(0);

					if (cam_dir->GetViewObject() != s_tgt) {

						if (event_param[0] == 6) {
							s_tgt->DropCam(event_param[1], event_param[2]);
							cam_dir->SetShip(s_tgt);
							cam_dir->SetMode(CameraDirector::MODE_DROP, 0);
						}
						else {
							Ship* cam_ship = cam_dir->GetShip();

							if (cam_ship && cam_ship->IsDropCam()) {
								cam_ship->CompleteTransition();
							}

							if (cam_dir->GetShip() != sim->GetPlayerShip())
							cam_dir->SetShip(sim->GetPlayerShip());
							cam_dir->SetViewObject(s_tgt, true); // immediate, no transition
						}
					}
				}

				else {
					const char* body_name = event_target.data();

					if (!strncmp(body_name, "body:", 5))
					body_name += 5;

					Orbital* orb = sim->FindOrbitalBody(body_name);

					if (orb) {
						::Print("   found body %s\n", orb->Name());
						cam_dir->SetViewOrbital(orb);
					}
				}
			}

			if (event_param[0] == 3) {
				cam_dir->SetOrbitPoint(event_point.x, event_point.y, event_point.z);
			}

			else if (event_param[0] == 5) {
				cam_dir->SetOrbitRates(event_point.x, event_point.y, event_point.z);
			}
		}
		break;

	case VOLUME:
		if (stars->InCutscene()) {
			AudioConfig* audio_cfg = AudioConfig::GetInstance();

			audio_cfg->SetEfxVolume(event_param[0]);
			audio_cfg->SetWrnVolume(event_param[0]);
		}
		break;

	case DISPLAY:
		if (stars->InCutscene()) {
			DisplayView* disp_view = DisplayView::GetInstance();

			if (disp_view) {
				Color color;
				color.Set(event_param[0]);

				if (event_message.length() && event_source.length()) {

					if (event_message.contains('$')) {
						Campaign*      campaign = Campaign::GetCampaign();
						Player*        user     = Player::GetCurrentPlayer();
						CombatGroup*   group    = campaign->GetPlayerGroup();

						if (user) {
							event_message = FormatTextReplace(event_message, "$NAME",  user->Name().data());
							event_message = FormatTextReplace(event_message, "$RANK",  Player::RankName(user->Rank()));
						}

						if (group) {
							event_message = FormatTextReplace(event_message, "$GROUP", group->GetDescription());
						}

						if (event_message.contains("$TIME")) {
							char timestr[32];
							FormatDayTime(timestr, campaign->GetTime(), true);
							event_message = FormatTextReplace(event_message, "$TIME", timestr);
						}
					}

					disp_view->AddText(  event_message,
					FontMgr::Find(event_source),
					color,
					event_rect,
					event_point.y,
					event_point.x,
					event_point.z);

				}

				else if (event_target.length()) {
					DataLoader* loader = DataLoader::GetLoader();

					if (loader) {
						loader->SetDataPath(0);
						loader->LoadBitmap(event_target, image, 0, true);
					}

					if (image.Width() && image.Height())
					disp_view->AddImage( &image,
					color,
					Video::BLEND_ALPHA,
					event_rect,
					event_point.y,
					event_point.x,
					event_point.z);
				}
			}
		}
		break;

	case FIRE_WEAPON:
		if (ship) {
			// fire single weapon:
			if (event_param[0] >= 0) {
				ship->FireWeapon(event_param[0]);
			}

			// fire all weapons:
			else {
				ListIter<WeaponGroup> g_iter = ship->Weapons();
				while (++g_iter) {
					ListIter<Weapon> w_iter = g_iter->GetWeapons();
					while (++w_iter) {
						Weapon* w = w_iter.value();
						w->Fire();
					}
				}
			}
		}
		break;

	default:
		break;
	}

	sim->ProcessEventTrigger(TRIGGER_EVENT, id);

	if (!silent && !sound && event_sound.length()) {
		DataLoader* loader = DataLoader::GetLoader();
		bool        use_fs = loader->IsFileSystemEnabled();
		DWORD       flags  = pan ? Sound::LOCKED|Sound::LOCALIZED : 
		Sound::LOCKED|Sound::AMBIENT;

		loader->UseFileSystem(true);
		loader->SetDataPath("Sounds/");
		loader->LoadSound(event_sound, sound, flags);
		loader->SetDataPath(0);

		if (!sound) {
			loader->SetDataPath("Mods/Sounds/");
			loader->LoadSound(event_sound, sound, flags);
			loader->SetDataPath(0);
		}

		if (!sound) {
			loader->LoadSound(event_sound, sound, flags);
		}

		loader->UseFileSystem(use_fs);

		// fire and forget:
		if (sound) {
			if (sound->GetFlags() & Sound::STREAMED) {
				sound->SetFlags(flags | sound->GetFlags());
				sound->SetVolume(AudioConfig::VoxVolume());
				sound->Play();
			}
			else {
				sound->SetFlags(flags);
				sound->SetVolume(AudioConfig::VoxVolume());
				sound->SetPan(pan);
				sound->SetFilename(event_sound);
				sound->AddToSoundCard();
				sound->Play();
			}
		}
	}

	status = COMPLETE;

	if (end_mission) {
		StarServer*  server = StarServer::GetInstance();

		if (stars) {
			stars->EndMission();
		}

		else if (server) {
			// end mission event uses event_target member
			// to forward server to next mission in the chain:
			if (event_target.length())
			server->SetNextMission(event_target);

			server->SetGameMode(StarServer::MENU_MODE);
		}
	}
}
예제 #26
0
void
QuitView::ExecFrame()
{
    sim = Sim::GetSim();

    if (show_menu) {
        Color::SetFade(1, Color::Black, 0);
        int action = 0;

        if (Mouse::LButton()) {
            mouse_latch = true;
        }
        else if (mouse_latch) {
            mouse_latch = false;

            if (Mouse::X() > xcenter - w2 && Mouse::X() < xcenter + w2) {
                int y0 = ycenter - h2;

                for (int i = 0; i < 4; i++)
                if (Mouse::Y() >= y0 + 75 + i * 30 && Mouse::Y() <= y0 + 105 + i * 30)
                action = i+1;
            }
        }

        for (int i = 1; i <= 4; i++) {
            if (Keyboard::KeyDown('0' + i))
            action = i;
        }

        // was mission long enough to accept?
        if (action == 1 && !CanAccept()) {
            Button::PlaySound(Button::SND_REJECT);
            action = 3;
        }

        // exit and accept:
        if (action == 1) {
            CloseMenu();
            Game::SetTimeCompression(1);

            Starshatter* stars = Starshatter::GetInstance();
            stars->SetGameMode(Starshatter::PLAN_MODE);
        }

        // quit and discard results:
        else if (action == 2) {
            CloseMenu();
            Game::SetTimeCompression(1);

            Starshatter*   stars    = Starshatter::GetInstance();
            Campaign*      campaign = Campaign::GetCampaign();

            // discard mission and events:
            if (sim) sim->UnloadMission();
            else ShipStats::Initialize();

            if (campaign && campaign->GetCampaignId() < Campaign::SINGLE_MISSIONS) {
                campaign->RollbackMission();
                stars->SetGameMode(Starshatter::CMPN_MODE);
            }

            else {
                stars->SetGameMode(Starshatter::MENU_MODE);
            }
        }

        // resume:
        else if (action == 3) {
            CloseMenu();
        }

        // controls:
        else if (action == 4) {
            GameScreen* game_screen = GameScreen::GetInstance();

            if (game_screen)
            game_screen->ShowCtlDlg();
            else
            CloseMenu();
        }
    }
}
예제 #27
0
void Campaigns::changeCampaign(const Campaign &campaign) {
	_newCampaign = campaign.getUID();
}
void
MsnSelectDlg::Show()
{
	FormWindow::Show();
	campaign = Campaign::GetCampaign();

	if (cmb_campaigns) {
		int n = 0;
		cmb_campaigns->ClearItems();
		ListIter<Campaign> iter = Campaign::GetAllCampaigns();
		while (++iter) {
			Campaign* c = iter.value();

			if (c->GetCampaignId() >= Campaign::SINGLE_MISSIONS) {
				cmb_campaigns->AddItem(c->Name());

				if (campaign->GetCampaignId() < Campaign::SINGLE_MISSIONS) {
					campaign = Campaign::SelectCampaign(c->Name());
					cmb_campaigns->SetSelection(n);
				}

				else if (campaign->GetCampaignId() == c->GetCampaignId()) {
					cmb_campaigns->SetSelection(n);
				}

				n++;
			}
		}
	}

	else if (lst_campaigns) {
		int n = 0;
		lst_campaigns->ClearItems();
		ListIter<Campaign> iter = Campaign::GetAllCampaigns();
		while (++iter) {
			Campaign* c = iter.value();

			if (c->GetCampaignId() >= Campaign::SINGLE_MISSIONS) {
				lst_campaigns->AddItem(c->Name());

				if (campaign->GetCampaignId() < Campaign::SINGLE_MISSIONS) {
					campaign = Campaign::SelectCampaign(c->Name());
					lst_campaigns->SetSelected(n);
				}

				else if (campaign->GetCampaignId() == c->GetCampaignId()) {
					lst_campaigns->SetSelected(n);
				}

				n++;
			}
		}
	}

	if (campaign) {
		int id = campaign->GetCampaignId();
		editable = (id >= Campaign::MULTIPLAYER_MISSIONS &&
		id <= Campaign::CUSTOM_MISSIONS);

		if (btn_new)  btn_new->SetEnabled(editable);
		if (btn_edit) btn_edit->SetEnabled(false);
		if (btn_del)  btn_del->SetEnabled(false);
	}

	if (description)
	description->SetText(Game::GetText("MsnSelectDlg.choose"));

	if (lst_missions) {
		lst_missions->ClearItems();

		if (campaign) {
			ListIter<MissionInfo> iter = campaign->GetMissionList();
			while (++iter) {
				MissionInfo* info = iter.value();
				Mission*     m    = info->mission;

				lst_missions->AddItem(info->name);

				if (m && m == edit_mission) {
					lst_missions->SetSelected(lst_missions->NumItems()-1);
				}
			}

			if (selected_mission >= 0 && lst_missions->GetSelCount() == 0) {
				lst_missions->SetSelected(selected_mission);
			}
		}

		OnMissionSelect(0);
		edit_mission = 0;
	}
}