I decided to write this thread to help people decode the AMPS code and see how to adapt it in the SC4 simulation and possibly understand how to create an updated and improved version. The Code The code is divided into 8 blocks, which are as follows The Exempalr Building IID table The table of Kva Rating The MWH Rating table The table of unlocking conditions The table with the names of energy corporations The variable reset table in the initialization phase The algorithms of operation The code related to the unlocking conditions The first thing to do is to study block by block AMPS for which you can deduce Exemplar Building IID Table only serves to understand IID of the buildings that are used by the mod. The table of Kva Rating, The MWH Rating table and The algorithms of operation are the beating heart related to the mod The table of unlocking conditions and The code related to the unlocking conditions are related to the unlocking conditions The table of names of energy companies are needed for LTEXTs. The rest of the variables is just to reset the algorithms in the city loading phase The logic behind AMPS The first question we ask is: What is KVA Rating? To answer this question, we need to select a type of power plant (in this case, Maxis oil-fired power plants). As you can see from the image, the Kva Rating consists of the IID of the Exemplar Building and a number, so by examining the Exemplar Building with PIM-X, you can see that the Kva Rating value corresponds to the Catalog Capacity value. But another question arises. Why are IID Exemplar between LUA code and PIM-X different? This is simple because incorrectly called Exemplar Building IID is actually just a Memory IID that is used to remember a certain value. The same reasoning is done with MWH Rating where this time MWH Rating corresponds to the value of the power generated by the power plant So we know that the memory address of the Maxis oil plant is 0xBB350090 We have decoded the meaning of MHW Rating and KVA Rating so we proceed in understanding the code of the algorithms In the algorithms section, there are several blocks that perform different functions, and let's go through them one by one The Building Count This code is only for counting the number of power plants present that comply with the AMPS code. This code definitely has the purpose for the UIs But already reading this detail there is an interesting thing. AMPS treats energy and buildings as if they were automata which makes us realize that we are most likely moving from a statsitic simulation to an agent simulation but surely using automata was one option to process complex things. This information is important for later KVa Rating The second block of algorithms is mainly related to the total calculation of Kva rating which can is summarized as follows Kva Rating Oil Total = (Number of Maxis oil power plants * Catalogue Capaity) + ....... ( After this calculation we proceed in calculating Kva final ratings and run a check on how many transformers there are to simulate the operation of a power grid. The variables in this final section mostly serve as unlocking conditions for the other power plants MHW Rating The block of the MHW Rating algorithm is identical to the KVA Rating algorithm. Therefore. First do the calculation of the total MHW Rating of oil-fired power plants. But there is a variation. Into the MHW Rating comes POWER_DEVIATION, which is a variable to handle all non-AMPS power plants. Entering this variable slightly changes the code of the final MHW Rating calculation but in the end you get the values you need to handle the unblocking and UI coding as you do for Kva Rating A detail that emerges in the POWER_DEVIATION that in addition to making intermediary between AMPS and non-AMPS power plants includes the variable of Age Degradation Rate which is ultimately how long it takes a power plant to go from 100% to 0% coditions This thing is due to the fact that in the SC4 simulation the capacity of a power plant decreases with the passage of time so it occurs that our beloved Advisor Jonas Sparks gets pissed off because the power plant is not producing much energy, it is going to explode and you have to change it with a new more powerful one The third block is related to batteries and their ability to take and store energy and to release energy. The fourth block is only related to the counting of administrative buildings The fifth block is related to in-game difficulty balancing that is then used in a later block i.e., the balancing algorithms that trigger problem alerts and unlock coditions The last block is related to the cost management of transformers and buildings Waste to energy W2E have earned a special codition in that they must burn waste to produce energy. For this reason, the code for calculating Total MHW Rating is different from other power plants To make a long story short. To calculate the Total MHW Rating value of a W2E I have to do the following step. First calculate the W2E of the Large (L) and Small (S) plants with the value of the power produced Actual MHw rating is given by the mathematical function (math.floor) (Energy Produced /( (MHW Total Rating of Large Plants + MHW Total Rating of Small Plants) x Value of garbage produced in the city) x 0.1) + 0.5 0.1 and 0.5 are just simple constants Classification of power plants While in SC4, the classification of power plants depends only on the type of fuel is used (Coal, Oil, Natural Gas, Nuclear Fission, Wind, Solar, and Waste) in AMPS a new classification is introduced Generators: Small Low Voltage Power Producers Small Power Plants: Medium Voltage Power Producers Large Power Plants: High Voltage Power Producers In addition to this, there is a classification of transformers Transmission Stations: High voltage Distribution Substation: Converters from High Voltage to Medium Voltage Transformers: Converters from Medium Voltage to Low Voltage In addition, large and small power plants only then divided into Peak Plants: They produce large amounts of energy but are very expensive but constant over time Base Load Plants: They provide an inexpensive amount of energy but are variable depending on the power plants built and the city's consumption Intermediate Plants: Typical renewable plants where energy production is so variable that it needs batteries or base load or peak load power plants to meet energy demand These distinctions are critical because we find them in the final algorithms where the final values are calculated, which are then used in the unlock conditions and in the UI Furthermore, the main fuel used in power plants is divided between Peak Plants, Base Load Plants, and Intermediate Plants. Therefore Peak Plants: oil, natural gas, fusion, and fission Base Load Plants: coal, wood, waste, geothermal, and hydroelectric Intermediate Plants: solar and wind Conclusions The code developed by @RobertaME is very effective and extends SC4's energy simulation to the next level, namely agent-based simulation. Although this is positive, it poses many technical challenges, as power plants must be included in the LUA AMPS system, which can make the code unmanageable in the long term. This analysis of the code can lead to an extension of the knowledge of SC4's potential and certainly an integration between DLL Mods, Lua Mods, and Building Mods to extend the gameplay. There will be additional chapters as I continue to analyze the AMPS code and the energy simulation mechanism of SC4.