From c4114d5c6d8a935f1d988556ec5e6af92774664d Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Sat, 28 Jul 2012 10:56:45 -0400 Subject: [PATCH] Dear God why did I ever use Tribal IDE! Fixed tabbing and made the code cleaner and not so hard to read. --- scripts/modScripts/client/clientFunctions.cs | 158 +++--- scripts/modScripts/client/initialize.cs | 2 + .../modScripts/client/serverRequestHandler.cs | 2 + scripts/modScripts/server/dataImport.cs | 484 +++++++++--------- scripts/modScripts/server/looting.cs | 105 ++-- scripts/modScripts/server/mining.cs | 4 +- scripts/modScripts/server/propData.cs | 2 +- scripts/modScripts/server/propertyOwning.cs | 244 +++++---- scripts/modScripts/server/serverFunctions.cs | 46 +- scripts/modScripts/server/serverNetworking.cs | 22 +- scripts/modScripts/shared/basicDataStorage.cs | 256 +++++---- scripts/modScripts/shared/fileProcessing.cs | 64 ++- scripts/modScripts/shared/initialize.cs | 3 +- .../modScripts/shared/numericProcessing.cs | 14 - scripts/modScripts/shared/stringProcessing.cs | 169 +++--- 15 files changed, 766 insertions(+), 809 deletions(-) delete mode 100644 scripts/modScripts/shared/numericProcessing.cs diff --git a/scripts/modScripts/client/clientFunctions.cs b/scripts/modScripts/client/clientFunctions.cs index c3226d1..a03502a 100644 --- a/scripts/modScripts/client/clientFunctions.cs +++ b/scripts/modScripts/client/clientFunctions.cs @@ -4,7 +4,7 @@ // one of the developers. Otherwise, your decompiler is so advanced that it can // somehow get commented lines in a script. If this is not the case, someone has // betrayed my trust. -// -- Dark Dragon DX +// -- Dark Dragon DX (as of 2011). //------------------------------------------------------------------------------ //Different from modVersionText, is used to compare our mod to the update server @@ -15,85 +15,83 @@ $ModVersion = 1.0; //Looks better as whole numbuhs //Although, hooks can be attached for custom actions. function clientCmdHandleScriptedCommand(%num,%arg1,%arg2,%arg3,%arg4) { - switch(%num) - { - case 0: //Pop Dialog - Canvas.popDialog(%arg1); - case 1: //BoxYesNo - messageBoxYesNo(%arg1,%arg2,%arg3,%arg4); - case 2: //FadeIn - ServerConnection.setBlackOut(true, %arg1); - case 3: //Fadeout - ServerConnection.setBlackOut(false, %arg1); - case 4: //Show Cursor - $cursorControlled = %arg1; - lockMouse(%arg1); + switch(%num) + { + case 0: //Pop Dialog + Canvas.popDialog(%arg1); + case 1: //BoxYesNo + messageBoxYesNo(%arg1,%arg2,%arg3,%arg4); + case 2: //FadeIn + ServerConnection.setBlackOut(true, %arg1); + case 3: //Fadeout + ServerConnection.setBlackOut(false, %arg1); + case 4: //Show Cursor + $cursorControlled = %arg1; + lockMouse(%arg1); - if (%arg1) - { - Canvas.cursorOn(); - GlobalActionMap.bind(mouse, button0, RTS_LeftButton); - GlobalActionMap.bind(mouse, button1, RTS_RightButton); - RTS_Command.push(); - $RTS::ButtonPress = false; - } - else - { - Canvas.cursorOff(); - GlobalActionMap.unbind(mouse, button0); - GlobalActionMap.unbind(mouse, button1); - Canvas.setCursor(DefaultCursor); - RTS_Command.pop(); - $RTS::ButtonPress = true; - } - case 5: //Verify Client - if (%arg1) - ScoreParent.settext("PDA - PERSONAL DATA ASSISTANT"); + if (%arg1) + { + Canvas.cursorOn(); + GlobalActionMap.bind(mouse, button0, RTS_LeftButton); + GlobalActionMap.bind(mouse, button1, RTS_RightButton); + RTS_Command.push(); + $RTS::ButtonPress = false; + } + else + { + Canvas.cursorOff(); + GlobalActionMap.unbind(mouse, button0); + GlobalActionMap.unbind(mouse, button1); + Canvas.setCursor(DefaultCursor); + RTS_Command.pop(); + $RTS::ButtonPress = true; + } + case 5: //Verify Client + if (%arg1) + ScoreParent.settext("PDA - PERSONAL DATA ASSISTANT"); + $Pref::LANAccount::GUID = stripNonNumericCharacters($Pref::LANAccount::GUID); //Make sure the GUID is pure before sending. Monkee, you won't be breaking anything here. The server does the same on its side. :) + //Let the server know we're an actual client.. and if we're offline, send my GUID + if (!$PlayingOnline) + commandToServer('VerifyClient',$Pref::LANAccount::GUID,$ModVersion); + else + commandToServer('VerifyClient',0,$ModVersion); + //Turn off the 'continue' button if it's T2Bol. + if (%arg2) + DB_ContinueBTN.setActive(0); + case 6: //Is RTS Game + hudClusterBack.opacity = 0; //Make it invisible + clientCmdHandleScriptedCommand(4,true); //Show our cursor + case 7: //Music fadeout + alxMusicFadeout($Pref::Audio::MusicVolume); + case 8: //Music Fadein + alxMusicFadein(0); + case 9: //Set client Time + clockHud.setVisible(0); + %pos = ClockHud.getPosition(); + %x = getWord(%pos,0); + %y = getWord(%pos,1); + %x = %x - -14; + %y = %y - -4; + if (!IsObject(timeHud)) + { + new GuiTextCtrl(timeHud) + { + profile ="ClockProfile"; + position = %x SPC %y; + extent = "41 12"; + text = %arg1 SPC "Hrs"; + horizSizing = "left"; + vertSizing = "bottom"; + }; + playGui.add(timeHud); + } - $Pref::LANAccount::GUID = stripNonNumericCharacters($Pref::LANAccount::GUID); //Make sure the GUID is pure before sending. Monkee, you won't be breaking anything here. The server does the same on its side. :) - //Let the server know we're an actual client.. and if we're offline, send my GUID - if (!$PlayingOnline) - commandToServer('VerifyClient',$Pref::LANAccount::GUID,$ModVersion); - else - commandToServer('VerifyClient',0,$ModVersion); - - //Turn off the 'continue' button if it's T2Bol. - if (%arg2) - DB_ContinueBTN.setActive(0); - case 6: //Is RTS Game - hudClusterBack.opacity = 0; //Make it invisible - clientCmdHandleScriptedCommand(4,true); //Show our cursor - case 7: //Music fadeout - alxMusicFadeout($Pref::Audio::MusicVolume); - case 8: //Music Fadein - alxMusicFadein(0); - case 9: //Set client Time - clockHud.setVisible(0); - %pos = ClockHud.getPosition(); - %x = getWord(%pos,0); - %y = getWord(%pos,1); - %x = %x - -14; - %y = %y - -4; - if (!IsObject(timeHud)) - { - new GuiTextCtrl(timeHud) - { - profile ="ClockProfile"; - position = %x SPC %y; - extent = "41 12"; - text = %arg1 SPC "Hrs"; - horizSizing = "left"; - vertSizing = "bottom"; - }; - playGui.add(timeHud); - } - - timeHud.setValue(%arg1); - timeHud.setVisible(1); - default: //If for some reason we got an invalid command ID, report it to console - if ($Pref::DeveloperMode) //If dev mode is on (just a value set on the clientside to tell scripts to echo shit to the console) - error("Scripted Command Handler: Received unknown command request ("@%num@") from server."); - return false; - } -return true; + timeHud.setValue(%arg1); + timeHud.setVisible(1); + default: //If for some reason we got an invalid command ID, report it to console + if ($Pref::DeveloperMode) //If dev mode is on (just a value set on the clientside to tell scripts to echo shit to the console) + error("Scripted Command Handler: Received unknown command request ("@%num@") from server."); + return false; + } + return true; } diff --git a/scripts/modScripts/client/initialize.cs b/scripts/modScripts/client/initialize.cs index 4f6131a..dc93741 100644 --- a/scripts/modScripts/client/initialize.cs +++ b/scripts/modScripts/client/initialize.cs @@ -1,5 +1,7 @@ //------------------------------------------------------------------------------ +// initialise.cs // Client Scripts Init +// Copright (c) 2012 The DarkDragonDX //============================================================================== exec("scripts/modScripts/client/clientFunctions.cs"); exec("scripts/modScripts/client/serverRequestHandler.cs"); diff --git a/scripts/modScripts/client/serverRequestHandler.cs b/scripts/modScripts/client/serverRequestHandler.cs index 8fee9d0..331e4b4 100644 --- a/scripts/modScripts/client/serverRequestHandler.cs +++ b/scripts/modScripts/client/serverRequestHandler.cs @@ -1,5 +1,7 @@ //------------------------------------------------------------------------------ +// serverRequestHandler.cs // Server Request Handler +// Copyright (c) 2012 The DarkDragonDX //============================================================================== function InteractWithObject(%val) diff --git a/scripts/modScripts/server/dataImport.cs b/scripts/modScripts/server/dataImport.cs index 565c191..aa2474a 100644 --- a/scripts/modScripts/server/dataImport.cs +++ b/scripts/modScripts/server/dataImport.cs @@ -4,300 +4,298 @@ function gameConnection::writeSaveFile(%this) { - //Compile Main Variable List - %mission = $CurrentMission; - %player = %this.player; - %transform = %player.getTransform(); - %velocity = %player.getVelocity(); - %damage = %player.getDamageLevel(); - %race = %this.race; - %armor = %this.armor; - %energy = %player.getEnergyLevel(); - %whiteout = %player.getWhiteout(); - %damageFlash = %player.getDamageFlash(); - %cash = %this.cash; - %hasRadio = %this.hasRadio; - %underStandsHuman = %this.underStandsHuman; - %underStandsBioderm = %this.underStandsBioderm; - %underStandsDraakan = %this.underStandsDraakan; - %underStandsCriollos = %this.underStandsCriollos; + //Compile Main Variable List + %mission = $CurrentMission; + %player = %this.player; + %transform = %player.getTransform(); + %velocity = %player.getVelocity(); + %damage = %player.getDamageLevel(); + %race = %this.race; + %armor = %this.armor; + %energy = %player.getEnergyLevel(); + %whiteout = %player.getWhiteout(); + %damageFlash = %player.getDamageFlash(); + %cash = %this.cash; + %hasRadio = %this.hasRadio; + %underStandsHuman = %this.underStandsHuman; + %underStandsBioderm = %this.underStandsBioderm; + %underStandsDraakan = %this.underStandsDraakan; + %underStandsCriollos = %this.underStandsCriollos; - %time = formatTimeString("hh:nn A"); - %date = formatTimeString("mm/dd/yy"); + %time = formatTimeString("hh:nn A"); + %date = formatTimeString("mm/dd/yy"); + + %file = "data/game/saves/" @ %mission @ "/" @ %this.guid @ ".txt"; + %fileObj = new fileObject(); + %fileObj.openForWrite(%file); + %fileObj.writeLine(";Saved by" SPC %this.nameBase SPC "on" SPC %date SPC "at" SPC %time); + %fileObj.writeLine(""); - %file = "data/game/saves/" @ %mission @ "/" @ %this.guid @ ".txt"; - %fileObj = new fileObject(); - %fileObj.openForWrite(%file); - %fileObj.writeLine(";Saved by" SPC %this.nameBase SPC "on" SPC %date SPC "at" SPC %time); - %fileObj.writeLine(""); + //Todo: Make this writing method more efficient ... + %fileObj.writeLine("[Character]"); + %fileObj.writeLine("transform = \x22" @ %transform @ "\x22;"); + %fileObj.writeLine("velocity = \x22" @ %velocity @ "\x22;"); + %fileObj.writeLine("damage = \x22" @ %damage @ "\x22;"); + %fileObj.writeLine("race = \x22" @ %race @ "\x22;"); + %fileObj.writeLine("armor = \x22" @ %armor @ "\x22;"); + %fileObj.writeLine("energy = \x22" @ %energy @ "\x22;"); + %fileObj.writeLine("whiteOut = \x22" @ %whiteout @ "\x22;"); + %fileObj.writeLine("damageFlash = \x22" @ %damageFlash @ "\x22;"); + %fileObj.writeLine("cash = \x22" @ %cash @ "\x22;"); + %fileObj.writeLine("hasRadio = \x22" @ %hasRadio @ "\x22;"); + %fileObj.writeLine("underStandsHuman = \x22" @ %underStandsHuman @ "\x22;"); + %fileObj.writeLine("underStandsBioderm = \x22" @ %underStandsBioderm @ "\x22;"); + %fileObj.writeLine("underStandsDraakan = \x22" @ %underStandsDraakan @ "\x22;"); + %fileObj.writeLine("underStandsCriollos = \x22" @ %underStandsCriollos @ "\x22;"); + %fileObj.writeLine(""); - //Todo: Make this writing method more efficient ... - %fileObj.writeLine("[Character]"); - %fileObj.writeLine("transform = \x22" @ %transform @ "\x22;"); - %fileObj.writeLine("velocity = \x22" @ %velocity @ "\x22;"); - %fileObj.writeLine("damage = \x22" @ %damage @ "\x22;"); - %fileObj.writeLine("race = \x22" @ %race @ "\x22;"); - %fileObj.writeLine("armor = \x22" @ %armor @ "\x22;"); - %fileObj.writeLine("energy = \x22" @ %energy @ "\x22;"); - %fileObj.writeLine("whiteOut = \x22" @ %whiteout @ "\x22;"); - %fileObj.writeLine("damageFlash = \x22" @ %damageFlash @ "\x22;"); - %fileObj.writeLine("cash = \x22" @ %cash @ "\x22;"); - %fileObj.writeLine("hasRadio = \x22" @ %hasRadio @ "\x22;"); - %fileObj.writeLine("underStandsHuman = \x22" @ %underStandsHuman @ "\x22;"); - %fileObj.writeLine("underStandsBioderm = \x22" @ %underStandsBioderm @ "\x22;"); - %fileObj.writeLine("underStandsDraakan = \x22" @ %underStandsDraakan @ "\x22;"); - %fileObj.writeLine("underStandsCriollos = \x22" @ %underStandsCriollos @ "\x22;"); - %fileObj.writeLine(""); + //Compile Inventory List + %slotCount = %player.weaponSlotCount; + %healthKits = %player.invRepairKit; + %fileObj.writeLine("[Inventory]"); + %fileObj.writeLine("slotCount = \x22" @ %slotCount @ "\x22;"); - //Compile Inventory List - %slotCount = %player.weaponSlotCount; - %healthKits = %player.invRepairKit; - %fileObj.writeLine("[Inventory]"); - %fileObj.writeLine("slotCount = \x22" @ %slotCount @ "\x22;"); + for (%i = 0; %i < %slotCount; %i++) + { + %weaponName = %player.weaponSlot[%i]; + %weaponAmmo = eval("%weaponAmmo = %player.inv" @ %weaponName @ "Ammo" @ ";"); + %fileObj.writeLine("slot" @ %i SPC "= \x22" @ %weaponName @ "\x22;"); + %fileObj.writeLine("slot" @ %i @ "Ammo" SPC "= \x22" @ %weaponAmmo @ "\x22;"); + } - for (%i = 0; %i < %slotCount; %i++) - { - %weaponName = %player.weaponSlot[%i]; - %weaponAmmo = eval("%weaponAmmo = %player.inv" @ %weaponName @ "Ammo" @ ";"); - %fileObj.writeLine("slot" @ %i SPC "= \x22" @ %weaponName @ "\x22;"); - %fileObj.writeLine("slot" @ %i @ "Ammo" SPC "= \x22" @ %weaponAmmo @ "\x22;"); - } - - %fileObj.writeLine("healthKits = \x22" @ %healthKits @ "\x22;"); - - %fileObj.detach(); - logEcho(" -- Save File Written for Player:" SPC %this.namebase SPC "--"); - return true; + %fileObj.writeLine("healthKits = \x22" @ %healthKits @ "\x22;"); + %fileObj.detach(); + logEcho(" -- Save File Written for Player:" SPC %this.namebase SPC "--"); + return true; } function gameConnection::applySaveFile(%this) { - //Compile Main Variable List - %mission = $CurrentMission; - %file = "data/game/saves/" @ %mission @ "/" @ %this.guid @ ".txt"; - - if (!isFile(%file)) - return false; - - %transform = getBlockData(%file,"Character",1,"transform"); - %velocity = getBlockData(%file,"Character",1,"velocity"); - %damage = getBlockData(%file,"Character",1,"damage"); - %race = getBlockData(%file,"Character",1,"race"); - %armor = getBlockData(%file,"Character",1,"armor"); - %energy = getBlockData(%file,"Character",1,"energyLevel"); - %whiteout = getBlockData(%file,"Character",1,"whiteOut"); - %damageFlash = getBlockData(%file,"Character",1,"damageFlash"); - %cash = getBlockData(%file,"Character",1,"cash"); - %hasRadio = getBlockData(%file,"Character",1,"hasRadio"); - %underStandsHuman = getBlockData(%file,"Character",1,"underStandsHuman"); - %underStandsBioderm = getBlockData(%file,"Character",1,"underStandsBioderm"); - %underStandsDraakan = getBlockData(%file,"Character",1,"underStandsDraakan"); - %underStandsCriollos = getBlockData(%file,"Character",1,"underStandsCriollos"); - - %player = %this.player; - %player.setTransform(%transform); - %player.setVelocity(%velocity); - %player.applyDamage(%damage); - %player.setArmor(%armor); - %player.setEnergyLevel(%energy); - %player.setWhiteout(%whiteOut); - %player.setDamageFlash(%damageFlash); - %this.cash = %cash; - %this.underStandsHuman = %underStandsHuman; - %this.underStandsBioderm = %underStandsBioderm; - %this.underStandsDraakan = %underStandsDraakan; - %this.underStandsCriollos = %underStandsCriollos; + //Compile Main Variable List + %mission = $CurrentMission; + %file = "data/game/saves/" @ %mission @ "/" @ %this.guid @ ".txt"; + + if (!isFile(%file)) + return false; + + %transform = getBlockData(%file,"Character",1,"transform"); + %velocity = getBlockData(%file,"Character",1,"velocity"); + %damage = getBlockData(%file,"Character",1,"damage"); + %race = getBlockData(%file,"Character",1,"race"); + %armor = getBlockData(%file,"Character",1,"armor"); + %energy = getBlockData(%file,"Character",1,"energyLevel"); + %whiteout = getBlockData(%file,"Character",1,"whiteOut"); + %damageFlash = getBlockData(%file,"Character",1,"damageFlash"); + %cash = getBlockData(%file,"Character",1,"cash"); + %hasRadio = getBlockData(%file,"Character",1,"hasRadio"); + %underStandsHuman = getBlockData(%file,"Character",1,"underStandsHuman"); + %underStandsBioderm = getBlockData(%file,"Character",1,"underStandsBioderm"); + %underStandsDraakan = getBlockData(%file,"Character",1,"underStandsDraakan"); + %underStandsCriollos = getBlockData(%file,"Character",1,"underStandsCriollos"); + + %player = %this.player; + %player.setTransform(%transform); + %player.setVelocity(%velocity); + %player.applyDamage(%damage); + %player.setArmor(%armor); + %player.setEnergyLevel(%energy); + %player.setWhiteout(%whiteOut); + %player.setDamageFlash(%damageFlash); + %this.cash = %cash; + %this.underStandsHuman = %underStandsHuman; + %this.underStandsBioderm = %underStandsBioderm; + %this.underStandsDraakan = %underStandsDraakan; + %this.underStandsCriollos = %underStandsCriollos; - return true; - for (%i = 0; %i < %slotCount; %i++) - { - %weaponName = %player.weaponSlot[%i]; - %weaponAmmo = eval("%weaponAmmo = %player.inv" @ %weaponName @ "Ammo" @ ";"); - %fileObj.writeLine("slot" @ %i SPC "= \x22" @ %weaponName @ "\x22;"); - %fileObj.writeLine("slot" @ %i @ "Ammo" SPC "= \x22" @ %weaponAmmo @ "\x22;"); - } + return true; + for (%i = 0; %i < %slotCount; %i++) + { + %weaponName = %player.weaponSlot[%i]; + %weaponAmmo = eval("%weaponAmmo = %player.inv" @ %weaponName @ "Ammo" @ ";"); + %fileObj.writeLine("slot" @ %i SPC "= \x22" @ %weaponName @ "\x22;"); + %fileObj.writeLine("slot" @ %i @ "Ammo" SPC "= \x22" @ %weaponAmmo @ "\x22;"); + } - %fileObj.writeLine("healthKits = \x22" @ %healthKits @ "\x22;"); + %fileObj.writeLine("healthKits = \x22" @ %healthKits @ "\x22;"); + return; } // Generic Import Functions function importGameData() { - importGems(); - importOres(); - importCharacters(); - return true; + importGems(); + importOres(); + importCharacters(); + return true; } // Gem Import Functions function importGems() { - if (!IsObject(GemData)) - { - new ScriptObject(GemData); + if (!IsObject(GemData)) + { + new ScriptObject(GemData); - if (!IsObject(GameData)) - new simGroup(GameData); + if (!IsObject(GameData)) + new simGroup(GameData); - GameData.add(GemData); - } - else - return true; + GameData.add(GemData); + } + else + return true; - %file = "data/game/gems.txt"; - %count = getBlockCount(%file,"Gem") + 1; + %file = "data/game/gems.txt"; + %count = getBlockCount(%file,"Gem") + 1; - for (%i = 1; %i < %count; %i++) - { - %name = getBlockData(%file,"Gem",%i,"Name"); - %price = getBlockData(%file,"Gem",%i,"Price"); - %sellPrice = getBlockData(%file,"Gem",%i,"SellPrice"); - - GemData.gem[%i] = %name; - GemData.price[%name] = %price; - GemData.sellPrice[%name] = %sellPrice; - warn("Imported gem:" SPC %name); - } - GemData.gemCount = %count--; -} + for (%i = 1; %i < %count; %i++) + { + %name = getBlockData(%file,"Gem",%i,"Name"); + %price = getBlockData(%file,"Gem",%i,"Price"); + %sellPrice = getBlockData(%file,"Gem",%i,"SellPrice"); + + GemData.gem[%i] = %name; + GemData.price[%name] = %price; + GemData.sellPrice[%name] = %sellPrice; + warn("Imported gem:" SPC %name); + + GemData.gemCount = %count--; + } // Ore Import Functions function importOres() { - if (!IsObject(OreData)) - { - new ScriptObject(OreData); + if (!IsObject(OreData)) + { + new ScriptObject(OreData); - if (!IsObject(GameData)) - new simGroup(GameData); + if (!IsObject(GameData)) + new simGroup(GameData); - GameData.add(OreData); - } - else - return true; + GameData.add(OreData); + } + else + return true; - %file = "data/game/ores.txt"; - %count = getBlockCount(%file,"Ore") + 1; + %file = "data/game/ores.txt"; + %count = getBlockCount(%file,"Ore") + 1; - for (%i = 1; %i < %count; %i++) - { - %name = getBlockData(%file,"Ore",%i,"Name"); - %price = getBlockData(%file,"Ore",%i,"Price"); - %sellPrice = getBlockData(%file,"Ore",%i,"SellPrice"); + for (%i = 1; %i < %count; %i++) + { + %name = getBlockData(%file,"Ore",%i,"Name"); + %price = getBlockData(%file,"Ore",%i,"Price"); + %sellPrice = getBlockData(%file,"Ore",%i,"SellPrice"); - OreData.ore[%i] = %name; - OreData.price[%name] = %price; - OreData.sellPrice[%name] = %sellPrice; - warn("Imported ore:" SPC %name); - } - OreData.oreCount = %count--; + OreData.ore[%i] = %name; + OreData.price[%name] = %price; + OreData.sellPrice[%name] = %sellPrice; + warn("Imported ore:" SPC %name); + } + OreData.oreCount = %count--; } // Character Import Functions function spawnCharacter(%name,%trans,%aimPos,%team) { - %object = "Character" @ %name; - - if (!IsObject(%object)) - return false; - - %Bname = %object.name; - %race = %object.race; - %skin = %object.skin; - %voice = %object.voice; - %voicePitch = %object.voicePitch; - %sex = %object.sex; - - %bot = aiConnectByName(%Bname,%team); - %bot.race = %race; - %bot.skin = addTaggedString(%skin); - %bot.voice = %voice; - %bot.voiceTag = addTaggedString(%voice); - %bot.voicePitch = %voicePitch; - %bot.sex = %sex; - setVoice(%bot,%voice, %voicePitch); - setSkin(%bot,%skin); - setSkin(%bot,%skin); - setTeam(%bot, %team); - %bot.player.setArmor("light"); - %bot.player.setTransform(%trans); - %bot.aimAt(%aimPos); - warn("Spawned Character:" SPC %name); + %object = "Character" @ %name; + + if (!IsObject(%object)) + return false; + + %Bname = %object.name; + %race = %object.race; + %skin = %object.skin; + %voice = %object.voice; + %voicePitch = %object.voicePitch; + %sex = %object.sex; + + %bot = aiConnectByName(%Bname,%team); + %bot.race = %race; + %bot.skin = addTaggedString(%skin); + %bot.voice = %voice; + %bot.voiceTag = addTaggedString(%voice); + %bot.voicePitch = %voicePitch; + %bot.sex = %sex; + setVoice(%bot,%voice, %voicePitch); + setSkin(%bot,%skin); + setSkin(%bot,%skin); + setTeam(%bot, %team); + %bot.player.setArmor("light"); + %bot.player.setTransform(%trans); + %bot.aimAt(%aimPos); + warn("Spawned Character:" SPC %name); } function importCharacters() { - %path = "data/game/characters/*.txt"; - for( %file = findFirstFile( %path ); %file !$= ""; %file = findNextFile( %path ) ) - { - %name = getFileNameFromString(%file); - %pos = strStr(%name,"."); - %character = getSubStr(%name,0,%pos); - importCharacter(%character); - } + %path = "data/game/characters/*.txt"; + for( %file = findFirstFile( %path ); %file !$= ""; %file = findNextFile( %path ) ) + { + %name = getFileNameFromString(%file); + %pos = strStr(%name,"."); + %character = getSubStr(%name,0,%pos); + importCharacter(%character); + } } function importCharacter(%character) { - %prefix = "data/game/characters/"; - %file = %prefix @ %character @ ".txt"; - %charName = %character; - %character = strReplace("Character" @ %character," ","_"); + %prefix = "data/game/characters/"; + %file = %prefix @ %character @ ".txt"; + %charName = %character; + %character = strReplace("Character" @ %character," ","_"); - if (!IsFile(%file)) - return false; + if (!IsFile(%file)) + return false; - if (!IsObject(%character)) - { - new scriptObject(%character); + if (!IsObject(%character)) + { + new scriptObject(%character); + if (!IsObject(GameData)) + new simGroup(GameData); - if (!IsObject(GameData)) - new simGroup(GameData); + GameData.add(%character); + } + else + return true; - GameData.add(%character); - } - else - return true; + //Get our variable values ... + %name = getBlockData(%file,"Character",1,"Name"); + %race = getBlockData(%file,"Character",1,"Race"); + %sex = getBlockData(%file,"Character",1,"Sex"); + %skin = getBlockData(%file,"Character",1,"Skin"); + %voice = getBlockData(%file,"Character",1,"Voice"); + %voicePitch = getBlockData(%file,"Character",1,"VoicePitch"); - //Get our variable values ... - %name = getBlockData(%file,"Character",1,"Name"); - %race = getBlockData(%file,"Character",1,"Race"); - %sex = getBlockData(%file,"Character",1,"Sex"); - %skin = getBlockData(%file,"Character",1,"Skin"); - %voice = getBlockData(%file,"Character",1,"Voice"); - %voicePitch = getBlockData(%file,"Character",1,"VoicePitch"); + //Import Message Arrays ... and assign them + %arrayName[0] = "Death"; + %arrayName[1] = "Kill"; + %arrayName[2] = "Healed"; + %arrayCount = 3; - //Import Message Arrays ... and assign them - %arrayName[0] = "Death"; - %arrayName[1] = "Kill"; - %arrayName[2] = "Healed"; - %arrayCount = 3; - - for (%i = 0; %i < %arrayCount; %i++) - { - %arrayVariableName[%i] = %arrayName[%i] @ "MessageArray"; - for (%j = 0; %j < 100; %j++) - { - %arrayTest = getArrayData(%file,%arrayName[%i],%j); - if (%arrayTest !$= "}") - { - if (%j == 0) - %arrayData[%i] = %arrayData[%i] @ %arrayTest; - else - %arrayData[%i] = %arrayData[%i] @ "\t" @ %arrayTest; - } - else - break; - } - eval(%character @ "." @ %arrayVariableName[%i] SPC "= \x22" @ %arrayData[%i] @ "\x22;"); - } - - //Assign the variables now ... - %character.name = %name; - %character.race = %race; - %character.sex = %sex; - %character.skin = %skin; - %character.voice = %voice; - %character.voicePitch = %voicePitch; - warn("Imported Character:" SPC %charname); + for (%i = 0; %i < %arrayCount; %i++) + { + %arrayVariableName[%i] = %arrayName[%i] @ "MessageArray"; + for (%j = 0; %j < 100; %j++) + { + %arrayTest = getArrayData(%file,%arrayName[%i],%j); + if (%arrayTest !$= "}") + { + if (%j == 0) + %arrayData[%i] = %arrayData[%i] @ %arrayTest; + else + %arrayData[%i] = %arrayData[%i] @ "\t" @ %arrayTest; + } + else + break; + } + eval(%character @ "." @ %arrayVariableName[%i] SPC "= \x22" @ %arrayData[%i] @ "\x22;"); + } + //Assign the variables now ... + %character.name = %name; + %character.race = %race; + %character.sex = %sex; + %character.skin = %skin; + %character.voice = %voice; + %character.voicePitch = %voicePitch; + warn("Imported Character:" SPC %charname); } diff --git a/scripts/modScripts/server/looting.cs b/scripts/modScripts/server/looting.cs index 634299e..f75f674 100644 --- a/scripts/modScripts/server/looting.cs +++ b/scripts/modScripts/server/looting.cs @@ -38,70 +38,69 @@ datablock ItemData(Lootbag) function LootBagCheckForPickUp(%this) //Not sure why, loot bags won't do a T2 system pickup.. { -cancel(%this.loop); + cancel(%this.loop); -if (!IsObject(%this)) -return; + if (!IsObject(%this)) + return; -%count = MissionCleanUp.getCount(); + %count = MissionCleanUp.getCount(); -for(%i = 0; %i < %count; %i++) -{ -%test = MissionCleanUp.getObject(%i); + for(%i = 0; %i < %count; %i++) + { + %test = MissionCleanUp.getObject(%i); -if (%test.getClassName() $= "Player" && %test.getState() !$= "dead" && !%test.client.isAIControlled()) -{ -%dist = vectorDist(%this.getPosition(),%test.getPosition()); + if (%test.getClassName() $= "Player" && %test.getState() !$= "dead" && !%test.client.isAIControlled()) + { + %dist = vectorDist(%this.getPosition(),%test.getPosition()); -if (%dist < %this.getDatablock().pickUpRadius) -{ -LootBagPickedUp(%this,%test.client); -return; -} + if (%dist < %this.getDatablock().pickUpRadius) + { + LootBagPickedUp(%this,%test.client); + return; + } -%this.loop = schedule(100,0,"LootBagCheckForPickup",%this); -} -} + %this.loop = schedule(100,0,"LootBagCheckForPickup",%this); + } + } } function LootBagPickedUp(%this,%client) { -%db = %client.player.getDatablock(); //The player's datablock -%money = %this.money; //Monies? -%numItems = %this.numItems; //Giving out items. -%numAmmo = %this.numAmmo; //..Ammo too! -//Does the bag have money? -if (%money $= "") -%hasMoney = false; -else -%hasMoney = true; + %db = %client.player.getDatablock(); //The player's datablock + %money = %this.money; //Monies? + %numItems = %this.numItems; //Giving out items. + %numAmmo = %this.numAmmo; //..Ammo too! + //Does the bag have money? + if (%money $= "") + %hasMoney = false; + else + %hasMoney = true; -if (%money !$= "") -%client.money = %client.money + %money; //Give some monies. + if (%money !$= "") + %client.money = %client.money + %money; //Give some monies. -for (%i = 0; %i < %numItems; %i++) -{ -if (%db.max[%this.item[%i]] != 0) //Don't want people in light armor running around with mortars, do we? -{ -%client.player.setInventory(%this.item[%i],1); -%client.player.setInventory(%this.ammo[%i],%this.ammoNum[%i]); -} -} -%this.delete(); //Delete the bag. + for (%i = 0; %i < %numItems; %i++) + { + if (%db.max[%this.item[%i]] != 0) //Don't want people in light armor running around with mortars, do we? + { + %client.player.setInventory(%this.item[%i],1); + %client.player.setInventory(%this.ammo[%i],%this.ammoNum[%i]); + } + } + %this.delete(); //Delete the bag. -//Let the player know. -switch (%hasMoney) -{ -case 0: -if (%numItems > 1) -messageClient(%client,'MsgClient','You picked up a bag of items that contained %1 items.',%numitems); -else -messageClient(%client,'MsgClient','You picked up a bag of items that contained 1 item.'); -case 1: -if (%numItems > 1) -messageClient(%client,'MsgClient','You picked up a bag of items that contained $%1 and %2 items.',%money,%numitems); -else -messageClient(%client,'MsgClient','You picked up a bag of items that contained $%1 and 1 item.',%money); + //Let the player know. + switch (%hasMoney) + { + case 0: + if (%numItems > 1) + messageClient(%client,'MsgClient','You picked up a bag of items that contained %1 items.',%numitems); + else + messageClient(%client,'MsgClient','You picked up a bag of items that contained 1 item.'); + case 1: + if (%numItems > 1) + messageClient(%client,'MsgClient','You picked up a bag of items that contained $%1 and %2 items.',%money,%numitems); + else + messageClient(%client,'MsgClient','You picked up a bag of items that contained $%1 and 1 item.',%money); + } } -} - diff --git a/scripts/modScripts/server/mining.cs b/scripts/modScripts/server/mining.cs index 85603cb..d7d87c1 100644 --- a/scripts/modScripts/server/mining.cs +++ b/scripts/modScripts/server/mining.cs @@ -33,6 +33,6 @@ datablock StaticShapeData(MiningBox) : StaticShapeDamageProfile { // ----------------------------------------------------- function MiningBox::onAdd(%this, %obj) { - %obj.startFade(1,0,1); - %obj.applyDamage(%obj.getDataBlock().maxDamage); //Start the rock off + %obj.startFade(1,0,1); + %obj.applyDamage(%obj.getDataBlock().maxDamage); //Start the rock off } diff --git a/scripts/modScripts/server/propData.cs b/scripts/modScripts/server/propData.cs index bdde1ce..c9d742e 100644 --- a/scripts/modScripts/server/propData.cs +++ b/scripts/modScripts/server/propData.cs @@ -72,5 +72,5 @@ datablock StaticShapeData(DeployedSpine) : StaticShapeDamageProfile { //---------------------------------------------------------------------------- function DetructableSecurityCamera::onDestroyed(%this, %obj) { -schedule(1000,0,"delete",%obj); + schedule(1000,0,"delete",%obj); } diff --git a/scripts/modScripts/server/propertyOwning.cs b/scripts/modScripts/server/propertyOwning.cs index 7ab0d05..bc80f58 100644 --- a/scripts/modScripts/server/propertyOwning.cs +++ b/scripts/modScripts/server/propertyOwning.cs @@ -9,159 +9,149 @@ function InteriorInstance::buyObject(%this,%objectID,%client,%team) { -if (%this.generatorCount $= "") -%this.generatorCount = 0; -if (%this.inventoryCount $= "") -%this.inventoryCount = 0; -if (%this.sensorCount $= "") -%this.sensorCount = 0; -if (%this.sentryCount $= "") -%this.sentryCount = 0; -if (%this.bannerCount $= "") -%this.bannerCount = 0; -if (%this.turretBaseCount $= "") -%this.turretBaseCount = 0; + if (%this.generatorCount $= "") + %this.generatorCount = 0; + if (%this.inventoryCount $= "") + %this.inventoryCount = 0; + if (%this.sensorCount $= "") + %this.sensorCount = 0; + if (%this.sentryCount $= "") + %this.sentryCount = 0; + if (%this.bannerCount $= "") + %this.bannerCount = 0; + if (%this.turretBaseCount $= "") + %this.turretBaseCount = 0; -switch(%objectID) -{ - case 0: //Generator - if (%this.generatorCount == $Property::Max[%this.interiorFile,0]) - return false; + switch(%objectID) + { + case 0: //Generator + if (%this.generatorCount == $Property::Max[%this.interiorFile,0]) + return false; - %shape = new StaticShape() - { - DataBlock = GeneratorLarge; - Position = vectorAdd($Property::Offset[%this.interiorFile,0,%this.generatorCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,0,%this.generatorCount]; - Team = %team; - }; + %shape = new StaticShape() + { + DataBlock = GeneratorLarge; + Position = vectorAdd($Property::Offset[%this.interiorFile,0,%this.generatorCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,0,%this.generatorCount]; + Team = %team; + }; + + GeneratorLarge.gainPower(%shape); + %this.generatorCount++; - GeneratorLarge.gainPower(%shape); + case 1: //Inventory + if (%this.generatorCount == 0 || %this.inventoryCount == $Property::Max[%this.interiorFile,1]) //Don't create if there's no generators + return false; - %this.generatorCount++; + %shape = new StaticShape() + { + DataBlock = StationInventory; + Position = vectorAdd($Property::Offset[%this.interiorFile,1,%this.inventoryCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,1,%this.inventoryCount]; + Team = %team; + }; - case 1: //Inventory - if (%this.generatorCount == 0 || %this.inventoryCount == $Property::Max[%this.interiorFile,1]) //Don't create if there's no generators - return false; + StationInventory.gainPower(%shape); + %this.inventoryCount++; - %shape = new StaticShape() - { - DataBlock = StationInventory; - Position = vectorAdd($Property::Offset[%this.interiorFile,1,%this.inventoryCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,1,%this.inventoryCount]; - Team = %team; - }; + case 2: //Sensor (Medium) + if (%this.generatorCount == 0 || %this.sensorCount == $Property::Max[%this.interiorFile,2]) + return false; + + %shape = new StaticShape() + { + DataBlock = SensorMediumPulse; + Position = vectorAdd($Property::Offset[%this.interiorFile,2,%this.sensorCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,2,%this.sensorCount]; + Team = %team; + }; + SensorMediumPulse.gainPower(%shape); + %this.sensorCount++; - StationInventory.gainPower(%shape); + case 3: //Sensor (Large) + if (%this.generatorCount == 0 || %this.sensorCount == $Property::Max[%this.interiorFile,2]) + return false; - %this.inventoryCount++; + %shape = new StaticShape() + { + DataBlock = SensorLargePulse; + Position = vectorAdd($Property::Offset[%this.interiorFile,3,%this.sensorCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,3,%this.sensorCount]; + Team = %team; + }; + + SensorLargePulse.gainPower(%shape); + %this.sensorCount++; - case 2: //Sensor (Medium) - if (%this.generatorCount == 0 || %this.sensorCount == $Property::Max[%this.interiorFile,2]) - return false; + case 4: //Sentry Turrets + if (%this.generatorCount == 0 || %this.sentryCount == $Property::Max[%this.interiorFile,4]) + return false; - %shape = new StaticShape() - { - DataBlock = SensorMediumPulse; - Position = vectorAdd($Property::Offset[%this.interiorFile,2,%this.sensorCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,2,%this.sensorCount]; - Team = %team; - }; - - SensorMediumPulse.gainPower(%shape); - - %this.sensorCount++; + %shape = new StaticShape() + { + DataBlock = SentryTurret; + Position = vectorAdd($Property::Offset[%this.interiorFile,4,%this.sentryCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,4,%this.sentryCount]; + Team = %team; + }; + SentryTurret.gainPower(%shape); + %this.sentryCount++; + + case 5: //Banner (Strength) + if (%this.bannerCount == $Property::Max[%this.interiorFile,5]) + return false; + %shape = new StaticShape() + { + DataBlock = Banner_Strength; + Position = vectorAdd($Property::Offset[%this.interiorFile,5,%this.bannerCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,5,%this.bannerCount]; + Team = %team; + }; + %this.bannerCount++; - case 3: //Sensor (Large) - if (%this.generatorCount == 0 || %this.sensorCount == $Property::Max[%this.interiorFile,2]) - return false; + case 6: //Large Turret Base + if (%this.generatorCount == 0 || %this.turretBaseCount == $Property::Max[%this.interiorFile,6]) + return false; - %shape = new StaticShape() - { - DataBlock = SensorLargePulse; - Position = vectorAdd($Property::Offset[%this.interiorFile,3,%this.sensorCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,3,%this.sensorCount]; - Team = %team; - }; + %shape = new StaticShape() + { + DataBlock = TurretBaseLarge; + Position = vectorAdd($Property::Offset[%this.interiorFile,6,%this.turretBaseCount],%this.getPosition()); + Rotation = $Property::Rotation[%this.interiorFile,6,%this.turretBaseCount]; + Team = %team; + }; - SensorLargePulse.gainPower(%shape); + %this.turretBaseCount++; + } - %this.sensorCount++; - - case 4: //Sentry Turrets - if (%this.generatorCount == 0 || %this.sentryCount == $Property::Max[%this.interiorFile,4]) - return false; - - %shape = new StaticShape() - { - DataBlock = SentryTurret; - Position = vectorAdd($Property::Offset[%this.interiorFile,4,%this.sentryCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,4,%this.sentryCount]; - Team = %team; - }; - - SentryTurret.gainPower(%shape); - - %this.sentryCount++; - - case 5: //Banner (Strength) - if (%this.bannerCount == $Property::Max[%this.interiorFile,5]) - return false; - - %shape = new StaticShape() - { - DataBlock = Banner_Strength; - Position = vectorAdd($Property::Offset[%this.interiorFile,5,%this.bannerCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,5,%this.bannerCount]; - Team = %team; - }; - - %this.bannerCount++; - - case 6: //Large Turret Base - if (%this.generatorCount == 0 || %this.turretBaseCount == $Property::Max[%this.interiorFile,6]) - return false; - - %shape = new StaticShape() - { - DataBlock = TurretBaseLarge; - Position = vectorAdd($Property::Offset[%this.interiorFile,6,%this.turretBaseCount],%this.getPosition()); - Rotation = $Property::Rotation[%this.interiorFile,6,%this.turretBaseCount]; - Team = %team; - }; - - %this.turretBaseCount++; -} - -%this.getGroup().add(%shape); -setTargetName(%shape.target,addTaggedString(%client.namebase @ "'s")); -setTargetSensorGroup(%shape.getTarget(), %team); -%shape.setSelfPowered(); - -return %shape; + %this.getGroup().add(%shape); + setTargetName(%shape.target,addTaggedString(%client.namebase @ "'s")); + setTargetSensorGroup(%shape.getTarget(), %team); + %shape.setSelfPowered(); + return %shape; } function staticShape::setPosition(%this,%pos) { -%this.setTransform(%pos); -return %this; + %this.setTransform(%pos); + return %this; } function staticShape::getRotation(%this) { -%trans = %this.getTransform(); -return getWord(%trans, 3) SPC getWord(%trans, 4) SPC getWord(%trans,5); + %trans = %this.getTransform(); + return getWord(%trans, 3) SPC getWord(%trans, 4) SPC getWord(%trans,5); } function objectIDToDatablock(%objectID) { -switch(%objectID) -{ - case 0: return "GeneratorLarge"; - case 1: return 0; - default: return -1; -} -return -1; + switch(%objectID) + { + case 0: return "GeneratorLarge"; + case 1: return 0; + default: return -1; + } + return -1; } diff --git a/scripts/modScripts/server/serverFunctions.cs b/scripts/modScripts/server/serverFunctions.cs index d117450..efa3799 100644 --- a/scripts/modScripts/server/serverFunctions.cs +++ b/scripts/modScripts/server/serverFunctions.cs @@ -9,45 +9,45 @@ //This should be used if I make some sort of online System function setVoice(%client, %voice, %voicepitch) { - freeClientTarget(%client); - %client.voice = %voice; - %client.voicetag = addtaggedstring(%voice); - %client.target = allocClientTarget(%client, %client.name, %client.skin, %client.voiceTag, '_ClientConnection', 0, 0, %client.voicePitch); + freeClientTarget(%client); + %client.voice = %voice; + %client.voicetag = addtaggedstring(%voice); + %client.target = allocClientTarget(%client, %client.name, %client.skin, %client.voiceTag, '_ClientConnection', 0, 0, %client.voicePitch); - if (IsObject(%client.player)) - %client.player.setTarget(%client.target); + if (IsObject(%client.player)) + %client.player.setTarget(%client.target); } function setSkin(%client, %skin) { - freeClientTarget(%client); - %client.skin = addtaggedstring(%skin); - %client.target = allocClientTarget(%client, %client.name, %client.skin, %client.voiceTag, '_ClientConnection', 0, 0, %client.voicePitch); + freeClientTarget(%client); + %client.skin = addtaggedstring(%skin); + %client.target = allocClientTarget(%client, %client.name, %client.skin, %client.voiceTag, '_ClientConnection', 0, 0, %client.voicePitch); - if (IsObject(%client.player)) - %client.player.setTarget(%client.target); + if (IsObject(%client.player)) + %client.player.setTarget(%client.target); } function setName(%client, %name) { - freeClientTarget(%client); - %client.namebase = %name; - %client.name = addtaggedstring(%name); - %client.target = allocClientTarget(%client, %client.name, %client.skin, %client.voiceTag, '_ClientConnection', 0, 0, %client.voicePitch); + freeClientTarget(%client); + %client.namebase = %name; + %client.name = addtaggedstring(%name); + %client.target = allocClientTarget(%client, %client.name, %client.skin, %client.voiceTag, '_ClientConnection', 0, 0, %client.voicePitch); - if (IsObject(%client.player)) - %client.player.setTarget(%client.target); + if (IsObject(%client.player)) + %client.player.setTarget(%client.target); - //Update the client in the lobby. - HideClient(%client); - ShowClient(%client); + //Update the client in the lobby. + HideClient(%client); + ShowClient(%client); } function setTeam(%client,%team) { - %client.team = %team; - %client.setSensorGroup(%team); - setTargetSensorGroup(%client.target,%team); + %client.team = %team; + %client.setSensorGroup(%team); + setTargetSensorGroup(%client.target,%team); } diff --git a/scripts/modScripts/server/serverNetworking.cs b/scripts/modScripts/server/serverNetworking.cs index 3f44dfe..065a962 100644 --- a/scripts/modScripts/server/serverNetworking.cs +++ b/scripts/modScripts/server/serverNetworking.cs @@ -11,13 +11,13 @@ function ServerNetwork::onConnect(%this) function ServerNetwork::onConnectFailed(%this) { - if (%this.testingServer) - { - error("Error: Unable to verify connection to server "@%this.testIP@" at port "@%this.testPort@"!"); - %this.testIP = ""; - %this.testPort = ""; - %this.testingServer = false; - } + if (%this.testingServer) + { + error("Error: Unable to verify connection to server "@%this.testIP@" at port "@%this.testPort@"!"); + %this.testIP = ""; + %this.testPort = ""; + %this.testingServer = false; + } } function ServerNetwork::onDisconnect(%this) @@ -42,8 +42,8 @@ function ServerNetwork::onLine(%this, %line) function ServerNetwork::testServerIP(%this, %IP, %port) { - %this.testingServer = true; - %this.testIP = %ip; - %this.testPort = %port; - %this.connect(%ip @ ":" @ %port); + %this.testingServer = true; + %this.testIP = %ip; + %this.testPort = %port; + %this.connect(%ip @ ":" @ %port); } diff --git a/scripts/modScripts/shared/basicDataStorage.cs b/scripts/modScripts/shared/basicDataStorage.cs index c9d5518..da687f9 100644 --- a/scripts/modScripts/shared/basicDataStorage.cs +++ b/scripts/modScripts/shared/basicDataStorage.cs @@ -3,91 +3,90 @@ // ----------------------------------------------------- function getBlockCount(%file,%blockName) //Searches a data file for all occurances of 'blockName' { -if (!IsFile(%file)) -return false; + if (!IsFile(%file)) + return false; -%blockSearch = strLwr("[" @ %blockName @ "]"); + %blockSearch = strLwr("[" @ %blockName @ "]"); -%fileP = new FileObject(); -%fileP.openForRead(%file); + %fileP = new FileObject(); + %fileP.openForRead(%file); -%count = 0; - while (!%fileP.isEOF()) - { - %line = %fileP.readLine(); - %lineTest = strLwr(%line); - %Search = strStr(%lineTest,%blockSearch); - if (%search != -1) - %count++; - } -%fileP.detach(); -return %count; + %count = 0; + while (!%fileP.isEOF()) + { + %line = %fileP.readLine(); + %lineTest = strLwr(%line); + %Search = strStr(%lineTest,%blockSearch); + if (%search != -1) + %count++; + } + %fileP.detach(); + return %count; } function getBlockData(%file,%blockName,%num,%data) //Gets values out of a block. Note that 1 is the first block in a file for %num { -if (!IsFile(%file)) -return false; + if (!IsFile(%file)) + return false; -%blockCount = getBlockCount(%file,%blockName); + %blockCount = getBlockCount(%file,%blockName); -if (!%blockCount || %num > %blockCount) //None of 'typeName' exist here -return -1; + if (!%blockCount || %num > %blockCount) //None of 'typeName' exist here + return -1; -%blockSearch = strLwr("[" @ %blockName @ "]"); + %blockSearch = strLwr("[" @ %blockName @ "]"); -%fileP = new FileObject(); -%fileP.openForRead(%file); + %fileP = new FileObject(); + %fileP.openForRead(%file); -%count = 0; -%lineCount = 0; - while (!%fileP.isEOF()) - { - %line = %fileP.readLine(); - %lineCount++; - - if (getSubStr(stripSpaces(%line),0,1) !$= ";") //If the beginning of the line is "commented", skip it. - { - %lineTest = strLwr(%line); - %Search = strStr(%lineTest,%blockSearch); + %count = 0; + %lineCount = 0; + while (!%fileP.isEOF()) + { + %line = %fileP.readLine(); + %lineCount++; + + if (getSubStr(stripSpaces(%line),0,1) !$= ";") //If the beginning of the line is "commented", skip it. + { + %lineTest = strLwr(%line); + %Search = strStr(%lineTest,%blockSearch); - if (%Search != -1 && %Count != %num) - %count++; - else if (%count == %num) //We found it, stop incrementing the count and find our data. - { - %Search = strStr(strLwr(%line),strLwr(%data)); + if (%Search != -1 && %Count != %num) + %count++; + else if (%count == %num) //We found it, stop incrementing the count and find our data. + { + %Search = strStr(strLwr(%line),strLwr(%data)); - %lineTest = strLwr(strReplace(%line," ","")); //See if we exited our block - if (GetSubStr(%lineTest, 0, 1) $= "[") //The beginning of a new block - return -1; + %lineTest = strLwr(strReplace(%line," ","")); //See if we exited our block + if (GetSubStr(%lineTest, 0, 1) $= "[") //The beginning of a new block + return -1; - if (%search != -1) //We found it, - { - %fileP.detach(); + if (%search != -1) //We found it, + { + %fileP.detach(); - //Since our line might have some sort of commenting after it, we better return to just the "end" symbol.. - %semiS =strStr(%line, ";"); - if (%semiS == -1) - return -1; - %line = getSubStr(%line, 0, %semiS); - //Now find where "equals" is.. - %equalS = strStr(%line, "="); - if (%equalS == -1) - return -1; - %line = getSubStr(%line, %equalS+1, strLen(%line)); - //Is our data in single quotations? If so, convert it to a tagged string. - if (strStr(%line,"\x27") != -1) //It is. - %line = addTaggedString(stripChars(%line,"\x27")); - //Now return our string without quotations. - %line = stripChars(stripTrailingSpaces(strReplace(%line,%data,"")),"\x22"); - return getSubStr(%line,1,strLen(%line)); - } - } - } - } - -%fileP.detach(); -return false; + //Since our line might have some sort of commenting after it, we better return to just the "end" symbol.. + %semiS =strStr(%line, ";"); + if (%semiS == -1) + return -1; + %line = getSubStr(%line, 0, %semiS); + //Now find where "equals" is.. + %equalS = strStr(%line, "="); + if (%equalS == -1) + return -1; + %line = getSubStr(%line, %equalS+1, strLen(%line)); + //Is our data in single quotations? If so, convert it to a tagged string. + if (strStr(%line,"\x27") != -1) //It is. + %line = addTaggedString(stripChars(%line,"\x27")); + //Now return our string without quotations. + %line = stripChars(stripTrailingSpaces(strReplace(%line,%data,"")),"\x22"); + return getSubStr(%line,1,strLen(%line)); + } + } + } + } + %fileP.detach(); + return false; } //function getBlockLength(%file,%blockName,%num) Won't work until I figure out a way to signal the end of a block without adding any extra characters, @@ -127,81 +126,76 @@ return false; // ----------------------------------------------------- function getArrayCount(%file,%array) { -if (!IsFile(%file)) -return false; + if (!IsFile(%file)) + return false; -%arraySearch = strLwr("\x22" @ %array @ "\x22"); + %arraySearch = strLwr("\x22" @ %array @ "\x22"); -%fileP = new FileObject(); -%fileP.openForRead(%file); + %fileP = new FileObject(); + %fileP.openForRead(%file); -%count = 0; - while (!%fileP.isEOF()) - { - %line = %fileP.readLine(); - %lineTest = strLwr(%line); - %Search = strStr(%lineTest,%typeSearch); - if (%search != -1) - %count++; - } -%fileP.detach(); -return %count; + %count = 0; + while (!%fileP.isEOF()) + { + %line = %fileP.readLine(); + %lineTest = strLwr(%line); + %Search = strStr(%lineTest,%typeSearch); + if (%search != -1) + %count++; + } + %fileP.detach(); + return %count; } function getArrayData(%file,%arrayName,%num) { -if (!IsFile(%file)) -return false; + if (!IsFile(%file)) + return false; -%arrayCount = getArrayCount(%file,%arrayName); + %arrayCount = getArrayCount(%file,%arrayName); -if (!%arrayCount) -return false; + if (!%arrayCount) + return false; -%arraySearch = strLwr("\x22" @ %arrayName @ "\x22"); + %arraySearch = strLwr("\x22" @ %arrayName @ "\x22"); -%fileP = new FileObject(); -%fileP.openForRead(%file); + %fileP = new FileObject(); + %fileP.openForRead(%file); -%lineCount = 0; - while (!%fileP.isEOF()) - { - %line = stripSpaces(%fileP.readline()); - %lineCount++; + %lineCount = 0; + while (!%fileP.isEOF()) + { + %line = stripSpaces(%fileP.readline()); + %lineCount++; - if (getSubStr(%line,0,1) !$= ";") //Is this line a comment? - { - %search = strStr(strLwr(%line),%arraySearch); + if (getSubStr(%line,0,1) !$= ";") //Is this line a comment? + { + %search = strStr(strLwr(%line),%arraySearch); - if (%search !$= -1) //Found it. - break; //Break the loop, we know the array exists - if (%fileP.IsEOF() && %search == -1) //Didn't find it, return the error. - return false; - } - } + if (%search !$= -1) //Found it. + break; //Break the loop, we know the array exists + if (%fileP.IsEOF() && %search == -1) //Didn't find it, return the error. + return false; + } + } -//Check where the array actually starts.. -%line = %fileP.readLine(); - if (%line $= "{") //Data starts on next line.. - { - %line = %fileP.readLine(); //Drop it down one - for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data - { - %line = %fileP.readLine(); - } + //Check where the array actually starts.. + %line = %fileP.readLine(); + if (%line $= "{") //Data starts on next line.. + { + %line = %fileP.readLine(); //Drop it down one + for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data + %line = %fileP.readLine(); + } + else //The line we just grabbed is part of the data + { + if (%num == 0) //The wanted data was on line zero.. + return %line; + + for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data + %line = %fileP.readLine(); + } + + %fileP.detach(); + return %line; } -else //The line we just grabbed is part of the data -{ -if (%num == 0) //The wanted data was on line zero.. -return %line; - - for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data - { - %line = %fileP.readLine(); - } -} - -%fileP.detach(); -return %line; -} - diff --git a/scripts/modScripts/shared/fileProcessing.cs b/scripts/modScripts/shared/fileProcessing.cs index beff75e..5f32c97 100644 --- a/scripts/modScripts/shared/fileProcessing.cs +++ b/scripts/modScripts/shared/fileProcessing.cs @@ -1,54 +1,48 @@ // ----------------------------------------------------- +// fileProcessing.cs // Basic file functions +// Copyright (c) 2012 The DarkDragonDX // ----------------------------------------------------- function getFileBuffer(%file) { -if (!IsFile(%file)) -return "Not existant."; + if (!IsFile(%file)) + return "Not existant."; -new FileObject(FileBuffer); -FileBuffer.openForRead(%file); + new FileObject(FileBuffer); + FileBuffer.openForRead(%file); - while (!FileBuffer.isEOF()) - { - %buffer = FileBuffer.readLine() @ "\n"; - } -FileBuffer.detach(); -return %buffer; //Long string. >.> + while (!FileBuffer.isEOF()) + %buffer = FileBuffer.readLine() @ "\n"; + FileBuffer.detach(); + return %buffer; //Long string. >.> } function getLine(%file, %line) { -if (!IsFile(%file)) -return "Not existant."; + if (!IsFile(%file)) + return "Not existant."; -new FileObject(FileLine); -FileLine.openForRead(%file); + new FileObject(FileLine); + FileLine.openForRead(%file); - for (%i = 0; %i < %line; %i++) - { - %line = FileLine.readLine(); - } -FileLine.detach(); - -return %line; + for (%i = 0; %i < %line; %i++) + %line = FileLine.readLine(); + FileLine.detach(); + return %line; } function getLine(%file, %line) { -if (!IsFile(%file)) -return "Not existant."; + if (!IsFile(%file)) + return "Not existant."; -new FileObject(FileLine); -FileLine.openForRead(%file); + new FileObject(FileLine); + FileLine.openForRead(%file); - for (%i = 0; %i < %line; %i++) - { - %line = FileLine.readLine(); - } -FileLine.detach(); - -return %line; + for (%i = 0; %i < %line; %i++) + %line = FileLine.readLine(); + FileLine.detach(); + return %line; } // ----------------------------------------------------- @@ -56,9 +50,9 @@ return %line; // ----------------------------------------------------- function fileObject::Detach(%this) //Detaches fileObject from file & deletes { -%this.close(); -%this.delete(); -return %this; + %this.close(); + %this.delete(); + return %this; } diff --git a/scripts/modScripts/shared/initialize.cs b/scripts/modScripts/shared/initialize.cs index 2371856..1acfaca 100644 --- a/scripts/modScripts/shared/initialize.cs +++ b/scripts/modScripts/shared/initialize.cs @@ -1,9 +1,10 @@ //------------------------------------------------------------------------------ +// initialise.cs // Shared Functions for T2Bol +// Copyright (c) 2012 The DarkDragonDX //============================================================================== exec("scripts/modScripts/shared/stringProcessing.cs"); exec("scripts/modScripts/shared/fileProcessing.cs"); -exec("scripts/modScripts/shared/numericProcessing.cs"); exec("scripts/modScripts/shared/basicDataStorage.cs"); diff --git a/scripts/modScripts/shared/numericProcessing.cs b/scripts/modScripts/shared/numericProcessing.cs deleted file mode 100644 index 0ea09ef..0000000 --- a/scripts/modScripts/shared/numericProcessing.cs +++ /dev/null @@ -1,14 +0,0 @@ -// ----------------------------------------------------- -// Number Processing -// ----------------------------------------------------- -function decimalToPercent(%decimal) //Doesn't work very nicely at the time.. probably won't be used after a bit -{ -return %decimal * 100; -} - -function isDecimal(%num) -{ -return strStr(%num,"."); -} - - diff --git a/scripts/modScripts/shared/stringProcessing.cs b/scripts/modScripts/shared/stringProcessing.cs index 5bf0f49..263c8eb 100644 --- a/scripts/modScripts/shared/stringProcessing.cs +++ b/scripts/modScripts/shared/stringProcessing.cs @@ -1,13 +1,19 @@ +//------------------------------------------------------------------------------ +// stringProcessing.cs +// String functions +// Copyright (c) 2012 The DarkDragonDX +//------------------------------------------------------------------------------ + //------------------------------------------------------------------------------ function textToHash(%text) { -new fileObject(TextToHash); -TextToHash.openForWrite("Hash.txt"); -TextToHash.writeLine(%text); -TextToHash.detach(); -%hash = getFileCRC("Hash.txt"); -deleteFile("Hash.txt"); -return %hash; + new fileObject(TextToHash); + TextToHash.openForWrite("Hash.txt"); + TextToHash.writeLine(%text); + TextToHash.detach(); + %hash = getFileCRC("Hash.txt"); + deleteFile("Hash.txt"); + return %hash; } //------------------------------------------------------------------------------ @@ -15,14 +21,11 @@ return %hash; //------------------------------------------------------------------------------ function strReverse(%string) { -%len = StrLen(%string); -%rstring = ""; - -for (%i = 0; %i < %len; %i++) -{ -%rstring = getSubStr(%string,%i,1) @ %rstring; -} -return %rstring; + %len = StrLen(%string); + %rstring = ""; + for (%i = 0; %i < %len; %i++) + %rstring = getSubStr(%string,%i,1) @ %rstring; + return %rstring; } //------------------------------------------------------------------------------ @@ -30,11 +33,10 @@ return %rstring; //------------------------------------------------------------------------------ function subStrInsert(%string,%insert,%slot) { -%seg = getSubStr(%string,0,%slot); -%seg = %seg @ %insert; -%string = %seg @ getSubStr(%string,%slot,strLen(%string)); - -return %string; + %seg = getSubStr(%string,0,%slot); + %seg = %seg @ %insert; + %string = %seg @ getSubStr(%string,%slot,strLen(%string)); + return %string; } //------------------------------------------------------------------------------ @@ -42,9 +44,9 @@ return %string; //------------------------------------------------------------------------------ function subStrRemove(%string,%slot)//Minimum: 1 { -%half2 = getSubStr(%string,%slot,strLen(%string)); -%half1 = getSubStr(%string,0,%slot-1); -return %half1 @ %half2; + %half2 = getSubStr(%string,%slot,strLen(%string)); + %half1 = getSubStr(%string,0,%slot-1); + return %half1 @ %half2; } //------------------------------------------------------------------------------ @@ -52,15 +54,13 @@ return %half1 @ %half2; //------------------------------------------------------------------------------ function strMove(%string,%factor) { -%len = GetWordCount(%string); - -for (%i = 0; %i < %len; %i++) -{ - %sub = getWord(%string,%i); - %move = subStrInsert(%move,%sub,%i); -} - -return %move; + %len = GetWordCount(%string); + for (%i = 0; %i < %len; %i++) + { + %sub = getWord(%string,%i); + %move = subStrInsert(%move,%sub,%i); + } + return %move; } //------------------------------------------------------------------------------ @@ -68,15 +68,13 @@ return %move; //------------------------------------------------------------------------------ function subStrMove(%string,%factor) { -%len = strLen(%string); - -for (%i = 0; %i < %len; %i++) -{ - %sub = getSubStr(%string,%i,1); - %move = subStrInsert(%move,%sub,%factor); -} - -return %move; + %len = strLen(%string); + for (%i = 0; %i < %len; %i++) + { + %sub = getSubStr(%string,%i,1); + %move = subStrInsert(%move,%sub,%factor); + } + return %move; } //------------------------------------------------------------------------------ @@ -84,25 +82,22 @@ return %move; //------------------------------------------------------------------------------ function subStrScramble(%string) { -%len = strLen(%string); - -for (%i = 0; %i < %len; %i++) -{ - %sub = getSubStr(%string,%i,1); - %scramble = subStrInsert(%scramble,%sub,getRandom(0,%len)); -} - -return %scramble; + %len = strLen(%string); + for (%i = 0; %i < %len; %i++) + { + %sub = getSubStr(%string,%i,1); + %scramble = subStrInsert(%scramble,%sub,getRandom(0,%len)); + } + return %scramble; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ function strSplit(%string) { -%count = strLen(%string); -%div = %count / 2; - -return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count); + %count = strLen(%string); + %div = %count / 2; + return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count); } //------------------------------------------------------------------------------ @@ -110,7 +105,7 @@ return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count); //------------------------------------------------------------------------------ function stripSpaces(%string) { -return strReplace(%string," ",""); + return strReplace(%string," ",""); } //------------------------------------------------------------------------------ @@ -118,8 +113,8 @@ return strReplace(%string," ",""); //------------------------------------------------------------------------------ function stripNonNumericCharacters(%string) { -%string = strLwr(%string); -return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>,<;:"); + %string = strLwr(%string); + return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>,<;:"); } //------------------------------------------------------------------------------ @@ -127,41 +122,39 @@ return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>, //------------------------------------------------------------------------------ function getSubStrOccurance(%string,%search) { -%len = strLen(%string); -%srLen = strLen(%search); -%count = 0; -for (%i = 0; %i < %len; %i++) -{ - %strSearch = strStr(%string,%search); - - if (%strSearch != -1) //It exists somewhere in the string - { - %count++; - %string = getSubStr(%string,%strSearch+%srLen,%len); - } - else - return %count; -} -return %count; + %len = strLen(%string); + %srLen = strLen(%search); + %count = 0; + for (%i = 0; %i < %len; %i++) + { + %strSearch = strStr(%string,%search); + if (%strSearch != -1) //It exists somewhere in the string + { + %count++; + %string = getSubStr(%string,%strSearch+%srLen,%len); + } + else + return %count; + } + return %count; } function getSubStrPos(%string,%str,%num) { -%len = strLen(%string); - -%subC = 0; - for (%i = 0; %i < %len; %i++) - { - %sub = getSubStr(%string,%i,1); + %len = strLen(%string); + %subC = 0; + for (%i = 0; %i < %len; %i++) + { + %sub = getSubStr(%string,%i,1); - if (%sub $= %str) - { - %subC++; - if (%subC == %num) - break; - } - } -return %i; + if (%sub $= %str) + { + %subC++; + if (%subC == %num) + break; + } + } + return %i; } //------------------------------------------------------------------------------ @@ -169,7 +162,7 @@ return %i; //------------------------------------------------------------------------------ function getFileNameFromString(%string) { -return getSubStr(%string,getSubStrPos(%string,"/",getSubStrOccurance(%string, "/"))+1,strLen(%string)); + return getSubStr(%string,getSubStrPos(%string,"/",getSubStrOccurance(%string, "/"))+1,strLen(%string)); } //------------------------------------------------------------------------------