Esempio n. 1
0
int BrigadeClass::CheckTactic (int tid)
	{
	Objective	o;

	if (tid < 1)
		return 0;
	if (haveWeaps < 0)
		{
		FalconEntity	*e;
		GridIndex		x,y,dx,dy;

		e = GetTarget();
		if (Engaged() && !e)
			SetEngaged(0);
		if (GetUnitSupply() > 20)
			haveWeaps = 1;
		else
			haveWeaps = 0;
		GetLocation(&x,&y);
		o = GetUnitObjective();
		ourObjOwner = 0;
		if (o && o->GetTeam() == GetTeam())
			ourObjOwner = 1;
		if (o)
			o->GetLocation(&dx,&dy);
		else
			GetUnitDestination(&dx,&dy);
		ourObjDist = FloatToInt32(Distance(x,y,dx,dy));
		}
	if (!CheckUnitType(tid, GetDomain(), GetType()))
		return 0;
	if (!CheckTeam(tid,GetTeam()))
		return 0;
	if (!CheckEngaged(tid,Engaged()))
		return 0;
	if (!CheckCombat(tid,Combat()))
		return 0;
	if (!CheckLosses(tid,Losses()))
		return 0;
	if (!CheckRetreating(tid,Retreating()))
		return 0;
	if (!CheckAction(tid,GetUnitOrders()))
		return 0;
	if (!CheckOwned(tid,ourObjOwner))
		return 0;
	if (TeamInfo[GetTeam()]->GetGroundAction()->actionType != GACTION_OFFENSIVE && !CheckRole(tid,0))
		return 0;
	if (!CheckRange(tid,ourObjDist))
		return 0;
//	if (!CheckDistToFront(tid,ourFrontDist))
//		return 0;
	if (!CheckStatus(tid,Broken()))
		return 0;
//	if (!CheckOdds(tid,odds))
//		return 0;
	return GetTacticPriority(tid);
	}
Esempio n. 2
0
int GroundTaskingManagerClass::AssignUnits (int orders, int mode)
{
	GODNode			curo,nexto;
	USNode			curu,nextu;
	int				ucnt=0,ocnt=0,sortBy = GODN_SORT_BY_PRIORITY;

#ifdef KEV_GDEBUG
	ulong	time,newtime;
	time = GetTickCount();
#endif

	if (!objList[orders] || !canidateList[orders])
		return 0;

	// Special case for reserve orders - 
	// We're only going to reorder the unit farthest from our primary objective
	if (orders == GORD_RESERVE)		
	{
		GridIndex		x,y,px=512,py=512;
		float			ds,bestds=FLT_MAX;
		USNode			bestn=NULL;
		Objective		po = (Objective) vuDatabase->Find(TeamInfo[owner]->GetGroundAction()->actionObjective);

		if (po)
			po->GetLocation(&px,&py);
		nextu = canidateList[orders];
		while (nextu)
		{
			curu = nextu;
			nextu = curu->next;
			curu->unit->GetLocation(&x,&y);
			ds = (float) DistSqu(x,y,px,py);
			if (ds < bestds)
			{
				bestds = ds;
				if (bestn)
					canidateList[orders] = canidateList[orders]->Remove(curu);
				bestn = curu;
			}
			else
				canidateList[orders] = canidateList[orders]->Remove(curu);
		}
	}

	// Maintain canidate list
	nextu = canidateList[orders];
	while (nextu)
	{
		curu = nextu;
		nextu = curu->next;
		if (curu->unit->Assigned())
			canidateList[orders] = canidateList[orders]->Remove(curu);
		else
			ucnt++;
	}

	// Set up our lists
	nexto = objList[orders];
	while (nexto)
	{
		curo = nexto;
		nexto = curo->next;

		if (orders == GORD_REPAIR) {
			// RV - Biker - Only repair ABs if they are used by some squadron
			if (curo->obj->GetType() == TYPE_AIRBASE || curo->obj->GetType() == TYPE_AIRSTRIP) {
				ATMAirbaseClass* atmbase = TeamInfo[curo->obj->GetTeam()]->atm->FindATMAirbase (curo->obj->Id());
				
				//Biker - That does not work???
				if (atmbase && atmbase->usage < 1) {
					continue;
				}
			}

			GridIndex ox = 0, oy = 0;
			curo->obj->GetLocation(&ox, &oy);
			float dist = DistanceToFront(ox,oy);

			// RV - Biker - Do not repair object near front only if it's a bridge
			if (curo->obj->Type() !=  TYPE_BRIDGE && (curo->obj->IsFrontline() || curo->obj->IsSecondline() || curo->obj->IsThirdline() || dist < 15.0f)) {
				continue;
			}
		}

		if (ocnt <= ucnt)
		{
			// Only take one objective per available unit (highest priority first)
			curu = canidateList[orders];
			while (curu)
			{
				curo->InsertUnit(curu->unit, curu->score, ScoreUnitFast(curu,curo,orders,mode));
				curu = curu->next;
			}
			if (curo->unit_options > 0)
				ocnt++;
			else
				objList[orders] = objList[orders]->Remove(curo);
		}
		else
			objList[orders] = objList[orders]->Remove(curo);
	}

	// Assign each objective
	while (objList[orders]) // && canidateList[orders])
	{
		curo = objList[orders] = objList[orders]->Sort(GODN_SORT_BY_OPTIONS);
		if (curo)
			AssignObjective(curo, orders, mode);
	}

	if (canidateList[orders])
		canidateList[orders] = canidateList[orders]->Purge();

#ifdef KEV_GDEBUG
	newtime = GetTickCount();
	Time[orders] = newtime - time;
#endif

	return 1;
}
Esempio n. 3
0
void GroundTaskingManagerClass::DoCalculations(void)
{
	Objective		o;
	int				score,fs,es,i;
	float			d;
	Team			t;
	GridIndex		x,y;
	POData			pd;

	// Don't do this if we're not active, or not owned by this machine
	if (!(TeamInfo[owner]->flags & TEAM_ACTIVE) || !IsLocal())
		return;

	topPriority = 0;
	VuListIterator	poit(POList);
	o = GetFirstObjective(&poit);
	while (o != NULL)
	{
		// Get score for proximity to front
		o->GetLocation(&x,&y);
		d = DistanceToFront(x,y);
		fs = FloatToInt32((200.0F - d) * 0.2F);

		t = o->GetTeam();
		pd = GetPOData(o);
		es = 0;
		// Get score for enemy strength
		if (d < 100.0F)
		{
			for (i=1; i<NUM_TEAMS; i++)
			{
				if (GetRoE(owner,i,ROE_GROUND_FIRE))
					es += pd->ground_assigned[i]/50;	// 1 assignment pt = 1 vehicle, so 1 enemy strength pt per 50 vehs..
			}
			if (es > 30)
				es = 30;								// Cap enemy strength after 1500 vehicles
			if (owner != t)
				es = -es + (rand()%5) - 2;
		}

		score = fs + es + (rand()%5);
		if (o->GetObjectivePriority() > 95)
			score += 50;
		if (o->GetObjectivePriority() > 90)
			score += 20;
		else
			score += o->GetObjectivePriority() - 80;

		//		os = (o->GetObjectivePriority()-80)*3;
		//		score = os + fs + es + (rand()%5);

		if (score < 0)
			score = 0;
		if (score > 100)
			score = 100;
		// Minimum of 1 priority if it's owned by us.
		if (!score && t == owner)
			score = 1;

		// KCK: AI's air and ground priorities are identical for now
		if (!(pd->flags & GTMOBJ_SCRIPTED_PRIORITY))
		{
			pd->ground_priority[owner] = score;
			pd->air_priority[owner] = score;
			// KCK: player_priority only used now if it's >= 0
			//			if (!(pd->flags & GTMOBJ_PLAYER_SET_PRIORITY))
			//				pd->player_priority[owner] = pd->air_priority[owner];
		}

		if (!GetRoE(owner,t,ROE_GROUND_CAPTURE) && owner != t)
			pd->ground_priority[owner] = 0;
		if (!GetRoE(owner,t,ROE_AIR_ATTACK) && owner != t)
			pd->air_priority[owner] = 0;

		if (score > topPriority)
		{
			topPriority = score;
			priorityObj = o->GetCampID();
		}
		o = GetNextObjective(&poit);
	}
}