void BulletinItemOnClick(struct BulletinItem* _Item, lua_State* _State, struct BigGuy* _Selector) { MissionCall(_State, CreateMissionFrame(_Item->Owner, _Selector, _Item->SuccMission)); }
void MissionCall(lua_State* _State, const struct Mission* _Mission, struct BigGuy* _Owner, struct BigGuy* _From) { struct MissionFrame* _Frame= NULL; const char* _NewDesc = NULL; if(_Mission == NULL) return; _Frame = CreateMissionFrame(_From, _Owner, _Mission); _NewDesc = _Mission->Description; if(g_GameWorld.Player == _Owner) { if(_Mission->TextFormatSz > 0) { //Breaks when MissionFormatText is run on a coroutine other than the main coroutine. //because the rule used points to the main coroutine's lua_State. _NewDesc = MissionFormatText(_Mission->Description, _Mission->TextFormat, _Mission->TextFormatSz, _Frame); /* if(_SizeOf == 0) { Log(ELOG_WARNING, "Mission %s failed: MissionFormatText failed to format text.", _Mission->Name); return; } */ } if(_Mission->OnTrigger != 0) { CallMissionAction(_State, _Mission->OnTrigger, _Frame); } if((_Mission->Flags & MISSION_FNOMENU) == MISSION_FNOMENU) return; lua_settop(_State, 0); lua_pushstring(_State, "MissionMenu"); lua_createtable(_State, 0, 3); lua_pushstring(_State, "Mission"); LuaConstCtor(_State, _Mission, LOBJ_MISSION); lua_rawset(_State, -3); lua_pushstring(_State, "BigGuy"); LuaCtor(_State, _Owner, LOBJ_BIGGUY); lua_rawset(_State, -3); lua_pushstring(_State, "Data"); lua_pushlightuserdata(_State, _Frame); lua_rawset(_State, -3); lua_pushstring(_State, "Description"); lua_pushstring(_State, _NewDesc); lua_rawset(_State, -3); lua_pushinteger(_State, 512); lua_pushinteger(_State, 512); LuaCreateWindow(_State); if(CoRunning() != 0) { g_PlayerMisCall = CoRunning(); CoYield(); } } else { int _BestIndex = -1; //float _BestUtility = -1.0; //float _Utility = 0.0; if(_Mission->OnTrigger != 0) { CallMissionCond(_State, _Mission->OnTrigger, _Frame); } if((_Mission->Flags & MISSION_FNOMENU) == MISSION_FNOMENU) return; /*for(int i = 0; i < _Mission->OptionCt; ++i) { if(RuleEval(_Mission->Options[i].Condition) == 0) continue; _Utility = RuleEval(_Mission->Options[i].Utility); if(_Utility > _BestUtility) { _BestIndex = i; _BestUtility = _Utility; } }*/ _BestIndex = 0; _Frame->IsOptSel = 1; CallMissionAction(_State, _Mission->Options[_BestIndex].Action, _Frame); MissionFrameClear(_Frame); } }