Exemple #1
0
/**
	@brief	BUS에 들어 있는 LOAD를 표시한다.

	@author BHK	

	@date 2009-05-27 오후 6:54:18	

	@param	

	@return		
*/
int CLoadListDlg::DisplayLoadList(const string& rBusID , const bool& bDisplayOnlySelectedLoad)
{
	CELoadDocData& docData = CELoadDocData::GetInstance();
	CBusItem* pBusItem = docData.FindBusItemByName(rBusID);
	if(pBusItem && m_pGeneratorItem)
	{
		m_wndLoadListCtrl.DeleteAllItems();
		
		vector<string> LoadItemEntry;
		CItemSelectionSet SelectionSet;
		docData.GetLoadItemSetInBus(SelectionSet , rBusID);
		for(int i = 0;i < SelectionSet.GetItemCount();++i)
		{
			CLoadItem* pLoadItem = static_cast<CLoadItem*>(SelectionSet.GetItemAt(i));
			LoadItemEntry.push_back(pLoadItem->GetName());
		}
		if(bDisplayOnlySelectedLoad)
		{
			const string& rSelectedLoadList = m_pGeneratorItem->prop()->GetValue(_T("General") , _T("Selected Load List"));
			if(!rSelectedLoadList.empty())
			{
				CTokenizer<CIsComma>::Tokenize(LoadItemEntry , rSelectedLoadList , CIsComma());
			}
		}

		CString rValue;
		for(int i = 0;i < SelectionSet.GetItemCount();++i)
		{
			const string rLoadID = SelectionSet.GetItemAt(i)->GetName();
			CLoadItem* pLoadItem = docData.FindLoadItemByName(rLoadID);
			if(pLoadItem)
			{
				const int nItem = m_wndLoadListCtrl.InsertItem(i , rLoadID.c_str());
				if(-1 != nItem)
				{
					const string& rLoadCategory = pLoadItem->prop()->GetValue(_T("Type") , _T("Load Category"));
					m_wndLoadListCtrl.SetItemText(nItem , 1 , rLoadCategory.c_str());

					const string& rRatingCapacity = pLoadItem->prop()->GetValue(_T("Rating") , _T("Rating Capacity"));
					m_wndLoadListCtrl.SetItemText(nItem , 2 , rRatingCapacity.c_str());
					const string& rBHP = pLoadItem->prop()->GetValue(_T("Load") , _T("BHP <1>"));
					m_wndLoadListCtrl.SetItemText(nItem , 3 , rBHP.c_str());
					
					vector<string>::iterator where = find(LoadItemEntry.begin() , LoadItemEntry.end() , rLoadID);
					m_wndLoadListCtrl.SetCheck(nItem , (where != LoadItemEntry.end()));

					rValue += CString(rLoadID.c_str()) + _T(",");
				}
			}
		}
		if(_T(",") == rValue.Right(1)) rValue = rValue.Left(rValue.GetLength() - 1);
		m_pGeneratorItem->prop()->SetValue(_T("General") , _T("Selected Load List") , rValue.operator LPCSTR());
	}

	return 0;
}
	bool CUnit::LoadBehaviours(){
		string d = G->Get_mod_tdf()->SGetValueDef("auto","AI\\behaviours\\"+utd->GetName());

		vector<string> v;
		CTokenizer<CIsComma>::Tokenize(v, d, CIsComma());

		if(!v.empty()){
			for(vector<string>::iterator vi = v.begin(); vi != v.end(); ++vi){

				string s = *vi;

				trim(s);
				tolowercase(s);

				if(s == "none"){
					return true;
				} else if(s == "metalmaker"){
					CMetalMakerBehaviour* m = new CMetalMakerBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(m);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "attacker"){
					CAttackBehaviour* a = new CAttackBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(a);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "dgun"){
					CDGunBehaviour* a = new CDGunBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(a);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "retreat"){
					CRetreatBehaviour* a = new CRetreatBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(a);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "kamikaze"){
					CKamikazeBehaviour* a = new CKamikazeBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(a);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "staticdefence"){
					CStaticDefenceBehaviour* a = new CStaticDefenceBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(a);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "movefailreclaim"){
					CMoveFailReclaimBehaviour* a = new CMoveFailReclaimBehaviour(G, GetID());
					boost::shared_ptr<IBehaviour> t(a);
					
					behaviours.push_back(t);
					t->Init();

					G->RegisterMessageHandler(t);
				} else if(s == "auto"){
					// we have to decide what this units behaviours should be automatically
					// check each type of unit for pre-requisites and then assign the behaviour
					// accordingly.

					if(utd->IsAttacker()){
						CAttackBehaviour* a = new CAttackBehaviour(G, GetID());
						boost::shared_ptr<IBehaviour> t(a);

						behaviours.push_back(t);
						t->Init();

						G->RegisterMessageHandler(t);
					}

					if(utd->IsMetalMaker()||(utd->IsMex() && utd->GetUnitDef()->onoffable ) ){
						CMetalMakerBehaviour* m = new CMetalMakerBehaviour(G, GetID());
						boost::shared_ptr<IBehaviour> t(m);

						behaviours.push_back(t);
						t->Init();

						G->RegisterMessageHandler(t);
						
					}
					
					if(utd->CanDGun()){
						CDGunBehaviour* a = new CDGunBehaviour(G, GetID());
						boost::shared_ptr<IBehaviour> t(a);
						
						behaviours.push_back(t);
						t->Init();

						G->RegisterMessageHandler(t);
					}

					

					if(utd->GetUnitDef()->canmove || utd->GetUnitDef()->canfly){
						CRetreatBehaviour* a = new CRetreatBehaviour(G, GetID());
						boost::shared_ptr<IBehaviour> t(a);
						
						behaviours.push_back(t);
						t->Init();

						G->RegisterMessageHandler(t);

						if(utd->GetUnitDef()->canReclaim){
							CMoveFailReclaimBehaviour* a = new CMoveFailReclaimBehaviour(G, GetID());
							boost::shared_ptr<IBehaviour> t(a);
							
							behaviours.push_back(t);
							t->Init();

							G->RegisterMessageHandler(t);
						}

					}else{
						/* this unit can't move, if it can fire a weapon though give it
						   the static defence behaviour*/

						if(utd->GetUnitDef()->weapons.empty()==false){
							CStaticDefenceBehaviour* a = new CStaticDefenceBehaviour(G, GetID());
							boost::shared_ptr<IBehaviour> t(a);
							
							behaviours.push_back(t);
							t->Init();

							G->RegisterMessageHandler(t);
						}
					}

					/*At the moment I can't think of a viable way of testing for the kamakaze
					  behaviour. It's usually a specialized behaviour though so a modder is
					  likely to mark it out in toolkit as a kamikaze unit
					*/

				}
			}
		}
		return true;
	}
	bool CConfigTaskManager::LoadTaskList(){
		NLOG("CConfigTaskManager::LoadTaskList");

		CUnit* u = G->unit_array[unit];

		CUnitTypeData* utd = u->GetUnitDataType();

		vector<string> vl;
		string sl;
		if(G->Cached->cheating){
			sl= G->Get_mod_tdf()->SGetValueMSG(string("TASKLISTS\\CHEAT\\")+utd->GetName());
		}else{
			sl = G->Get_mod_tdf()->SGetValueMSG(string("TASKLISTS\\NORMAL\\")+utd->GetName());
		}

		tolowercase(sl);
		trim(sl);
		string us = utd->GetName();
		if(sl != string("")){
			CTokenizer<CIsComma>::Tokenize(vl, sl, CIsComma());
			if(vl.empty() == false){
				int randnum = G->mrand()%vl.size();
				us = vl.at(min(randnum,max(int(vl.size()-1),1)));
			}
		}

		string s = G->Get_mod_tdf()->SGetValueMSG(string("TASKLISTS\\LISTS\\")+us);

		if(s.empty()){
			G->L.print(" error loading tasklist for unit :: \"" + us + "\" :: buffer empty, most likely because of an empty list");
			nolist=true;
			return false;
		}

		tolowercase(s);
		trim(s);

		vector<string> v;

		CTokenizer<CIsComma>::Tokenize(v, s, CIsComma());

		if(v.empty() == false){
			G->L.print("loading contents of  tasklist :: " + us + " :: filling tasklist with #" + to_string(v.size()) + " items");
			bool polate=false;
			bool polation = G->info->rule_extreme_interpolate;
			btype bt = G->Manufacturer->GetTaskType(G->Get_mod_tdf()->SGetValueDef("b_na","AI\\interpolate_tag"));

			if(utd->IsFactory()){
				polation = false;
			}

			if(bt == B_NA){
				polation = false;
			}


			// TASKS LOADING
			
			for(std::vector<string>::iterator vi = v.begin(); vi != v.end(); ++vi){
				if(polation){
					if(polate){
						boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),bt));
						tasks.push_back(t);
					}
					polate = !polate;
				}
				std::string q = *vi;

				trim(q);
				tolowercase(q);

				CUnitTypeData* b = G->UnitDefLoader->GetUnitTypeDataByName(q);
				if(b != 0){
					boost::shared_ptr<IModule> t(new CUnitConstructionTask(G,u->GetID(),utd,b));
					tasks.push_back(t);
				}else if(q == string("")){
					continue;
				}else if(q == string("b_na")){
					continue;
				} else if(q == string("no_rule_interpolation")){
					polation=false;
				} else if(q == string("rule_interpolate")){
					polation=true;
				}else if(q == string("base_pos")){
					G->Map->base_positions.push_back(G->GetUnitPos(u->GetID()));
				} else if(q == string("gaia")){
					G->info->gaia = true;
				} else if(q == string("not_gaia")){
					G->info->gaia = false;
				} else if(q == string("switch_gaia")){
					G->info->gaia = !G->info->gaia;
				} else if(q == string("b_factory")){
					boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_FACTORY));
					tasks.push_back(t);
				} else if(q == string("b_power")){
					boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_POWER));
					tasks.push_back(t);
				} else if(q == string("b_defence")){
					boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_DEFENCE));
					tasks.push_back(t);
				}  else if(q == string("b_mex")){
					boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),B_MEX));
					tasks.push_back(t);
				} else{
					btype x = G->Manufacturer->GetTaskType(q);
					if( x != B_NA){
						boost::shared_ptr<IModule> t(new CKeywordConstructionTask(G,u->GetID(),x));
						tasks.push_back(t);
					}else{
						G->L.print("error :: a value :: " + *vi +" :: was parsed in :: "+us + " :: this does not have a valid UnitDef according to the engine, and is not a Task keyword such as repair or b_mex");
					}
				}

			}
			if(utd->GetUnitDef()->isCommander){
				G->Map->basepos = G->GetUnitPos(u->GetID());
			}

			G->L.print("loaded contents of  tasklist :: " + us + " :: loaded tasklist at " + to_string(tasks.size()) + " items");
			return !tasks.empty();
		} else{
			G->L.print(" error loading contents of  tasklist :: " + us + " :: buffer empty, most likely because of an empty tasklist");
			return false;
		}
	}