Scriptperformance dezentralisierung kontra zentralisierung | |
Ich schreibe eine etwas aufwändigere Modifikation die einiges an Scripten fordert.
Die habe ich auch größtenteils schon fertig doch jetzt stellt sich mir eine Performancefrage.
Ist es besser möglichst viel in ein Script zu packen (weniger globale Variablen, weniger Scripte im speicher) oder es zu dezentralisieren wie es immoment ist (gibt schneller ein return). Dazu sollte man sagen, alle Scripte laufen die ganze Zeit, natürlich nicht völlig durch.
Insgesamt sind es immoment so um die 1000 Zeilen Code.
Immoment sieht das so aus:
Kursiv die globalen Variablen (alle short es sei denn es steht anders dabei).
Kommt noch einiges an Kram zu.
//EDIT//
Natürlich hier die Scripts (sorry für die Länge):
code: ScriptName MadCityBudget
; this script edits the city's budget
; VERSION 1.0 ALPHA
; madmaxx
; last edit: 1/1/07
; licence: do whatever you want
short GoldBefore ; Variables for the msgbox at the end of the week.
short GoldAfter
short Costs
short Withdraws
short displayed
begin GameMode
if ( MadCityCityStatus <= 79 ) ; only if you have at least a mine
return
endif
if ( MadCityDone == 0 ) ; only once a week ;) see 'MadCityDayspassed'-Script
set GoldBefore to MadCityBudget
if ( MadCityCityStatus >= 80 ) ; mine
set MadCityBudget to MadCityBudget + MadCityMineWithdraw
endif
if ( MadCityCityStatus >= 200 ) ; Schmelze
set MadCityBudget to MadCityBudget + MadCityMeltingWithdraw
endif
if ( MadCityCityStatus >= 220 ) ; taxes
set MadCityBudget to MadCityBudget + MadCityTaxes
endif
if ( MadCityCityStatus >= 320 ) ; port
set MadCityBudget to MadCityBudget + MadCityPortWithdraw
endif
if ( MadCityBudget <= MadCityGuardCost + MadCityArcherCost + MadCityEliteGuardCost + MadCityPoliceCost + MadCityArmyCost + MadCityMineCost + MadCityMeltingCost ) ; to go shure that MadCityBudget don't become negative.
set MadCityGuardBudget to 0 ; Otherwise, the MadCityModifier1 - script would set it back
set MadCityChangedGuard to 1 ; so the MadCityModifier1 - script calculate all the modifiers
set MadCityArcher Budget to 0
set MadCityChangedArcher to 1
set MadCityEliteGuardBudget to 0
set MadCityChangedEliteGuard to 1
set MadCityPoliceBudget to 0
set MadCityChangedPolice to 1
set MadCityArmyBudget to 0
set MadCityChangedArmy to 1
set MadCityMineBudget to 0
set MadCityMeltingBudget to 0
set MadCityBudget to 0 ; sounds pretty hard, but thats life.
MessageBox "Eurer kleinen Ansiedlung ist das Geld ausgegangen, zumindest kann nicht der Sold all Eurer Männer bezahlt werden.. Eure Leute haben alles genommen, was noch in der Kasse war und ihre Arbeit niedergelegt, bis Ihr wieder bezahlen könnt oder es zumindest versprecht. Geht zu Eurem Buchhalter und regelt die Sache!", "Und das nach allem, was ich für sie getan habe.."
endif
if ( MadCityCityStatus >= 80 ) ; mine
set MadCityBudget to MadCityBudget - MadCityMineCost
endif
if ( MadCityCityStatus >= 120 ) ; manager
if ( MadCityBudget >= 100)
set MadCityBudget to MadCityBudget - 100
endif
endif
if ( MadCityCityStatus >= 200 ) ; Schmelze
set MadCityBudget to MadCityBudget - MadCityMeltingCost
endif
if ( MadCityCityStatus >= 110 ) ; guards
set MadCityBudget to MadCityBudget - MadCityGuardCost
endif
if ( MadCityCityStatus >= 140 ) ; archer
set MadCityBudget to MadCityBudget - MadCityArcherCost
endif
if ( MadCityCityStatus >= 170 ) ; eliteguards
set MadCityBudget to MadCityBudget - MadCityEliteGuardCost
endif
if ( MadCityCityStatus >= 240 ) ; police
set MadCityBudget to MadCityBudget - MadCityPoliceCost
endif
if ( MadCityCityStatus >= 290 ) ; army
set MadCityBudget to MadCityBudget - MadCityArmyCost
endif
set GoldAfter to MatCityBudget
set Costs to MadCityMineCost + MadCityMeltingCost + MadCityGuardCost + MadCityArcherCost + MadCityEliteGuardCost + MadCityPoliceCost + MadCityArmyCost + 100
set Withdraw to MadCityMineWithdraw + MadCityMeltingWithdraw + MadCityTaxes + MadCityPortWithdraw
set displayed to Withdraw - Costs
set MadCityDone to 1
if ( Costs > Withdraw )
MessageBox "Eine weitere Woche ist vergangen. Am Anfang dieser Woche hattet Ihr %.2f Gold in eurer Kasse. Nun habt ihr noch %.2f. Dies entspricht einem Verlust von %.2f .", GoldBefore, GoldAfter, displayed "Verdammt!"
endif
if ( Withdraw > Costs )
MessageBox "Eine weitere erfreuliche Woche ist vergangen! Anfangs hattet Ihr %.2f Gold in eurer Kasse, nun sind es schon %.2f. Das entspricht einem Gewinn von %.2f !", Gold Before, GoldAfter, displayed "Damit hab ich mir ein Bier verdient!"
endif
if ( Withdraw == Costs )
MessageBox "Eine weitere Woche ist vergangen, doch an dem Inhalt Eurer Schatztruhe hat sich nichts geändert. Nach wie vor sind %.2f Gold darin.", displayed "Nun gut.."
endif
end
#############
scn MadCityModifier1
; this script calculates the very basic modificators of the mod. this is the heart of everything! all scripts are working closely
; together in a pretty complex way. if you want to change something, you should proceed to another script unless you know what you
; are doing or BAD THINGS WILL HAPPEN!
; it calculates the overall modifiers for vandalism, assasination, riots and theft in percent. these are used in the other scripts
; to calculate if something will happen or not. also, the costs for army, guards, ... are calculated for the MadCityBudget script.
;
; VERSION 1.0 ALPHA
; madmaxx
; last edit 1/1/07
; license: do whatever you want
short MadCityGuardModifier ; negative theft modifier
short MadCityArcherModifier ; negative vandalism modifier
short MadCityEliteGuardModifier ; negative assasination modifier
short MadCityArmyModifierB ; negative vandalism mofifier
short MadCityArmyModifierR ; negative riot modifier
short MadCityArmyPoliceModifierB ; negative vandalism modifier
short MadCityArmyPoliceModifierT ; negative theft modifier
short MadCityArmyPoliceModifierR ; negative riot modifier
short MadCityArmyMadCityTaxModifierB ; vandalism modifer
short MadCityArmyMadCityTaxModifierT ; theft modifier
short MadCityArmyMadCityTaxModifierR ; riot modifier
begin GameMode
if ( MadCityChangedGuard == 0 && MadCityChangedArcher == 0 && MadCityChangedEliteguard == 0 && MadCityChangedArmy == 0 && MadCityChangedTax == 0 ) ; if nothing was changed..
return
endif
if ( MadCityChangedGuard == 1 ) ; if the guard budget was changed, calculate cost and modifier for the guards
if ( MadCityGuardBudget == 0 )
set MadCityGuardCost to 0
set MadCityGuardModifier to 0
endif
if ( MadCityGuardBudget == 10 )
set MadCityGuardCost to 50
set MadCityGuardModifier to 30
endif
if ( MadCityGuardBudget == 20 )
set MadCityGuardCost to 70
set MadCityGuardModifier to 60
endif
[usw - 246 Zeilen exakt wie die oben]
set MadCityChangedGuard to 0 ; everything ok now.
endif
; set all the modificators for the other scripts
set MadCityTheftMod to MadCityTaxModifierT + MadCityPortModT - MadCityPoliceModifierT - MadCityGuardModifier
set MadCityBeschMod to MadCityTaxModifierB + MadCityPortModB - MadCityPoliceModifierB - MadCityArcherModifier -MadCityArmyModifierB
set MadCityRiotMod to MadCityTaxModifierR - MadCityArmyModifierR - MadCityPoliceModifierR
set MadCityAttackMod to MadCityEliteGuardModifier
end
#################
****scn MadCityAttackScript ; * heißt WIP
; this script calculates if assasins attack you because you have used your people for swordtraining.
;
; VERSION 1.0 ALPHA
; madmaxx
; last edit 1/1/07
; license: do whatever you want
short attackchance
short myday
begin GameMode
if ( MadCityDaysPassed == myday )
return
endif
if ( MadCityDaysPassed =! myday )
set myday to MadCityDaysPassed
endif
if ( IsPCSleeping == 1 )
if ( GetRandomPercent >= 90 ) ; this is a balancing value. Bigger means it is more unlikely that you will be attacked.
if ( MadCityAttackMod >= GetRandomPercent - 10 ) ; this is to determine if your guards will be killed.
set MadCityEGuardsDead to 1 ; there's a script on the guards themself
endif
player.PlaceAtMe Assasin 1 256 1
player.PlaceAtMe Assasin 1 250 1
player.PlaceAtMe Assasin 1 260 1
WakeUpPC
if ( Assasin.GetDead == 1 )
if ( MadCityEguardsDead == 1 )
Messagebox "Es waren einfach zu wenig Wachen als das sie etwas hätten unternehmen können. Sie wurden alle getötet, bevor ihr wach wurdet." "OK"
else
Messagebox "Wer Euch diese Meuchelmörder auf den Hals gehetzt hat wird wohl auf ewig im Dunkeln bleiben, zum Glück wurden eure Leibwächter nicht im Schlaf überrascht." "OK"
endif
endif
endif
endif
end
############
ScriptName MadCityDayspassed
; this script is a global counter - counts till 6 (a week)
; VERSION 1.0 ALPHA
; madmaxx
; last edit: 1/1/07
; licence: do whatever you want
begin GameMode
short myday
if ( MadCityDayspassed == 0 )
set myday to day
endif
if ( myday != day )
set MadCityDayspassed to MadCityDayspassed + 1
set myday to day
endif
if ( MadCityDayspassed >=6 )
set MadCityDayspassed to 0
set MadCityDone to 0 ; after that, MadCityMine, MadCityMelting, MadCityPort and MadCityBudget will start to work
endif
end
##########
scn MadCityPort
; this script calculate the withdraw from the port
;
; VERSION 1.0 ALPHA
; madmaxx
; last edit 1/1/07
; license: do whatever you want
begin GameMode
if ( MadCityCityStatus <= 319 ) ; only if it exists
return
endif
if ( MadCityDone == 0 ) ; only once a week ;) check the 'MadCityDayspassed' and the 'MadCityBudget' scripts
set MadCityPortModT to 30
set MadCityPortModB to 20
set MadCityPortWithdraw to GetRandomPercent+GetRandomPercentcent*25
if ( MadCityPortWithdraw <= 850 )
set MadCityPortWithdraw to MadCityPortWithdraw + 850
endif
endif
end
#############
ScriptName MadCityMineBudget
; this script calculates the mine withdraw and mine cost
; (MadCityMineWithdraw ; MadCityMineCost)
; VERSION 1.0 ALPHA
; madmaxx
; last edit 1/1/07
; license: do whatever you want
begin GameMode
; MineBudget 0: no work
; MineBudget 10-40: normal mine
; MineBudget 50-80: manager
; MineBudget 90-120: big mine
if ( MadCityCityStatus <= 79 ) ; only if there IS a mine actually
return
endif
if ( MadCityDone == 0 ) ; only once a week ;) check the 'MadCityDayspassed' and the 'MadCityBudget' scripts
if ( MadCityMineBudget == 0 )
set MadCityMineCost to 0
set MadCityMineWithdraw to 0
return
endif
if ( MadCityMineBudget == 10 )
set MadCityMineCost to 100
set MadCityMineWithdraw to GetRandomPercent+GetRandomPercent+GetRandomPercent ; wird noch geändert auf GetRandomPercent*x
if ( MadCityMineWithdraw <= 79 ) ; the smallest withdraw of the mine at this point is 80 gold
set MadCityMineWithdraw to MadCityMineWithdraw + 80
endif
return
endif
[usw 100 Zeilen entfernt]
return
endif
endif
endif
end
#########
Schmelzenbudget wie oben
#########
scn MadCityTheftScript
; this script calculates if thieves get in your house and ruin your plan of getting rich.
;
; VERSION 2.0 ALPHA
; madmaxx
; last edit 1/1/07
; license: do whatever you want
short TheftMod
short myday
short difference
short randomstolen
begin GameMode
if ( MadCityDaysPassed == myday )
return
endif
if ( MadCityDaysPassed =! myday )
set myday to MadCityDaysPassed
endif
; yes, it will happen once every single day, but the chances are only about 5%
set TheftMod to MadCityTheftMod
set TheftMod to TheftMod + 67 ; this is a balancing constant, because MadCityTheftMod is always a negativ number, bigger means bigger chance of theft.
if ( MadCityDaysPassed == randomday )
if ( GetRandomPercent <= TheftMod ) ; if TRUE, the thieves will get in.
set randomstolen to GetRandomPercent - 20
set difference to MadCityBudget
set MadCityBudget to MadCityBudget / 100 * randomstolen ; so randomstolen percent are.. stolen.
set difference to difference - MadCityBudget
Messagebox "Eure Wachen haben versagt! Bei euch wurde eingebrochen! Es wurden Gegenstände im Wert von %.2f entwendet..", difference "Diese verdammten..."
endif
endif
end
__________________
"Die Flamme unsrer Väter wird nie erlöschen
sie lodert in uns auf Ewigkeiten
die Zeit steht kurz still, wir erinnern uns
mit stolzem Gefühl."
Das aktuelle TESCSKompendium & einiges mehr findet ihr hier
|