2025-07-18 13:27 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000572Spring engineGeneralpublic2007-08-13 18:22
Reporterimbaczek 
Assigned Toimbaczek 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000572: [patch] build once
Descriptionby popular demand:
- if a factory is set on repeat and the user alt-leftclicks a unit, it gets inserted right behind the current order and is only built once. behavior of alt-click when repeat is off is unchanged (ie. replace the currently built unit.)
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon build_once.patch (3,187 bytes) 2007-07-28 15:07 -
    Index: rts/Game/command.h
    ===================================================================
    --- rts/Game/command.h	(revision 4098)
    +++ rts/Game/command.h	(working copy)
    @@ -88,6 +88,7 @@
     #define SHIFT_KEY       (1 << 5) //  32
     #define CONTROL_KEY     (1 << 6) //  64
     #define ALT_KEY         (1 << 7) // 128
    +#define DONT_REPEAT		(1 << 8) // 256
     
     
     struct Command {
    @@ -96,7 +97,7 @@
     	: timeOut(INT_MAX), options(0), tag(0) {};
     	int id;
     	vector<float> params;
    -	unsigned char options;
    +	int options;
     	unsigned int tag;
     	int timeOut;  // remove this command after this frame
     	              // can only be set locally, not sent over net
    Index: rts/Sim/Units/CommandAI/CommandAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/CommandAI.cpp	(revision 4098)
    +++ rts/Sim/Units/CommandAI/CommandAI.cpp	(working copy)
    @@ -1204,7 +1204,9 @@
     void CCommandAI::FinishCommand(void)
     {
     	const int type = commandQue.front().id;
    +	const bool dontrepeat = commandQue.front().options & DONT_REPEAT;
     	if (repeatOrders
    +		&& !dontrepeat
     	    && (type != CMD_STOP)
     	    && (type != CMD_PATROL)
     	    && (type != CMD_SET_WANTED_MAX_SPEED)
    @@ -1293,7 +1295,7 @@
     		}
     		Command& c=commandQue[a];
     		file->lsInt(c.id);
    -		file->lsUChar(c.options);
    +		file->lsInt(c.options);
     		file->lsInt(c.timeOut);
     
     		int paramSize=c.params.size();
    Index: rts/Sim/Units/CommandAI/FactoryCAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/FactoryCAI.cpp	(revision 4098)
    +++ rts/Sim/Units/CommandAI/FactoryCAI.cpp	(working copy)
    @@ -237,11 +237,23 @@
     	} else {
     		if(c.options & ALT_KEY){
     			for(int a=0;a<numItems;++a){
    -				commandQue.push_front(c);
    +				if (repeatOrders) {
    +					Command nc(c);
    +					nc.options |= DONT_REPEAT;
    +					if (commandQue.empty())
    +						commandQue.push_front(nc);
    +					else
    +						commandQue.insert(commandQue.begin()+1, nc);
    +				} else {
    +					commandQue.push_front(c);
    +				}
    +
     			}
    -			building=false;
    -			CFactory* fac=(CFactory*)owner;
    -			fac->StopBuild();
    +			if (!repeatOrders) {
    +				building=false;
    +				CFactory* fac=(CFactory*)owner;
    +				fac->StopBuild();
    +			}
     		} else {
     			for(int a=0;a<numItems;++a){
     				commandQue.push_back(c);
    @@ -294,7 +306,7 @@
     
     void CFactoryCAI::CancelRestrictedUnit(const Command& c, BuildOption& buildOption)
     {
    -	if(!repeatOrders) {
    +	if(!repeatOrders || c.options & DONT_REPEAT) {
     		buildOption.numQued--;
     		ENTER_MIXED;
     		if (owner->team == gu->myTeam) {
    @@ -331,7 +343,7 @@
     					building=false;
     					if(owner->group)
     						owner->group->CommandFinished(owner->id,commandQue.front().id);
    -					if(!repeatOrders)
    +					if(!repeatOrders || c.options & DONT_REPEAT)
     						boi->second.numQued--;
     					UpdateIconName(c.id,boi->second);
     					FinishCommand();
    @@ -347,7 +359,7 @@
     			} else {
     				const UnitDef *def = unitDefHandler->GetUnitByName(boi->second.name);
     				if(luaRules && !luaRules->AllowUnitCreation(def, owner, NULL)) {
    -					if(!repeatOrders){
    +					if(!repeatOrders || c.options & DONT_REPEAT){
     						boi->second.numQued--;
     					}
     					UpdateIconName(c.id,boi->second);
    
    patch file icon build_once.patch (3,187 bytes) 2007-07-28 15:07 +
  • patch file icon build_once_v2.patch (3,517 bytes) 2007-07-29 22:09 -
    Index: rts/Game/command.h
    ===================================================================
    --- rts/Game/command.h	(revision 4106)
    +++ rts/Game/command.h	(working copy)
    @@ -54,7 +54,6 @@
     #define CMD_CAPTURE              130
     #define CMD_AUTOREPAIRLEVEL      135
     #define CMD_LOOPBACKATTACK       140
    -#define CMD_IDLEMODE             145
     
     #define CMDTYPE_ICON                        0  // expect 0 parameters in return
     #define CMDTYPE_ICON_MODE                   5  // expect 1 parameter in return (number selected mode)
    @@ -84,13 +83,16 @@
     
     
     // bits for the option field of Command
    -#define INTERNAL_ORDER  (1 << 3) //   8
    +#define DONT_REPEAT     (1 << 3) //   8
     #define RIGHT_MOUSE_KEY (1 << 4) //  16
     #define SHIFT_KEY       (1 << 5) //  32
     #define CONTROL_KEY     (1 << 6) //  64
     #define ALT_KEY         (1 << 7) // 128
     
     
    +#define INTERNAL_ORDER  (DONT_REPEAT)
    +
    +
     struct Command {
     	CR_DECLARE_STRUCT(Command);
     	Command()
    Index: rts/Sim/Units/CommandAI/CommandAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/CommandAI.cpp	(revision 4106)
    +++ rts/Sim/Units/CommandAI/CommandAI.cpp	(working copy)
    @@ -1204,11 +1204,13 @@
     void CCommandAI::FinishCommand(void)
     {
     	const int type = commandQue.front().id;
    +	const bool dontrepeat = commandQue.front().options & DONT_REPEAT
    +			|| commandQue.front().options & INTERNAL_ORDER;
     	if (repeatOrders
    +		&& !dontrepeat
     	    && (type != CMD_STOP)
     	    && (type != CMD_PATROL)
    -	    && (type != CMD_SET_WANTED_MAX_SPEED)
    -			&& !(commandQue.front().options & INTERNAL_ORDER)){
    +	    && (type != CMD_SET_WANTED_MAX_SPEED)){
     		commandQue.push_back(commandQue.front());
     	}
     	commandQue.pop_front();
    Index: rts/Sim/Units/CommandAI/FactoryCAI.cpp
    ===================================================================
    --- rts/Sim/Units/CommandAI/FactoryCAI.cpp	(revision 4106)
    +++ rts/Sim/Units/CommandAI/FactoryCAI.cpp	(working copy)
    @@ -237,11 +237,23 @@
     	} else {
     		if(c.options & ALT_KEY){
     			for(int a=0;a<numItems;++a){
    -				commandQue.push_front(c);
    +				if (repeatOrders) {
    +					Command nc(c);
    +					nc.options |= DONT_REPEAT;
    +					if (commandQue.empty())
    +						commandQue.push_front(nc);
    +					else
    +						commandQue.insert(commandQue.begin()+1, nc);
    +				} else {
    +					commandQue.push_front(c);
    +				}
    +
     			}
    -			building=false;
    -			CFactory* fac=(CFactory*)owner;
    -			fac->StopBuild();
    +			if (!repeatOrders) {
    +				building=false;
    +				CFactory* fac=(CFactory*)owner;
    +				fac->StopBuild();
    +			}
     		} else {
     			for(int a=0;a<numItems;++a){
     				commandQue.push_back(c);
    @@ -294,7 +306,7 @@
     
     void CFactoryCAI::CancelRestrictedUnit(const Command& c, BuildOption& buildOption)
     {
    -	if(!repeatOrders) {
    +	if(!repeatOrders || c.options & DONT_REPEAT) {
     		buildOption.numQued--;
     		ENTER_MIXED;
     		if (owner->team == gu->myTeam) {
    @@ -331,7 +343,7 @@
     					building=false;
     					if(owner->group)
     						owner->group->CommandFinished(owner->id,commandQue.front().id);
    -					if(!repeatOrders)
    +					if(!repeatOrders || c.options & DONT_REPEAT)
     						boi->second.numQued--;
     					UpdateIconName(c.id,boi->second);
     					FinishCommand();
    @@ -347,7 +359,7 @@
     			} else {
     				const UnitDef *def = unitDefHandler->GetUnitByName(boi->second.name);
     				if(luaRules && !luaRules->AllowUnitCreation(def, owner, NULL)) {
    -					if(!repeatOrders){
    +					if(!repeatOrders || c.options & DONT_REPEAT){
     						boi->second.numQued--;
     					}
     					UpdateIconName(c.id,boi->second);
    
    patch file icon build_once_v2.patch (3,517 bytes) 2007-07-29 22:09 +

-Relationships
+Relationships

-Notes

~0001033

trepan (reporter)

You bumped from 8 bits to 32 bits for all command options
for this feature when the 3 lower bits aren't being used?

Also, the INTERNAL_ORDER bit is available. It is used to
provide the DONT_REPEAT functionality in normal queues
(as well as the time-out feature, but you don't need that).

~0001034

imbaczek (reporter)

Last edited: 2007-07-29 13:29

yes. structures get aligned to 4/8 bytes depending on architecture anyway and save file sizes aren't an issue.

I wasn't aware of INTERNAL_ORDER though. I'll check it out. edit: if only it was named more inappropriately... Build-once orders are anything but internal. I can resubmit a patch that uses this flag, but will feel guilty ;)

~0001035

trepan (reporter)

I was more concerned with needless bandwidth usage than savefiles.
As mentionned, if you don't like INTERNAL_ORDER, the 3 lower bits
also seem to be available.

~0001036

imbaczek (reporter)

ah ok, good point. i'll submit a new one soon.

~0001037

imbaczek (reporter)

as promised. reverted Command::options type to uchar and sanitized INTERNAL_ORDER (I hope.)

~0001097

imbaczek (reporter)

committed in r4191.
+Notes

-Issue History
Date Modified Username Field Change
2007-07-28 15:07 imbaczek New Issue
2007-07-28 15:07 imbaczek File Added: build_once.patch
2007-07-28 15:43 trepan Note Added: 0001033
2007-07-29 13:25 imbaczek Note Added: 0001034
2007-07-29 13:29 imbaczek Note Edited: 0001034
2007-07-29 16:03 trepan Note Added: 0001035
2007-07-29 17:25 imbaczek Note Added: 0001036
2007-07-29 22:09 imbaczek File Added: build_once_v2.patch
2007-07-29 22:15 imbaczek Note Added: 0001037
2007-08-13 18:22 imbaczek Status new => resolved
2007-08-13 18:22 imbaczek Resolution open => fixed
2007-08-13 18:22 imbaczek Assigned To => imbaczek
2007-08-13 18:22 imbaczek Note Added: 0001097
+Issue History