2025-11-30 07:18 CET

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000194Spring engineGeneralpublic2006-06-12 23:36
ReporterILMTitan 
Assigned To 
PrioritynormalSeveritytweakReproducibilityN/A
StatusclosedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000194: Ctr-Shift surround queued buildings
DescriptionThis patch allows for Ctr-Shift to surround buildings that have been queued, and prevents Ctr-Shift from canceling buildings in queue.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon surroundChanges.patch (7,783 bytes) 2006-06-09 00:35 -
    Index: rts/Game/UI/GuiHandler.cpp
    ===================================================================
    --- rts/Game/UI/GuiHandler.cpp	(revision 1451)
    +++ rts/Game/UI/GuiHandler.cpp	(working copy)
    @@ -32,6 +32,7 @@
     #include "SDL_keysym.h"
     #include "SDL_mouse.h"
     #include "mmgr.h"
    +#include "Sim/Units/CommandAI/CommandAI.h"
     
     //////////////////////////////////////////////////////////////////////
     // Construction/Destruction
    @@ -1304,9 +1305,31 @@
     	CUnit* unit=0;
     	float dist2=helper->GuiTraceRay(camera->pos,mouse->dir,gu->viewRange*1.4,unit,20,true);
     
    -	if(unit && keys[SDLK_LSHIFT] && keys[SDLK_LCTRL]){		//circle build around building
    -		UnitDef* unitdef2=unit->unitDef;
    -		float3 pos2=unit->pos;
    +	UnitDef* unitdef2=0;
    +	float3 buildPos;
    +	if(unit){
    +		unitdef2=unit->unitDef;
    +		buildPos = unit->pos;
    +	} else if(keys[SDLK_LSHIFT] && keys[SDLK_LCTRL]){
    +		Command c = uh->GetBuildCommand(camera->pos,mouse->dir);
    +		if(c.id < 0){
    +			unitdef2=unitDefHandler->GetUnitByID(-c.id);
    +			buildPos.x = c.params[0];
    +			buildPos.y = c.params[1];
    +			buildPos.z = c.params[2];
    +		}
    +	}
    +
    +
    +
    +	if(unitdef2 && keys[SDLK_LSHIFT] && keys[SDLK_LCTRL]){		//circle build around building
    +		Command c;
    +		c.id = -unitdef->id;
    +		c.params.push_back(0);
    +		c.params.push_back(0);
    +		c.params.push_back(0);
    +
    +		float3 pos2 = buildPos;
     		pos2=helper->Pos2BuildPos(pos2,unitdef2);
     		start=pos2;
     		end=pos2;
    @@ -1321,7 +1344,19 @@
     			p2.x+=(unitdef->xsize/2)*SQUARE_SIZE;
     			p2.z-=(unitdef->ysize/2)*SQUARE_SIZE;
     			p2=helper->Pos2BuildPos(p2,unitdef);
    -			ret.push_back(p2);
    +			c.params[0] = p2.x;
    +			c.params[1] = p2.y;
    +			c.params[2] = p2.z;
    +			bool cancel = false;
    +			std::set<CUnit*>::iterator ui = selectedUnits.selectedUnits.begin();
    +			for(;ui != selectedUnits.selectedUnits.end() && !cancel; ++ui){
    +				if((*ui)->commandAI->WillCancelQueued(c)){
    +					cancel = true;
    +				}
    +			}
    +			if(!cancel){
    +				ret.push_back(p2);
    +			}
     		}
     		pos=start;
     		pos.x=end.x;
    @@ -1330,7 +1365,19 @@
     			p2.x+=(unitdef->xsize/2)*SQUARE_SIZE;
     			p2.z+=(unitdef->ysize/2)*SQUARE_SIZE;
     			p2=helper->Pos2BuildPos(p2,unitdef);
    -			ret.push_back(p2);
    +			c.params[0] = p2.x;
    +			c.params[1] = p2.y;
    +			c.params[2] = p2.z;
    +			bool cancel = false;
    +			std::set<CUnit*>::iterator ui = selectedUnits.selectedUnits.begin();
    +			for(;ui != selectedUnits.selectedUnits.end() && !cancel; ++ui){
    +				if((*ui)->commandAI->WillCancelQueued(c)){
    +					cancel = true;
    +				}
    +			}
    +			if(!cancel){
    +				ret.push_back(p2);
    +			}
     		}
     		pos=end;
     		for(;pos.x>=start.x;pos.x-=unitdef->xsize*SQUARE_SIZE){
    @@ -1338,7 +1385,19 @@
     			p2.x-=(unitdef->xsize/2)*SQUARE_SIZE;
     			p2.z+=(unitdef->ysize/2)*SQUARE_SIZE;
     			p2=helper->Pos2BuildPos(p2,unitdef);
    -			ret.push_back(p2);
    +			c.params[0] = p2.x;
    +			c.params[1] = p2.y;
    +			c.params[2] = p2.z;
    +			bool cancel = false;
    +			std::set<CUnit*>::iterator ui = selectedUnits.selectedUnits.begin();
    +			for(;ui != selectedUnits.selectedUnits.end() && !cancel; ++ui){
    +				if((*ui)->commandAI->WillCancelQueued(c)){
    +					cancel = true;
    +				}
    +			}
    +			if(!cancel){
    +				ret.push_back(p2);
    +			}
     		}
     		pos=end;
     		pos.x=start.x;
    @@ -1347,7 +1406,19 @@
     			p2.x-=(unitdef->xsize/2)*SQUARE_SIZE;
     			p2.z-=(unitdef->ysize/2)*SQUARE_SIZE;
     			p2=helper->Pos2BuildPos(p2,unitdef);
    -			ret.push_back(p2);
    +			c.params[0] = p2.x;
    +			c.params[1] = p2.y;
    +			c.params[2] = p2.z;
    +			bool cancel = false;
    +			std::set<CUnit*>::iterator ui = selectedUnits.selectedUnits.begin();
    +			for(;ui != selectedUnits.selectedUnits.end() && !cancel; ++ui){
    +				if((*ui)->commandAI->WillCancelQueued(c)){
    +					cancel = true;
    +				}
    +			}
    +			if(!cancel){
    +				ret.push_back(p2);
    +			}
     		}
     	} else if(keys[SDLK_LALT]){			//build a rectangle
     		float xsize=unitdef->xsize*8+buildSpacing*16;
    Index: rts/Sim/Units/CommandAI/CommandAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/CommandAI.cpp	(revision 1451)
    +++ rts/Sim/Units/CommandAI/CommandAI.cpp	(working copy)
    @@ -349,6 +349,33 @@
     		SlowUpdate();
     }
     
    +/**
    +* @brief Determins if c will cancel a queued command
    +* @return true if c will cancel a queued command
    +**/
    +bool CCommandAI::WillCancelQueued(Command &c)
    +{
    +	if(!commandQue.empty()){
    +		std::deque<Command>::iterator ci=commandQue.end();
    +		for(--ci;ci!=commandQue.begin();--ci){							//iterate from the end and dont check the current order
    +			if((ci->id==c.id || (c.id<0 && ci->id<0)) && ci->params.size()==c.params.size()){
    +				if(c.params.size()==1){			//we assume the param is a unit of feature id
    +					if(ci->params[0]==c.params[0]){
    +						return true;
    +					}
    +				} else if(c.params.size()>=3){		//we assume this means that the first 3 makes a position
    +					float3 cpos(c.params[0],c.params[1],c.params[2]);
    +					float3 cipos(ci->params[0],ci->params[1],ci->params[2]);
    +					if((cpos-cipos).SqLength2D()<17*17){
    +						return true;
    +					}
    +				}
    +			}
    +		}
    +	}
    +	return false;
    +}
    +
     void CCommandAI::SlowUpdate()
     {
     	if(commandQue.empty())
    Index: rts/Sim/Units/CommandAI/CommandAI.h
    ===================================================================
    --- rts/Sim/Units/CommandAI/CommandAI.h	(revision 1451)
    +++ rts/Sim/Units/CommandAI/CommandAI.h	(working copy)
    @@ -29,6 +29,7 @@
     	virtual void WeaponFired(CWeapon* weapon);
     	virtual void BuggerOff(float3 pos, float radius);
     	virtual void LoadSave(CLoadSaveInterface* file, bool loading);
    +	virtual bool WillCancelQueued(Command &c);
     
     	void AddStockpileWeapon(CWeapon* weapon);
     	void StockpileChanged(CWeapon* weapon);
    Index: rts/Sim/Units/UnitHandler.cpp
    ===================================================================
    --- rts/Sim/Units/UnitHandler.cpp	(revision 1451)
    +++ rts/Sim/Units/UnitHandler.cpp	(working copy)
    @@ -25,6 +25,7 @@
     #include "UnitLoader.h"
     #include "SyncTracer.h"
     #include "Game/GameSetup.h"
    +#include "Game/Command.h"
     #include "Sim/Misc/AirBaseHandler.h"
     #include "mmgr.h"
     
    @@ -495,3 +496,36 @@
     	}
     	return true;
     }
    +
    +/**
    +* returns a build Command that intersects the ray described by pos and dir from the command queues of the
    +* units units on team number team
    +* @breif returns a build Command that intersects the ray described by pos and dir
    +* @return the build Command, or 0 if one is not found
    +*/
    +
    +Command CUnitHandler::GetBuildCommand(float3 pos, float3 dir){
    +	float3 tempF1 = pos;
    +	std::list<CUnit*>::iterator ui = this->activeUnits.begin();
    +	std::deque<Command>::iterator ci;
    +	for(; ui != this->activeUnits.end(); ui++){
    +		if((*ui)->team == gu->myTeam){
    +			ci = (*ui)->commandAI->commandQue.begin();
    +			for(; ci != (*ui)->commandAI->commandQue.end(); ci++){
    +				if((*ci).id < 0 && (*ci).params.size() >= 3){
    +					tempF1.x = (*ci).params[0];
    +					tempF1.y = (*ci).params[1];
    +					tempF1.z = (*ci).params[2];
    +					tempF1 = pos + dir*((tempF1.y - pos.y)/dir.y) - tempF1;
    +					UnitDef* ud = unitDefHandler->GetUnitByID(-(*ci).id);
    +					if(ud && ud->xsize/2*SQUARE_SIZE > abs(tempF1.x) && ud->ysize/2*SQUARE_SIZE > abs(tempF1.z)){
    +						return (*ci);
    +					}
    +				}
    +			}
    +		}
    +	}
    +	Command c;
    +	c.id = 0;
    +	return c;
    +}
    Index: rts/Sim/Units/UnitHandler.h
    ===================================================================
    --- rts/Sim/Units/UnitHandler.h	(revision 1451)
    +++ rts/Sim/Units/UnitHandler.h	(working copy)
    @@ -14,6 +14,7 @@
     #include <string>
     
     #include "UnitDef.h"
    +#include "Game\Command.h"
     
     class CBuilderCAI;
     class CFeature;
    @@ -58,6 +59,7 @@
     	float GetBuildHeight(float3 pos, const UnitDef* unitdef);
     
     	void LoadSaveUnits(CLoadSaveInterface* file, bool loading);
    +	Command GetBuildCommand(float3 pos, float3 dir);
     
     	std::list<CUnit*> activeUnits;				//used to get all active units
     	std::deque<int> freeIDs;
    
    patch file icon surroundChanges.patch (7,783 bytes) 2006-06-09 00:35 +

-Relationships
+Relationships

-Notes

~0000228

jcnossen (reporter)

thanks, patch applied
+Notes

-Issue History
Date Modified Username Field Change
2006-06-09 00:35 ILMTitan New Issue
2006-06-09 00:35 ILMTitan File Added: surroundChanges.patch
2006-06-12 23:36 jcnossen Status new => closed
2006-06-12 23:36 jcnossen Note Added: 0000228
2006-06-12 23:36 jcnossen Resolution open => fixed
+Issue History