Changeset 25089

Timestamp:
Mar 20, 2021, 5:01:11 PM (3 years ago)
Author:
Freagarach
Message:

Move Mirage information to respective components.

Moves the functions that define the properties/functions to mirage to their respective components, making it easier for modders to know their existence and to modify.

Closes: #5985
Differential revision: D3695
Comments by: @wraitii

Location:
ps/trunk/binaries/data/mods/public/simulation/components
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/binaries/data/mods/public/simulation/components/Capturable.js

    r25087 r25089  
    370370};
    371371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
    372392Engine.RegisterComponentType(IID_Capturable, "Capturable", Capturable);
  • ps/trunk/binaries/data/mods/public/simulation/components/Foundation.js

    r24405 r25089  
    532532};
    533533
     534
     535
     536
     537
     538
     539
     540
     541
     542
     543
     544
     545
     546
     547
     548
     549
     550
     551
     552
    534553Engine.RegisterComponentType(IID_Foundation, "Foundation", Foundation);
    535 
  • ps/trunk/binaries/data/mods/public/simulation/components/Health.js

    r25030 r25089  
    484484};
    485485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
     504
     505
     506
     507
     508
     509
    486510Engine.RegisterComponentType(IID_Health, "Health", Health);
  • ps/trunk/binaries/data/mods/public/simulation/components/Identity.js

    r24624 r25089  
    202202};
    203203
     204
     205
     206
     207
     208
     209
     210
     211
     212
     213
     214
     215
     216
     217
     218
     219
     220
     221
     222
     223
    204224Engine.RegisterComponentType(IID_Identity, "Identity", Identity);
  • ps/trunk/binaries/data/mods/public/simulation/components/Market.js

    r20953 r25089  
    8585};
    8686
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
    87154Engine.RegisterComponentType(IID_Market, "Market", Market);
  • ps/trunk/binaries/data/mods/public/simulation/components/Mirage.js

    r25079 r25089  
    5050// Parent entity data
    5151
    52 function MiragedIdentity() {}
    53 MiragedIdentity.prototype.Init = function(cmpIdentity)
     52Mirage.prototype.CopyCapturable = function(cmpCapturable)
    5453{
    55     // Mirages don't get identity classes via the template-filter, so that code can query
    56     // identity components via Engine.QueryInterface without having to explicitly check for mirages.
    57     // This is cloned as otherwise we get a reference to Identity's property,
    58     // and that array is deleted when serializing (as it's not seralized), which ends in OOS.
    59     this.classes = clone(cmpIdentity.GetClassesList());
     54    this.miragedIids.set(IID_Capturable, cmpCapturable.Mirage());
    6055};
    6156
    62 MiragedIdentity.prototype.GetClassesList = function() { return this.classes; };
    63 Engine.RegisterGlobal("MiragedIdentity", MiragedIdentity);
     57Mirage.prototype.CopyFoundation = function(cmpFoundation)
     58{
     59    this.miragedIids.set(IID_Foundation, cmpFoundation.Mirage());
     60};
     61
     62Mirage.prototype.CopyHealth = function(cmpHealth)
     63{
     64    this.miragedIids.set(IID_Health, cmpHealth.Mirage());
     65};
    6466
    6567Mirage.prototype.CopyIdentity = function(cmpIdentity)
    6668{
    67     let mirage = new MiragedIdentity();
    68     mirage.Init(cmpIdentity);
    69     this.miragedIids.set(IID_Identity, mirage);
     69    this.miragedIids.set(IID_Identity, cmpIdentity.Mirage());
    7070};
    7171
    72 // Foundation data
    73 
    74 function MiragedFoundation() {}
    75 MiragedFoundation.prototype.Init = function(cmpFoundation)
     72Mirage.prototype.CopyMarket = function(cmpMarket)
    7673{
    77     this.numBuilders = cmpFoundation.GetNumBuilders();
    78     this.buildTime = cmpFoundation.GetBuildTime();
     74    this.miragedIids.set(IID_Market, cmpMarket.Mirage(this.entity, this.player));
    7975};
    80 
    81 MiragedFoundation.prototype.GetNumBuilders = function() { return this.numBuilders; };
    82 MiragedFoundation.prototype.GetBuildTime = function() { return this.buildTime; };
    83 Engine.RegisterGlobal("MiragedFoundation", MiragedFoundation);
    84 
    85 Mirage.prototype.CopyFoundation = function(cmpFoundation)
    86 {
    87     let mirage = new MiragedFoundation();
    88     mirage.Init(cmpFoundation);
    89     this.miragedIids.set(IID_Foundation, mirage);
    90 };
    91 
    92 // Repairable data
    93 
    94 function MiragedRepairable() {}
    95 MiragedRepairable.prototype.Init = function(cmpRepairable)
    96 {
    97     this.numBuilders = cmpRepairable.GetNumBuilders();
    98     this.buildTime = cmpRepairable.GetBuildTime();
    99 };
    100 
    101 MiragedRepairable.prototype.GetNumBuilders = function() { return this.numBuilders; };
    102 MiragedRepairable.prototype.GetBuildTime = function() { return this.buildTime; };
    103 Engine.RegisterGlobal("MiragedRepairable", MiragedRepairable);
    10476
    10577Mirage.prototype.CopyRepairable = function(cmpRepairable)
    10678{
    107     let mirage = new MiragedRepairable();
    108     mirage.Init(cmpRepairable);
    109     this.miragedIids.set(IID_Repairable, mirage);
     79    this.miragedIids.set(IID_Repairable, cmpRepairable.Mirage());
    11080};
    111 
    112 // Health data
    113 
    114 function MiragedHealth() {}
    115 MiragedHealth.prototype.Init = function(cmpHealth)
    116 {
    117     this.maxHitpoints = cmpHealth.GetMaxHitpoints();
    118     this.hitpoints = cmpHealth.GetHitpoints();
    119     this.repairable = cmpHealth.IsRepairable();
    120     this.injured = cmpHealth.IsInjured();
    121     this.unhealable = cmpHealth.IsUnhealable();
    122 };
    123 
    124 MiragedHealth.prototype.GetMaxHitpoints = function() { return this.maxHitpoints; };
    125 MiragedHealth.prototype.GetHitpoints = function() { return this.hitpoints; };
    126 MiragedHealth.prototype.IsRepairable = function() { return this.repairable; };
    127 MiragedHealth.prototype.IsInjured = function() { return this.injured; };
    128 MiragedHealth.prototype.IsUnhealable = function() { return this.unhealable; };
    129 Engine.RegisterGlobal("MiragedHealth", MiragedHealth);
    130 
    131 Mirage.prototype.CopyHealth = function(cmpHealth)
    132 {
    133     let mirage = new MiragedHealth();
    134     mirage.Init(cmpHealth);
    135     this.miragedIids.set(IID_Health, mirage);
    136 };
    137 
    138 // Capture data
    139 
    140 function MiragedCapturable() {}
    141 MiragedCapturable.prototype.Init = function(cmpCapturable)
    142 {
    143     this.capturePoints = clone(cmpCapturable.GetCapturePoints());
    144     this.maxCapturePoints = cmpCapturable.GetMaxCapturePoints();
    145 };
    146 
    147 MiragedCapturable.prototype.GetCapturePoints = function() { return this.capturePoints; };
    148 MiragedCapturable.prototype.GetMaxCapturePoints = function() { return this.maxCapturePoints; };
    149 MiragedCapturable.prototype.CanCapture = Capturable.prototype.CanCapture;
    150 Engine.RegisterGlobal("MiragedCapturable", MiragedCapturable);
    151 
    152 Mirage.prototype.CopyCapturable = function(cmpCapturable)
    153 {
    154     let mirage = new MiragedCapturable();
    155     mirage.Init(cmpCapturable);
    156     this.miragedIids.set(IID_Capturable, mirage);
    157 };
    158 
    159 // ResourceSupply data
    160 function MiragedResourceSupply() {}
    161 MiragedResourceSupply.prototype.Init = function(cmpResourceSupply)
    162 {
    163     this.maxAmount = cmpResourceSupply.GetMaxAmount();
    164     this.amount = cmpResourceSupply.GetCurrentAmount();
    165     this.type = cmpResourceSupply.GetType();
    166     this.isInfinite = cmpResourceSupply.IsInfinite();
    167     this.killBeforeGather = cmpResourceSupply.GetKillBeforeGather();
    168     this.maxGatherers = cmpResourceSupply.GetMaxGatherers();
    169     this.numGatherers = cmpResourceSupply.GetNumGatherers();
    170 };
    171 
    172 MiragedResourceSupply.prototype.GetMaxAmount = function() { return this.maxAmount; };
    173 MiragedResourceSupply.prototype.GetCurrentAmount = function() { return this.amount; };
    174 MiragedResourceSupply.prototype.GetType = function() { return this.type; };
    175 MiragedResourceSupply.prototype.IsInfinite = function() { return this.isInfinite; };
    176 MiragedResourceSupply.prototype.GetKillBeforeGather = function() { return this.killBeforeGather; };
    177 MiragedResourceSupply.prototype.GetMaxGatherers = function() { return this.maxGatherers; };
    178 MiragedResourceSupply.prototype.GetNumGatherers = function() { return this.numGatherers; };
    179 
    180 // Apply diminishing returns with more gatherers, for e.g. infinite farms. For most resources this has no effect
    181 // (GetDiminishingReturns will return null). We can assume that for resources that are miraged this is the case.
    182 MiragedResourceSupply.prototype.GetDiminishingReturns = function() { return null; };
    183 
    184 Engine.RegisterGlobal("MiragedResourceSupply", MiragedResourceSupply);
    18581
    18682Mirage.prototype.CopyResourceSupply = function(cmpResourceSupply)
    18783{
    188     let mirage = new MiragedResourceSupply();
    189     mirage.Init(cmpResourceSupply);
    190     this.miragedIids.set(IID_ResourceSupply, mirage);
    191 };
    192 
    193 // Market data
    194 function MiragedMarket() {}
    195 MiragedMarket.prototype.Init = function(cmpMarket, entity, parent, player)
    196 {
    197     this.entity = entity;
    198     this.parent = parent;
    199     this.player = player;
    200 
    201     this.traders = new Set();
    202     for (let trader of cmpMarket.GetTraders())
    203     {
    204         let cmpTrader = Engine.QueryInterface(trader, IID_Trader);
    205         let cmpOwnership = Engine.QueryInterface(trader, IID_Ownership);
    206         if (!cmpTrader || !cmpOwnership)
    207         {
    208             cmpMarket.RemoveTrader(trader);
    209             continue;
    210         }
    211         if (this.player != cmpOwnership.GetOwner())
    212             continue;
    213         cmpTrader.SwitchMarket(cmpMarket.entity, this.entity);
    214         cmpMarket.RemoveTrader(trader);
    215         this.AddTrader(trader);
    216     }
    217     this.marketType = cmpMarket.GetType();
    218     this.internationalBonus = cmpMarket.GetInternationalBonus();
    219 };
    220 
    221 MiragedMarket.prototype.HasType = function(type) { return this.marketType.has(type); };
    222 MiragedMarket.prototype.GetInternationalBonus = function() { return this.internationalBonus; };
    223 MiragedMarket.prototype.AddTrader = function(trader) { this.traders.add(trader); };
    224 MiragedMarket.prototype.RemoveTrader = function(trader) { this.traders.delete(trader); };
    225 
    226 MiragedMarket.prototype.UpdateTraders = function(msg)
    227 {
    228     let cmpMarket = Engine.QueryInterface(this.parent, IID_Market);
    229     if (!cmpMarket) // The parent market does not exist anymore
    230     {
    231         for (let trader of this.traders)
    232         {
    233             let cmpTrader = Engine.QueryInterface(trader, IID_Trader);
    234             if (cmpTrader)
    235                 cmpTrader.RemoveMarket(this.entity);
    236         }
    237         return;
    238     }
    239 
    240     // The market becomes visible, switch all traders from the mirage to the market
    241     for (let trader of this.traders)
    242     {
    243         let cmpTrader = Engine.QueryInterface(trader, IID_Trader);
    244         if (!cmpTrader)
    245             continue;
    246         cmpTrader.SwitchMarket(this.entity, cmpMarket.entity);
    247         this.RemoveTrader(trader);
    248         cmpMarket.AddTrader(trader);
    249     }
    250 };
    251 Engine.RegisterGlobal("MiragedMarket", MiragedMarket);
    252 
    253 Mirage.prototype.CopyMarket = function(cmpMarket)
    254 {
    255     let mirage = new MiragedMarket();
    256     mirage.Init(cmpMarket, this.entity, this.parent, this.player);
    257     this.miragedIids.set(IID_Market, mirage);
     84    this.miragedIids.set(IID_ResourceSupply, cmpResourceSupply.Mirage());
    25885};
    25986
  • ps/trunk/binaries/data/mods/public/simulation/components/Repairable.js

    r25087 r25089  
    152152};
    153153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
    154173Engine.RegisterComponentType(IID_Repairable, "Repairable", Repairable);
  • ps/trunk/binaries/data/mods/public/simulation/components/ResourceSupply.js

    r24989 r25089  
    469469};
    470470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
     488
     489
     490
     491
     492
     493
     494
     495
     496
     497
     498
     499
     500
     501
     502
     503
    471504Engine.RegisterComponentType(IID_ResourceSupply, "ResourceSupply", ResourceSupply);
Note: See TracChangeset for help on using the changeset viewer.