So far I made a small change to source code:
Inside game.cpp
- Add in the beginning, add:
Code: Select all
#include "UnitLoader.h"
Code: Select all
if(s.find(".cheat")==0 && player==0){
gs->cheatEnabled=true;
info->AddLine("Cheating!");
}
by:
Code: Select all
if(s.find(".gi")==0 && gs->cheatEnabled){
if (((s.rfind(" "))!=string::npos) && ((s.length() - s.rfind(" ") -1)>0)){
string unit_to_give=s.substr(s.rfind(" ")+1,s.length() - s.rfind(" ") -1);
string temp_string_unit_to_give=s.substr(s.find(" "),s.rfind(" ")+1 - s.find(" "));
if(temp_string_unit_to_give.find_first_not_of(" ")!=string::npos)
temp_string_unit_to_give=temp_string_unit_to_give.substr(temp_string_unit_to_give.find_first_not_of(" "),temp_string_unit_to_give.find_last_not_of(" ") +1 - temp_string_unit_to_give.find_first_not_of(" "));
bool is_unit_to_give_nanoframe=(temp_string_unit_to_give.find("nano")!=string::npos);
int number_of_unit_to_give=1;
if(temp_string_unit_to_give.find_first_of("0123456789")!=string::npos){
temp_string_unit_to_give=temp_string_unit_to_give.substr(temp_string_unit_to_give.find_first_of("0123456789"),temp_string_unit_to_give.find_last_of("0123456789") +1 -temp_string_unit_to_give.find_first_of("0123456789"));
number_of_unit_to_give = atoi(temp_string_unit_to_give.c_str());
}
if (unitDefHandler->GetUnitByName(unit_to_give)!=0) {
float dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
float3 pos=camera->pos+mouse->dir*dist;
UnitDef *unit_to_give_definition= unitDefHandler->GetUnitByName(unit_to_give);
int xsize_utg=(unit_to_give_definition->xsize);
int zsize_utg=(unit_to_give_definition->ysize);
int counter_utg=number_of_unit_to_give;
int znum_of_unit_to_give=(int)sqrt((float)number_of_unit_to_give);
int xnum_of_unit_to_give=number_of_unit_to_give/znum_of_unit_to_give;
float3 minpos=pos;
minpos.x-=(xnum_of_unit_to_give*xsize_utg*SQUARE_SIZE)/2;
minpos.z-=(znum_of_unit_to_give*zsize_utg*SQUARE_SIZE)/2;
int counterx_utg;
int counterz_utg;
for(counterx_utg=xnum_of_unit_to_give;counterx_utg>=1;--counterx_utg){
for(counterz_utg=znum_of_unit_to_give;counterz_utg>=1;--counterz_utg){
unitLoader.LoadUnit(unit_to_give,float3(float (minpos.x + counterx_utg * xsize_utg*SQUARE_SIZE), float (minpos.y + 0), float (minpos.z + counterz_utg * zsize_utg*SQUARE_SIZE)),gu->myTeam,is_unit_to_give_nanoframe);
--counter_utg;
}
}
for(counterx_utg=counter_utg;counterx_utg>=1;--counterx_utg){
unitLoader.LoadUnit(unit_to_give,float3(float (minpos.x + counterx_utg * xsize_utg*SQUARE_SIZE), float (minpos.y + 0), float (minpos.z + counterz_utg * zsize_utg*SQUARE_SIZE)),gu->myTeam,is_unit_to_give_nanoframe);
}
//unitLoader.LoadUnit(unit_to_give,pos,gu->myTeam,is_unit_to_give_nanoframe);
char dsfdsfdsfdsfdsqfsqdg[130];//Sorry, I don't know how to convert an int to a string without using a temporary variable
_itoa(gu->myTeam,dsfdsfdsfdsfdsqfsqdg,10);
string speech_to_say="Giving one "+unit_to_give+" to team "+dsfdsfdsfdsfdsqfsqdg;
_itoa(number_of_unit_to_give,dsfdsfdsfdsfdsqfsqdg,10);
if (number_of_unit_to_give!=1)
speech_to_say.replace(speech_to_say.find("one"),3,dsfdsfdsfdsfdsqfsqdg);
if(is_unit_to_give_nanoframe)
speech_to_say+=" nanoframe";
info->AddLine(speech_to_say);
}else{
info->AddLine(unit_to_give+" is not a valid unitname");
}
}
}
if(s.find(".cheat")==0 && player==0){
if (gs->cheatEnabled){
gs->cheatEnabled=false;
info->AddLine("No more cheating");
}else{
gs->cheatEnabled=true;
info->AddLine("Cheating!");
}
}
The effect are the following:
1) .cheat becomes a toggle, once cheat are enabled typing .cheat again disable the cheat mode. Useful when you need the cheat once in the beginning of a game but don't want other player to be able to use them later.
2) a new cheat code is added: .gi* (number) (nano*) unitname. For instance
.give armavp create an arm advanced vehicle plant
.gimme nanoframe armpw create an unbuilt peewee
.gift 50 CorKrog create fifty krogoths!
You can combine nano and a number. The unitname must always be last. Units are spawn under the cursor, nicely organised in a square.
Ok, the addition of that cheat code is probably not vital to spring (but I'd still like it to be included, it works well and it's very useful for testing stuff. For instance it's nice to be able to build anything without having to travel the whole buildtree, or to build stuff even if they aren't in the buildmenu, or to get unit that would cause problem in the factory they're supposed to be built from, or to get instabuild anywhere without using the .nocost cheat that can't be turned off, or....)
But now, given that concrete exemple, I'd like someone to teach me the proper way to get it uploaded on sourceforge. Using WinCVS I can download the latest source fine, but now, how to upload a change? Do I just post in the Spring Developpement forum like I did? Must I create a diff file with WinCVS and post it? (If so, what do I diff it with, lastest source from CVS or source of lastest officialy realesed build?) Is there some secret menu in WinCVS to upload my change automatically? Is there some page on the CVS to upload and comment my change?
I know that many people had trouble getting their change to the source code included in official release, so I'd like to know the proper way. So if I ever does a much bigger and more useful change (lemme dream!), I'll know the way.