⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bugbots.cpp

📁 BugBots是一个游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				{
					std::cout << "BUGBOT LOCATION MISMATCH!" << endl;
				}
				if(tmp != m_pos)				BotPos.push_back(Pixel(tmp, DistPTP(tmp, m_pos)));			}

			if(BotPos.size())
			{				std::sort(BotPos.begin(), BotPos.end());				m_dest = (BotPos.begin())->Location;
				if(MH.GetBugBotAt(m_dest) != 0)				m_targetbot = (MH.GetBugBotAt(m_dest))->GetMe();
				else std::cout << "RENEGADE: Tried bugbot at " << m_dest.x << ',' << m_dest.y << endl;
			}
			

	    }	}	if(m_flags[HUNGRY] && m_flags[SEARCHING])	{	    Position tmp;	    if(Food.empty() && Corpse.empty())	    {		if((*MH.GetMainBrainIter(m_team)).CanFeed(m_health))		{		    m_dest = (*MH.GetMainBrainIter(m_team)).GetPos();		    m_flags -= SEARCHING;		}		else if((tmp = (*MH.GetMainBrainIter(m_team)).GetTargetPos(m_pos)) != NoPosition)		{		    m_dest = tmp;		    m_flags -= SEARCHING;		}		else		{		    m_dest.Random();		}	    }	}    }}std::vector<Item> BugBot::Radar(){    std::vector<Item> ItemList;    std::list<BugBot>::iterator Bot;    std::list<BugBot>::iterator Corpse;    std::list<Food>::iterator Food;        for(int x = m_pos.x - RadarDist; x <= m_pos.x + RadarDist; x++)    {		for(int y = m_pos.y - RadarDist; y <= m_pos.y + RadarDist; y++)		{			if(DistPTP(m_pos, Position(x,y)) <= float(RadarDist))			{				if((Bot = MH.GetBugBotAt(Position(x, y))) != 0)				{					ItemList.push_back(Item((*Bot).GetMe(), true));				}				if((Corpse = MH.GetCorpseAt(Position(x, y))) != 0)				{					ItemList.push_back(Item((*Corpse).GetMe(), true));				}				if((Food = MH.GetFoodAt(Position(x, y))) != 0)				{					ItemList.push_back(Item((*Food).GetMe(), false));				}			}		}    }    return ItemList;}void BugBot::ReachedTarget(){    if(IsRenegade())    {	return;    }    if(HasItem())    {	if((m_item.bot && !MH.IsOccupiedByCorpse(m_pos)) || (!m_item.bot && !MH.IsOccupiedByFood(m_pos)))	{	    DropItem();	    std::list<MainBrain>::iterator mbit = MH.GetMainBrainIter(m_team);	    	    if(mbit!=0)		m_dest = (*mbit).GetTargetPos(m_pos);

		if(m_dest == NoPosition)
		{
			m_dest.Random();
		}
	}    }    if(IsHungry() || IsStarving())    {	std::list<MainBrain>::iterator mbit = MH.GetMainBrainIter(m_team);		if(mbit!=0)	    (*mbit).Feed(m_me);    }}void BugBot::PrepareForAttack(){    if(MH.IsOccupiedByItem(m_pos))    {	std::list<BugBot>::iterator corpse = MH.GetCorpseAt(m_pos);	std::list<Food>::iterator food = MH.GetFoodAt(m_pos);		if(corpse != 0)	{	    Eat(Item((*corpse).GetMe(),true));	}	if(food != 0)	{	    Eat(Item((*food).GetMe(),false));	}    }    if(HasItem())    {
		Eat(m_item);
		m_item.vnum = -1;    }}bool BugBot::Attack(int bot){

	SoundManager *manager = SoundManager::GetInstance();
	manager->PlaySound(SoundManager::SND_ATTACK);    std::list<BugBot>::iterator botit = MH.GetBugBotIter(bot);    if( botit == 0 )    {	//std::cout << "Attack, bad bot:" << bot << endl;    }    else    {	PrepareForAttack();	(*botit).PrepareForAttack();	if(m_health < (*botit).GetHealth())	{
	//	std::cout << "Other died in attack." << endl;	    Die();	    return false;	}	else	{	    //you win	    (*botit).Die();	   	    return true;	}    }}void BugBot::Eat(Item item){
	if(item.vnum == -1)
	{
		std::cout << "Tried to eat something you didnt have! Why??" << endl;
		return;
	}    if(!item.bot)    {	//food

	SoundManager *manager = SoundManager::GetInstance();
	manager->PlaySound(SoundManager::SND_EAT);		std::list<Food>::iterator foodit = MH.GetFoodIter(item.vnum);				if(foodit==0)		{			return;		}				int clump = (*foodit).GetClump();		MH.SetFoodAt((*foodit).GetPos(),0);						if(clump != -1 && !(*foodit).IsCarried())		{			std::list<Clump>::iterator cit = MH.GetClumpIter(clump);						if(cit!=0)			(*cit).RemoveFood((*foodit).GetMe());		}		m_health += FoodValue;		MH.EraseFood(item.vnum);	}    else    {

	
	SoundManager *manager = SoundManager::GetInstance();
	manager->PlaySound(SoundManager::SND_EAT_BOT);	//if(GlobalBugBotList.count(item.bugbot))	std::list<BugBot>::iterator botit = MH.GetBugBotIter(item.vnum);	

	if(botit==0 || ! botit->IsCorpse())	{	    std::cout << "Eat, bad item vnum (or tried to eat live bot): " << item.vnum << endl;	    return;	}//	std::cout << "Ate corpse: " << item.vnum << endl;	Position pos = (*botit).GetPos();	MH.SetCorpseAt(pos,0);		MH.EraseBugBot(item.vnum);		m_health += CorpseValue;
	if(!m_flags[CANNIBAL])
	{		m_flags += CANNIBAL;
		manager->PlaySound(SoundManager::SND_CANNIBAL);
	}

    } // was bot
    if(m_health > 1000)    {	m_health=1000;    }

	item.vnum = -1;}void BugBot::Die(){
	ticks_dead = 0;

	SoundManager *manager = SoundManager::GetInstance();
	manager->PlaySound(SoundManager::SND_DIE);    if(m_team != -1 )    {	std::list<MainBrain>::iterator i= MH.GetMainBrainIter(m_team);		if(i!=0)	{	    (*i).RemoveBugBot(m_me);	    (*i).ReportCorpse(m_me);	}	    }        m_flags+=CORPSE;        if(HasItem())    {
		cout << GetMe() << " died with item in hand. " << endl;
		if(m_item.bot)
		{
			//we have to drop the corpse in a different square, or else we have two corpses in the same square.
			(MH.GetBugBotIter(m_item.vnum))->SetPos( MH.NoBot(m_pos), true);
			(MH.GetBugBotIter(m_item.vnum))->SetCarried(false);
		//	std::cout << "Dying and dropping a corpse." << endl;
		}
		else DropItem();    }    
	

//	if(m_health > 0)
//		std::cout << GetMe() << " died with health: " << m_health << endl;    MH.SetBugBotAt(m_pos,0);    MH.SetCorpseAt(m_pos,MH.GetBugBotIter(m_me)); //it _should_ be doing this automatically later    } void BugBot::PickUp(Item item){    m_item = item;    if(!item.bot)    {	std::list<Food>::iterator foodit = MH.GetFoodIter(item.vnum);	int clump=(*foodit).GetClump();	if(clump != -1)	{	    (*foodit).CarryClump();	    std::list<Clump>::iterator cit = MH.GetClumpIter(clump);	    	    if(cit != 0)		(*cit).RemoveFood((*foodit).GetMe());	}    }    else    {
		std::list<BugBot>::iterator botit = MH.GetBugBotIter(item.vnum);	
	if(!botit->IsCorpse())
	{
		std::cout << "Picking up alive bot: " << item.vnum << endl;
	}
	if(botit != 0)	{	    (*botit).SetCarried(true);	}	else	{	    std::cout << "Pickup, bad item vnum: " << item.vnum << endl;	}    }}void BugBot::AvoidUpdate(Avoid Param){    Param.Update();    if(Param.IsOver())    {	std::vector<Avoid>::iterator i = std::find(m_avoids.begin(),m_avoids.end(),Param);	m_avoids.erase(i);    }}void BugBot::Update(){    if(!m_flags[CARRIED] && !m_flags[CORPSE])    {	//MH.SetBugBotAt(m_pos, 0); //WOOP	////std::cout << "E BB::Upd" << endl;	CheckRenegade();	for(std::vector<Avoid>::iterator i=m_avoids.begin();i!=m_avoids.end();i++)	{	    AvoidUpdate(*i);	}	m_health--;	CheckHunger();
	if(!m_flags[CORPSE])
	{	CheckFollow();
	}	////std::cout << "done with checkhunger and checkfollow" << endl;
	if(!m_flags[CORPSE])	AreaScan();	// //std::cout << "doing checkdest" << endl;
	if(!m_flags[CORPSE])	CheckDest();	////std::cout << "done with checkdest, doing movetodest" << endl;
	if(!m_flags[CORPSE])	MoveToDest();	////std::cout << "end mtd" << endl;	////std::cout << "L BB Upd" << endl;	//MH.SetBugBotAt(m_pos, MH.GetBugBotIter(m_me));


    }
	if(IsCorpse())ticks_dead++;
	if(!IsCorpse() && MH.GetBugBotAt(m_pos) == 0)
	{
		std::cout << "ERROR - I'm here but the map doesnt show me. " << GetMe() << endl;
	}

	if(IsCorpse() && MH.GetCorpseAt(m_pos) != MH.GetBugBotIter(GetMe()) &&  MH.GetCorpseAt(m_pos) != NULL)
	{
		std::cout << "somebody just walked over me! " << GetMe() << endl;
	}

	if(IsCorpse() && MH.GetCorpseAt(m_pos) == 0)
	{
		std::cout << ticks_dead << " ticks ";
		if(starved)

		std::cout << "ERROR - STARVED CORPSE here but the map doesnt show me. " << GetMe() << endl;
		else std::cout << "ERROR - corpse here but the map doesnt show me." << GetMe() << endl;
	}
}bool BugBot::IsCannibal(){    return m_flags.IsSet(CANNIBAL);}bool BugBot::IsHungry(){    return m_flags.IsSet(HUNGRY);}bool BugBot::IsStarving(){     return m_flags.IsSet(STARVING);}bool BugBot::HasItem(){    return (m_item.vnum != -1);}int BugBot::GetColor(){    return m_color;}Flag BugBot::GetFlags(){    return m_flags;}int BugBot::GetTeam(){    return m_team;}int BugBot::GetHealth(){    return m_health;}Position BugBot::GetPos(){    return m_pos;}bool BugBot::IsCorpse(){    return m_flags[CORPSE];}bool BugBot::IsRenegade(){    return m_flags[RENEGADE];}void BugBot::SetPos(Position pos, bool replace){        if(pos == m_pos) replace=false;        std::list<BugBot>::iterator meit = MH.GetBugBotIter(m_me);    Position tpos = m_pos;    m_pos = pos;    if(!IsCorpse())    {	MH.SetBugBotAt(pos,meit);    }    else    {	MH.SetCorpseAt(pos,meit);    }        if(replace)    {	if(!IsCorpse())	{	    MH.SetBugBotAt(tpos,0);	}	else	{	    MH.SetCorpseAt(tpos,0);	}    }}void BugBot::SetMe(int i){    m_me = i;}int BugBot::GetMe(){    return m_me;}void BugBot::CheckRenegade(){    std::list<MainBrain>::iterator mbit = MH.GetMainBrainIter(m_team);        if(mbit==0) return;    if((*mbit).NumberOfBotsControlled() >= 20)    {	if(1.0 / (float)sqrt((float)(*mbit).NumberOfBotsControlled()-19) + 1>rand())	{	    m_flags+=RENEGADE;
		SoundManager *manager = SoundManager::GetInstance();
		manager->PlaySound(SoundManager::SND_RENEGADE);
	    //GlobalMainBugBotList[m_team].RemoveBot(m_vnum);	}    }}void BugBot::DropItem(){
	if(!HasItem())
	{
		std::cout << "Tried to drop item you didnt have." << endl;
		return;
	}    //if(m_item.bot) ////std::cout << "Bot # " : ////std::cout << "Food # ";    ////std::cout << m_item.vnum << " at " << m_pos.x << ", " << m_pos.y;    if(!m_item.bot)    {	std::list<Food>::iterator foodit = MH.GetFoodIter(m_item.vnum);	if(foodit==0) return;	(*foodit).NoClump();	(*foodit).NoCarryClump();    }    else    {
		std::cout << "Dropping corpse." << m_item.vnum << endl;	std::list<BugBot>::iterator botit = MH.GetBugBotIter(m_item.vnum);	if( botit == 0)	{	    std::cout << "Drop Item, Bad item vnum: " << m_item.vnum << endl;	    return;	}	(*botit).SetCarried(false);    }    m_item.vnum=-1;    m_item.bot=false;}void BugBot::FoodFromGod(int FoodValue ){
	SoundManager *manager = SoundManager::GetInstance();
	manager->PlaySound(SoundManager::SND_FOOD_FROM_GOD);    m_health+=FoodValue;    if(m_health > 1000)    {	m_health=1000;    }}bool BugBot::IsCarried(){    return m_flags[CARRIED];}void BugBot::SetCarried(bool t){    if(t)    {	m_flags+=CARRIED;    }    else    {	m_flags-=CARRIED;    }}void BugBot::SetTeam(int ateam){    m_team = ateam;}void BugBot::RemoveRefOfBot(int bot){    if(m_targetbot == bot)    {	m_targetbot=-1;    }    if(m_item.vnum==bot)    {	m_item.vnum=-1;    }}void BugBot::RemoveRefOfFood(int i){    if(m_item.vnum==i)    {	m_item.vnum=-1;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -