attack order priority

Discussion in 'Feedback' started by FN198, Mar 31, 2013.

  1. Sgt.Security

    Sgt.Security Member

    Messages:
    3,137
    Likes Received:
    140
    Trophy Points:
    0
    This whole idea sounds like a combination of single and multi target I believe.
    Could be nice to try.
     
    Last edited: Apr 5, 2013
  2. Neoony

    Neoony Member

    Messages:
    1,370
    Likes Received:
    106
    Trophy Points:
    0
    This is what I mean:
    Selecting a Group of friendly infantry and using A and creating a box would do this:

    [​IMG]

    But I guess this might put targets spamming back to the game.
     
    Last edited: Apr 5, 2013
  3. Sgt.Security

    Sgt.Security Member

    Messages:
    3,137
    Likes Received:
    140
    Trophy Points:
    0
    Yes, the closest enemy wouldn't always be the same one.

    That's why I was wondering if this is worthy for dev to spend time on.
    Designating a random target might not be drastically inferior than this.
     
  4. Neoony

    Neoony Member

    Messages:
    1,370
    Likes Received:
    106
    Trophy Points:
    0
    yep, thats why we need Jephir to consider this :rolleyes:
    Its for sure not worth doing, if it isnt easy (lets say 1 hour of work max)
     
  5. Candles

    Candles CAPTAIN CANDLES, DUN DUN DUN, DUN DUN DUN DUN.

    Messages:
    4,251
    Likes Received:
    10
    Trophy Points:
    0
    For each player selected, check the distance between the given player and every enemy in the targeting box. Then set the target to the one with the lowest distance.

    Depending on how complicated the code that actually sets the target and the code that selects entities is, this could be either very hard or very easy.
     
  6. Trickster

    Trickster Retired Developer

    Messages:
    16,576
    Likes Received:
    46
    Trophy Points:
    0
    Problem is that you often give targets to more than 1 player. Different targets out of those will be closer to different players. That's where it starts getting a little messy code-side.
     
  7. Neoony

    Neoony Member

    Messages:
    1,370
    Likes Received:
    106
    Trophy Points:
    0
    Thats what I was thinking in that case. Otherwise it could be done on some averages.

    Yeah, Check distance for each friendly player to every enemy target. And then the calculations would have to come and thats why I didnt liked this idea. So I made that one with individual single unit targets where no calculations are necessary.
     
    Last edited: Apr 5, 2013
  8. Jephir

    Jephir ALL GLORY TO THE JEPHIR

    Messages:
    1,409
    Likes Received:
    6
    Trophy Points:
    0
    I'm not an active Empires developer at the moment, but if I'm reading what you guys want correctly, then it's just a matter of getting the distance between each potential target and the ordered unit, and getting the minimum one out of that. If I'm active again in the future I could probably do this, but at the moment I'm taking a bit of a break from Empires development.
     
  9. FN198

    FN198 Member

    Messages:
    2,434
    Likes Received:
    0
    Trophy Points:
    0
    That it wasn't coded this way before 2.4 was released just goes to show how little the devs care about the most definitive role in the game, the commander.
     
  10. Jephir

    Jephir ALL GLORY TO THE JEPHIR

    Messages:
    1,409
    Likes Received:
    6
    Trophy Points:
    0
    Here FN, since it's so easy, if you want this feature, you implement it.
    Code:
    //we're done drawing a selection box, get all entities and see if they're within the box, if yes, then add them to the selection array
    int numentities;
    numentities = ClientEntityList().NumberOfEntities();
    C_BaseEntity *pEnt;
    C_BaseEntityIterator iterator;
    Vector vecMins, vecMaxs, vecOrigin;
    int vOrigin[2];
    bool bSelectNone;
    //bool bFirstIteration = true;
    C_BaseEntity *pTargets[256];
    int numTargets = 0;
    while ((pEnt = iterator.Next()) != NULL ) {
    	bSelectNone = true;
    	if (pEnt->GetTeamNumber() == pSDKPlayer->GetTeamNumber() && !pEnt->IsDormant() && !m_bForceAttack) {
    		if (pEnt->IsPlayer() || pEnt->IsBuilding() || pEnt->IsVehicle() )
    		{
    			pEnt->GetRenderBounds(vecMins, vecMaxs);
    			vecOrigin = pEnt->GetAbsOrigin();
    			//set custom bounds for a player
    			if (pEnt->IsPlayer()) {
    				vecMins.x = -16;
    				vecMins.y = -16;
    				vecMaxs.x = 16;
    				vecMaxs.y = 16;
    				vecOrigin.z += 30;
    			}
    			GetVectorInScreenSpace(vecOrigin, vOrigin[0], vOrigin[1], NULL);
    			if (vOrigin[0] > x[0] && vOrigin[0] < x[1] && vOrigin[1] > y[0] && vOrigin[1] < y[1]) {
    				//if we have other things selected and we're holding shift, we're going to deselect things that were selected and are now in our box
    				if (iSelectionSize > 0 && m_bMultipleSelect) {
    					for (int i=0;i<iSelectionSize;i++) {
    						if (pSelection[i] == pEnt) {
    							//this is the unit we clicked, set them to null and shift down all units above in the array
    							/*pSelection[i] = NULL;
    							for (int i2=i;i2<iSelectionSize-1;i2++) {
    								if (iSelectionSize > i2+1) pSelection[i2] = pSelection[i2 + 1];
    							}
    							pSelection[iSelectionSize-1] = NULL;
    							iSelectionSize--;
    							*/
    							bSelectNone = false;
    							break;
    							//m_iClick = -1;
    							//return;
    						}
    					}
    				}
    				if (bSelectNone) {
    					pSelection[iSelectionSize] = pEnt;
    					iSelectionSize++;
    				}
    			}
    		}
    	}
    	// Select units from the attack box.
    	else if (pEnt->IsAlive() && pEnt->GetTeamNumber() != pSDKPlayer->GetTeamNumber() && !pEnt->IsDormant() && m_bForceAttack && r_mousex > -1 && r_mousey > -1) {
    		if (pEnt->IsPlayer() || pEnt->IsBuilding() || pEnt->IsVehicle() )
    		{
    			// Don't target players in a vehicle
    			if (pEnt->IsPlayer())
    			{
    				auto pPlayer = ToSDKPlayer(pEnt);
    
    				if (pPlayer && pPlayer->IsInAVehicle())
    				{
    					continue;
    				}
    			}
    			pEnt->GetRenderBounds(vecMins, vecMaxs);
    			vecOrigin = pEnt->GetAbsOrigin();
    			//set custom bounds for a player
    			vecMins.x = -16;
    			vecMins.y = -16;
    			vecMaxs.x = 16;
    			vecMaxs.y = 16;
    			vecOrigin.z += 30;
    			GetVectorInScreenSpace(vecOrigin, vOrigin[0], vOrigin[1], NULL);
    			if (vOrigin[0] > x[0] && vOrigin[0] < x[1] && vOrigin[1] > y[0] && vOrigin[1] < y[1])
    			{
    				if (iSelectionSize > 0)
    				{
    					pTargets[numTargets++] = pEnt;
    				}
    			}
    		}
    	}
    }
    //send the list of targets to attack to our selected units
    if (numTargets > 0)
    {
    	char command[256];
    
    	// Prioritize infantry and vehicles before buildings
    	int index = 0;
    	for (int i=0;i<numTargets;i++) // Target infantry first if there are any
    	{
    		if (pTargets[i]->IsPlayer())
    		{
    			index = pTargets[i]->index;
    			break;
    		}
    	}
    	if (!index)
    	{
    		for (int i=0;i<numTargets;i++) // Target vehicles next if there are any
    		{
    			if (pTargets[i]->IsVehicle())
    			{
    				index = pTargets[i]->index;
    				break;
    			}
    		}
    		if (!index) // Target anything
    		{
    			index = pTargets[0]->index;
    		}
    	}
    	Q_snprintf( command,sizeof(command), "orders");
    	int orderSelectionSize = 0;
    	for (int i=0;i<iSelectionSize && orderSelectionSize < 32;i++)
    	{
    		if (pSelection[i].Get() && (pSelection[i].Get()->IsPlayer() || pSelection[i].Get()->IsVehicle()))
    		{
    			orderSelectionSize++;
    			Q_snprintf( command,sizeof(command), "%s %i", command, pSelection[i].Get()->index);
    		}
    	}
    	engine->ServerCmd( const_cast<char *>( command ) );
    	Q_snprintf( command,sizeof(command), "order %i %i", EMP_ORDER_ATTACK_ENTITY, index);
    	engine->ServerCmd( const_cast<char *>( command ) );			
    }
    
     
  11. Trickster

    Trickster Retired Developer

    Messages:
    16,576
    Likes Received:
    46
    Trophy Points:
    0
    And people wonder why we struggle for coders.
     
  12. MOOtant

    MOOtant Member

    Messages:
    4,047
    Likes Received:
    0
    Trophy Points:
    0
    Yes, huge part of the code is just a pile of shit. No one wants to touch it. There's no personal gain whatsoever in improving the situation, no one gets paid for doing so so it just stays as is.

    If anyone were to refactor/clean this up, it'd lead to regressions and general hate from "community".
     
  13. Sgt.Security

    Sgt.Security Member

    Messages:
    3,137
    Likes Received:
    140
    Trophy Points:
    0
    That code doesn't look as shit as I thought it is. :D

    But I can't imagine debugging them, which is the point.

    Also, comm isn't the most definitive guy on the field, in pubber it's the team, in scrim/pug it's the battle commander and squad leaders.
     
    Last edited: Apr 6, 2013
  14. MOOtant

    MOOtant Member

    Messages:
    4,047
    Likes Received:
    0
    Trophy Points:
    0
    Because you saw 1% of it.
     
  15. flasche

    flasche Member Staff Member Moderator

    Messages:
    13,299
    Likes Received:
    168
    Trophy Points:
    0
    is the increased runtime for iterating over the array and comparing the the player->target distance to the last closest player->target distance in compairison to just picking the first occurance of a player as index and break - which is quite a lot less - bearable? targets will get issued often and cpu is already busy doing a lot of stuff in empires isnt it?

    i dont mean to say the idea is bad - its not bad at all, more like the contrary - i just wonder if its good to do it.

    edit:
    ohohoho tarp - the above code ofc only is for all players on the team, so if this should give individual targets you would need to iterate over all the players on your team aswell. thats not only a lot more, that a whole lot more then it is now. but to avoid that you could take the center of mass of a convex shape - or even just the center of a AABB - containing all your selected players and compair to this instead. it wouldnt be perfect either but at least somewhat predictable for the commander aka "just dont issue the whole map as targets for everyone and you should be set".

    edit2:
    i should think before i post, the above ofc would still require you to look at each player selected on your team too or how would you get the shape for the center. so its no shortcut - compairing all selected players with all selected enemy players simply wont get even close to "get first occurance of player in array and issue to everyone" - in the worst case youd have to go through the loop 1024 times while atm its only 32 times if you only consider players - if you add other entities like vehicles and buildings it could get way more too (n*m where n is players who get targets and m is possible targeted entities). imagine 32 players in a turret farm and some empty vehicles - you could maybe reach 60entites*32players and we are close to 2000 iterations ...
     
    Last edited: Apr 6, 2013
  16. MOOtant

    MOOtant Member

    Messages:
    4,047
    Likes Received:
    0
    Trophy Points:
    0
    It's not the point, it's the amount and copy & paste programming. Refactoring this is tedious and it's easy to make errors when doing so. There are 10000+ lines like that.
     
  17. flasche

    flasche Member Staff Member Moderator

    Messages:
    13,299
    Likes Received:
    168
    Trophy Points:
    0
    so where is the followup project? :sadface:
     
  18. Neoony

    Neoony Member

    Messages:
    1,370
    Likes Received:
    106
    Trophy Points:
    0
    Why are u even suggesting an idea when u are punching devs to the face...
    They can just not care at all, they are doing service to you and its not like they are payed for it..
    All they recieve for their hard work is more bitching and thats why this game is short on devs...
    - respect FN :pathetic: Iam disappointed.
     
    Last edited: Apr 6, 2013
  19. FN198

    FN198 Member

    Messages:
    2,434
    Likes Received:
    0
    Trophy Points:
    0
    come on man, you just called me out on a friday night.

    Code:
    //send the list of targets to attack to our selected units
    if (numTargets > 0)
    {
    	char command[256];
    
    	// Assign the closest target to the selected units
    	int index = 0;
    	vec_t minDistance = pTargets[0]->DisToSqr(pSelection[0]);
    	for (int i=0;i<numTargets;i++)
    	{
    		for (int j=0;j<iSelectionSize;j++)
    		{
    			if (pTargets[i]->DisToSqr(pSelection[j]) < minDistance)
    			{
    				minDistance = pTargets[i]->DisToSqr(pSelection[j]);
    				index = pTargets[i]->index;
    			}
    		}
    
    	}
    	Q_snprintf( command,sizeof(command), "orders");
    	int orderSelectionSize = 0;
    	for (int i=0;i<iSelectionSize && orderSelectionSize < 32;i++)
    	{
    		if (pSelection[i].Get() && (pSelection[i].Get()->IsPlayer() || pSelection[i].Get()->IsVehicle()))
    		{
    			orderSelectionSize++;
    			Q_snprintf( command,sizeof(command), "%s %i", command, pSelection[i].Get()->index);
    		}
    	}
    	engine->ServerCmd( const_cast<char *>( command ) );
    	Q_snprintf( command,sizeof(command), "order %i %i", EMP_ORDER_ATTACK_ENTITY, index);
    	engine->ServerCmd( const_cast<char *>( command ) );
    }
    go easy on me guys this is my first time coding
     
    Last edited: Apr 6, 2013
  20. ViroMan

    ViroMan Black Hole (*sniff*) Bully

    Messages:
    8,382
    Likes Received:
    4
    Trophy Points:
    0
    just a glance over but, now you can't target buildings?
     

Share This Page