Skip to content

Commit

Permalink
- Fixed a series of compile errors and exceptions introduced by some …
Browse files Browse the repository at this point in the history
…very poorly thought out changes by Blizzard in 1.5. Temporarily disabled Smart Hostile.
  • Loading branch information
Motive committed Sep 16, 2012
1 parent 858a822 commit a9f9889
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 117 deletions.
2 changes: 1 addition & 1 deletion Commands/SpawnCommand.galaxy
Expand Up @@ -37,7 +37,7 @@ bool libcrtx_command_spawn_parse(string lp_message)
}

val = StringWord(lp_message, currentParameter);
if( StringToInt(val) != 0 ) // integer - spawncount only
if( libcrtx_is_integer(val) && StringToInt(val) != 0 ) // integer - spawncount only
{
// reset when we have a new integer!
libcrtx_command_spawn_instances[EventPlayer()].count = libcrtx_boundsInt(StringToInt(val), 0, libcrtx_setting_getint(libcrtx_setting_int_maxspawncount));
Expand Down
25 changes: 20 additions & 5 deletions Commands/UnitCommands.galaxy
Expand Up @@ -59,12 +59,27 @@ bool libcrtx_command_removearea(bool testConds, bool runActions) {

bool libcrtx_command_scale(bool testConds, bool runActions) {
fixed scale;
fixed scaleY;
fixed scaleZ;
fixed scaleY = 0;
fixed scaleZ = 0;
string x;
string y;
string z;
unitgroup g = libcrtx_chat_get_context(EventPlayer());
scale = StringToFixed(StringWord(libcrtx_chat_get_parse_line(EventPlayer()), 2));
scaleY = StringToFixed(StringWord(libcrtx_chat_get_parse_line(EventPlayer()), 3));
scaleZ = StringToFixed(StringWord(libcrtx_chat_get_parse_line(EventPlayer()), 4));
x = StringWord(libcrtx_chat_get_parse_line(EventPlayer()), 2);
y = StringWord(libcrtx_chat_get_parse_line(EventPlayer()), 3);
z = StringWord(libcrtx_chat_get_parse_line(EventPlayer()), 4);

if( libcrtx_is_float(x) ) {
scale = StringToFixed(x);
}

if( libcrtx_is_float(y) ) {
scaleY = StringToFixed(y);
}

if( libcrtx_is_float(z) ) {
scaleZ = StringToFixed(z);
}

if(scaleZ == 0.0) {
scaleZ = scale;
Expand Down
111 changes: 0 additions & 111 deletions Common/ComputerAI.galaxy
Expand Up @@ -37,128 +37,17 @@ bool libcrtx_ai_is_enabled()

void libcrtx_ai_start()
{
int player;
point targDPoint;
point targOPoint;
wavetarget targD;
wavetarget targO;
player = libcrtx_setting_getint(libcrtx_setting_int_smarthostile);
if( libcrtx_ai_setup ) {
libcrtx_ai_enabled = true;
return;
}

libcrtx_ai_enabled = true;
libcrtx_ai_setup = true;

// Get 'em started on minerals.
PlayerModifyPropertyInt( player, c_playerPropMinerals, c_playerPropOperAdd, 500000 );
PlayerModifyPropertyInt( player, c_playerPropVespene, c_playerPropOperAdd, 500000 );

AIStart(player, false, 400);

AISetDifficulty(player, c_diffNormalVision, false);
AISetDifficulty(player, c_diffLimitAPM, false);

AISetDifficulty(player, c_diffSpotChangelings, false);
AISetDifficulty(player, c_diffWaveAvoidDanger, true);
AISetDifficulty(player, c_diffFleeDamage, true);
AISetDifficulty(player, c_diffEarlyDefenseScout, true);
AISetDifficulty(player, c_diffUseExtraScouts, true);
AISetDifficulty(player, c_diffHoldAtIdleChokes, true);
AISetDifficulty(player, c_diffPressForward, true);
AISetDifficulty(player, c_diffFleeWorkers, true);
AISetDifficulty(player, c_diffFleeDanger, true);

AISetDifficulty(player, c_diffRepairDamage, true);
AISetDifficulty(player, c_diffOptimizeGas, true);
AISetDifficulty(player, c_diffDefendWithPeons, true);
AISetDifficulty(player, c_diffEnableDangerMap, true);
AISetDifficulty(player, c_diffNormalTargetPrio, true);
AISetDifficulty(player, c_diffAllowResourceReq, true);

AISetDifficulty(player, c_diffAutoLoadBunkers, false);
AISetDifficulty(player, c_diffEarlyGameRepair, false);

//AISetFlag(player, e_flagsRunScared, AIDiffThreshold(player, false, c_skirVeryHard, true));
AISetFlag(player, e_flagsRunScared, false); // TODO fix scared and re-add this

AISetFlag(player, e_flagsLateScout, false);
AISetFlag(player, e_flagsClearObs, false);

//AIDeclareTown(player, c_townOne, p);
//AISetMainTown(player, c_townOne);
AIHarvest(player, c_townOne);
AISetNumScouts(player, 1);
AIScout(player);
AISetAllStates(player, 1);

targDPoint = AIWaveTargetGatherDPoint(player, c_townMain);
targOPoint = AIWaveTargetGatherOPoint(player, c_townMain);
targD = AIWaveTargetGatherD(player, c_townMain);
targO = AIWaveTargetGatherO(player, c_townMain);

AIWaveSet(player, c_waveMain, AIWaveCreate(AIWaveInfoCreate(), player, targOPoint));
AIWaveSet(player, c_waveAttack, AIWaveCreate(AIWaveInfoCreate(), player, targOPoint));
AIWaveSet(player, c_waveDivert1, AIWaveCreate(AIWaveInfoCreate(), player, targOPoint));
AIWaveSet(player, c_waveDivert2, AIWaveCreate(AIWaveInfoCreate(), player, targOPoint));
AIWaveSet(player, c_waveClearObs, AIWaveCreate(AIWaveInfoCreate(), player, targOPoint));
AIWaveSet(player, c_waveHome, AIWaveCreate(AIWaveInfoCreate(), player, targDPoint));
AIWaveSet(player, c_waveDefend, AIWaveCreate(AIWaveInfoCreate(), player, targDPoint));

AIWaveSetType(AIWaveGet(player, c_waveMain), c_waveStateIdle, targO);
AIWaveSetType(AIWaveGet(player, c_waveAttack), c_waveStateIdle, targO);
AIWaveSetType(AIWaveGet(player, c_waveDivert1), c_waveStateIdle, targO);
AIWaveSetType(AIWaveGet(player, c_waveDivert2), c_waveStateIdle, targO);
AIWaveSetType(AIWaveGet(player, c_waveClearObs), c_waveStateIdle, targO);
AIWaveSetType(AIWaveGet(player, c_waveHome), c_waveStateIdle, targD);
AIWaveSetType(AIWaveGet(player, c_waveDefend), c_waveStateIdle, targD);

AISetMaxBestAttackersLimit(player, 8);

AITransportIgnore(player, "VikingAssault");
AITransportSetPanic(player, 0.6);
AITransportSetReturn(player, targDPoint);

AISpecifiedMakers();
AISpecifiedHealers(player);
AISetDefaultCombatFlags(player, true);
AIAddDetectionDangerUnits(player);

AISetNukeConstants(player);

AISetSpecificState(player, e_mainState, e_mainState_Init);
}

void libcrtx_ai_createtown(point p, bool makeCapital)
{
int player = libcrtx_setting_getint(libcrtx_setting_int_smarthostile);
libNtve_gf_DeclareNextTown( player, p );
if( !libcrtx_ai_maintownsetup || makeCapital ) {
AIDeclareTown(player, c_townOne, p);
AISetMainTown(player, c_townOne);
libcrtx_ai_start();
libcrtx_ai_maintownsetup = true;

AISetSpecificState(player, e_mainState, e_mainState_Init);
}
}

void libcrtx_ai_update()
{
int player = libcrtx_setting_getint(libcrtx_setting_int_smarthostile);

if( !libcrtx_ai_maintownsetup ) {
return;
}

if( libcrtx_ai_race == libcrtx_race_zerg ) {
AIMeleeZerg(player);
} else if( libcrtx_ai_race == libcrtx_race_protoss ) {
AIMeleeProt(player);
} else if( libcrtx_ai_race == libcrtx_race_terran ) {
AIMeleeTerr(player);
}
}

void libcrtx_ai_stop()
Expand Down
40 changes: 40 additions & 0 deletions Common/Utility.galaxy
Expand Up @@ -352,3 +352,43 @@ string libcrtx_replace_word(string s, string word, string replace, int maxCount,
}
return result;
}

// Blizzard made StringTo<X> functions throw exceptions rather than fail gracefully
// but in their genius, did not add test functions. So we have to write our own. ><
bool libcrtx_is_integer(string s)
{
int x = 1;
string c1 = "";
while( x != StringLength(s) )
{
c1 = StringSub(s, x, x);

if( !(c1 == "0" || c1 == "1" || c1 == "2" || c1 == "3" || c1 == "4" || c1 == "5" || c1 == "6" || c1 == "7" || c1 == "8" || c1 == "9") ) {
return false;
}

x += 1;
}

return true;
}

// Blizzard made StringTo<X> functions throw exceptions rather than fail gracefully
// but in their genius, did not add test functions. So we have to write our own. ><
bool libcrtx_is_float(string s)
{
int x = 1;
string c1 = "";
while( x != StringLength(s) )
{
c1 = StringSub(s, x, x);

if( !(c1 == "." || c1 == "0" || c1 == "1" || c1 == "2" || c1 == "3" || c1 == "4" || c1 == "5" || c1 == "6" || c1 == "7" || c1 == "8" || c1 == "9") ) {
return false;
}

x += 1;
}

return true;
}

0 comments on commit a9f9889

Please sign in to comment.