Skip to content

Commit

Permalink
Numeric Variables (#424)
Browse files Browse the repository at this point in the history
* Implement the logic

* Finish the doc

* Update YRPP

* Finish generate random integer

* Implement scripts

* Add a debug trigger action

* Minor fixes

* Add mission pTeam

* Fixup the document
  • Loading branch information
secsome authored Nov 3, 2021
1 parent 019ebb7 commit 3eb18e7
Show file tree
Hide file tree
Showing 16 changed files with 848 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Phobos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<ClCompile Include="src\Ext\TAction\Body.cpp" />
<ClCompile Include="src\Ext\TAction\Hooks.cpp" />
<ClCompile Include="src\Ext\Team\Body.cpp" />
<ClCompile Include="src\Ext\TEvent\Hooks.cpp" />
<ClCompile Include="src\Ext\TEvent\Body.cpp" />
<ClCompile Include="src\Ext\Trigger\Hooks.cpp" />
<ClCompile Include="src\Misc\CaptureManager.cpp" />
<ClCompile Include="src\Misc\TextInput.cpp" />
<ClCompile Include="src\New\Entity\ShieldClass.cpp" />
Expand Down Expand Up @@ -108,6 +111,7 @@
<ClInclude Include="src\Ext\Anim\Body.h" />
<ClInclude Include="src\Ext\TAction\Body.h" />
<ClInclude Include="src\Ext\Team\Body.h" />
<ClInclude Include="src\Ext\TEvent\Body.h" />
<ClInclude Include="src\Misc\CaptureManager.h" />
<ClInclude Include="src\New\Entity\ShieldClass.h" />
<ClInclude Include="src\New\Type\RadTypeClass.h" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Credits
- **4SG** - help with docs
- **wiktorderelf** - overhauled Unicode font
- **Uranusian (Thrifinesma)** - Mind Control enhancement, custom warhead splash list, harvesters counter, promoted spawns, shields, death after dead fix, customizeable missing cameo, cameo sorting priority, placement mode responding of tab hotkeys fix, producing progress, custom ore gathering anim, NoManualMove, DeathWeapon fix, re-enable obsolete `JumpjetControls`, overhauled Unicode font, docs maintenance, CN docs translation
- **secsome (SEC-SOME)** - debug info dump hotkey, refactoring & porting of Ares helper code, introducing more Ares-derived stuff, disguise removal warhead, Mind Control removal warhead, Mind Control enhancement, shields, AnimList.PickRandom, MoveToCell fix, unlimited waypoints, Build At trigger action buildup anim fix, Undeploy building into a unit plays `EVA_NewRallyPointEstablished` fix, custom ore gathering anim, TemporaryClass related crash, Retry dialog on mission failure, Default disguise for individual InfantryTypes, PowerPlant Enhancer, SaveGame Trigger Action, QuickSave command
- **secsome (SEC-SOME)** - debug info dump hotkey, refactoring & porting of Ares helper code, introducing more Ares-derived stuff, disguise removal warhead, Mind Control removal warhead, Mind Control enhancement, shields, AnimList.PickRandom, MoveToCell fix, unlimited waypoints, Build At trigger action buildup anim fix, Undeploy building into a unit plays `EVA_NewRallyPointEstablished` fix, custom ore gathering anim, TemporaryClass related crash, Retry dialog on mission failure, Default disguise for individual InfantryTypes, PowerPlant Enhancer, SaveGame Trigger Action, QuickSave command, Numeric variables
- **Otamaa (Fahroni, BoredEXE)** - help with CellSpread, ported and fixed custom RadType code, togglable ElectricBolt bolts, customizable Chrono Locomotor properties per TechnoClass, DebrisMaximums fixes, Anim-to-Unit, NotHuman anim sequences improvements, Customizable OpenTopped Properties, hooks for ScriptType Actions 92 & 93
- **E1 Elite** - TileSet 255 and above bridge repair fix
- **FS-21** - Dump Object Info enhancements, Powered.KillSpawns, Spawner.LimitRange, ScriptType Actions 71, 72, 73, 74 to 81, 92, 93, 94, 95 to 98, 111, 112, MC deployer fixes, help with docs, Automatic Passenger Deletion
Expand Down
2 changes: 1 addition & 1 deletion YRpp
89 changes: 89 additions & 0 deletions docs/New-or-Enhanced-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,35 @@ Interceptor.EliteMinimumGuardRange=0.0 ; double
Interceptable=no ; boolean
```

## Trigger events

### `500-511` Variable comparation
- Compares the variable's value with given number

In `mycampaign.map`:
```ini
[Events]
...
ID=EventCount,[Event1],[EVENTID],2,[VariableIndex],[Param],[EventX]
...
```

| *Event ID* | *Description* | *Global* |
| :------: | :-------------------------------------------: | :-------: |
500 | CurrentValue > Number | No |
501 | CurrentValue < CurrentValue | No |
502 | CurrentValue = CurrentValue | No |
503 | CurrentValue >= CurrentValue | No |
504 | CurrentValue <= CurrentValue | No |
505 | CurrentValue & CurrentValue | No |
506 | CurrentValue > CurrentValue | Yes |
507 | CurrentValue < ~CurrentValue | Yes |
508 | CurrentValue = CurrentValue | Yes |
509 | CurrentValue >= CurrentValue | Yes |
510 | CurrentValue <= CurrentValue | Yes |
511 | CurrentValue & CurrentValue | Yes |


## Trigger actions

### `500` Save Game
Expand All @@ -540,6 +569,56 @@ ID=ActionCount,[Action1],500,4,[CSFKey],0,0,0,0,A,[ActionX]
...
```

### `501` Edit Variable
- Operate a variable's value
- The variable's value type is int32, which means it ranges from -2^31 to 2^31-1.
- Any numbers exceeding this limit will lead to unexpected results!

In `mycampaign.map`:
```ini
[Actions]
...
ID=ActionCount,[Action1],501,0,[VariableIndex],[Operation],[Number],[IsGlobalVariable],0,A,[ActionX]
...
```

| *Operation* | *Description* |
| :------: | :-------------------------------------------: |
0 | CurrentValue = Number |
1 | CurrentValue = CurrentValue + Number |
2 | CurrentValue = CurrentValue * Number |
3 | CurrentValue = CurrentValue / Number |
4 | CurrentValue = CurrentValue % Number |
5 | CurrentValue = CurrentValue leftshift Number |
6 | CurrentValue = CurrentValue rightshift Number |
7 | CurrentValue = ~CurrentValue |
8 | CurrentValue = CurrentValue xor Number |
9 | CurrentValue = CurrentValue or Number |
10 | CurrentValue = CurrentValue and Number |

### `502` Generate random number
- Generate a random integer ranged in [Min, Max] and store it in a given variable

In `mycampaign.map`:
```ini
[Actions]
...
ID=ActionCount,[Action1],502,0,[VariableIndex],[Min],[Max],[IsGlobalVariable],0,A,[ActionX]
...
```

### `503` Print variable value
- Print a variable value to the message list

In `mycampaign.map`:
```ini
[Actions]
...
ID=ActionCount,[Action1],503,[VariableIndex],0,[IsGlobalVariable],0,0,0,A,[ActionX]
...
```


## Script actions

### `71` Timed Area Guard
Expand Down Expand Up @@ -763,3 +842,13 @@ In `aimd.ini`:
[SOMESCRIPTTYPE] ; ScriptType
x=112,n
```
### `500 - 519` Edit Variable
- Operate a variable's value
- The variable's value type is int16 instead of int32 in trigger actions for some reason, which means it ranges from -2^15 to 2^15-1.
- Any numbers exceeding this limit will lead to unexpected results!

In `aimd.ini`:
```ini
[SOMESCRIPTTYPE] ; ScriptType
x=i,n ; where 500 <= i <= 519, n is made up of two parts, the low 16 bits is being used to store the variable index, the high 16 bits is being used for storing the param value.
```
65 changes: 62 additions & 3 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,74 @@ In `FAData.ini`:
[ParamTypes]
47=Structures,28
53=Play BuildUp,10
54=Use GlobalVar,10
55=Operation,0
56=Variable index,0
57=Lower bound,0
58=Upper bound,0

[EventsRA2]
500=Local variable is greater than,48,6,0,0,[LONG DESC],0,1,500,1
501=Local variable is less than,48,6,0,0,[LONG DESC],0,1,501,1
502=Local variable equals to,48,6,0,0,[LONG DESC],0,1,502,1
503=Local variable is greater than or equals to,48,6,0,0,[LONG DESC],0,1,503,1
504=Local variable is less than or equals,48,6,0,0,[LONG DESC],0,1,504,1
505=Local variable and X is true,48,6,0,0,[LONG DESC],0,1,505,1
506=Global variable is greater than,48,6,0,0,[LONG DESC],0,1,506,1
507=Global variable is less than,48,6,0,0,[LONG DESC],0,1,507,1
508=Global variable equals to,48,6,0,0,[LONG DESC],0,1,508,1
509=Global variable is greater than or queals to,48,6,0,0,[LONG DESC],0,1,509,1
510=Global variable is less than or equals to,48,6,0,0,[LONG DESC],0,1,510,1
511=Global variable and X is true,48,6,0,0,[LONG DESC],0,1,511,1

[ActionsRA2]
125=Build at...,-10,47,53,0,0,0,1,0,0,[LONG DESC],0,1,125
500=Save game,-4,13,0,0,0,0,0,0,0,[LONG DESC],0,1,500,1
501=Edit variable,0,56,55,6,54,0,0,0,0,[LONG DESC],0,1,501,1
502=Generate random number,0,56,57,58,54,0,0,0,0,[LONG DESC],0,1,502,1
503=Print variable value,0,56,54,0,0,0,0,0,0,[LONG DESC],0,1,503,0

[ScriptsRA2] ; NEEDS FA2EXT.DLL (by AlexB) or FA2SP.DLL (by secsome)
71=Timed Area Guard,4,0,1,[LONG DESC] ; FA2Ext.dll only
71=Timed Area Guard,20,0,1,[LONG DESC] ; FA2sp.dll only
; FOLLOWING STUFFS NEEDS FA2SP.DLL (by secsome)
[ScriptTypeLists]
1=ScriptLocalVariable
2=ScriptGlobalVariable

[ScriptLocalVariable]
HasExtraParam=Yes
BuiltInType=14

[ScriptGlobalVariable]
HasExtraParam=Yes
BuiltInType=5

[ScriptsRA2]
71=Timed Area Guard,20,0,1,[LONG DESC]
72=Load Onto Transports,0,0,1,[LONG DESC]
73=Wait until ammo is full,0,0,1,[LONG DESC]
500=Local variable add,22,0,1,[LONG DESC]
501=Local variable multiply,22,0,1,[LONG DESC]
502=Local variable divide,22,0,1,[LONG DESC]
503=Local variable mod,22,0,1,[LONG DESC]
504=Local variable left shift,22,0,1,[LONG DESC]
505=Local variable right shift,22,0,1,[LONG DESC]
506=Local variable reverse,22,0,1,[LONG DESC]
507=Local variable xor,22,0,1,[LONG DESC]
508=Local variable or,22,0,1,[LONG DESC]
509=Local variable and,22,0,1,[LONG DESC]
510=Global variable add,23,0,1,[LONG DESC]
511=Global variable multiply,23,0,1,[LONG DESC]
512=Global variable divide,23,0,1,[LONG DESC]
513=Global variable mod,23,0,1,[LONG DESC]
514=Global variable left shift,23,0,1,[LONG DESC]
515=Global variable right shift,23,0,1,[LONG DESC]
516=Global variable reverse,23,0,1,[LONG DESC]
517=Global variable xor,23,0,1,[LONG DESC]
518=Global variable or,23,0,1,[LONG DESC]
519=Global variable and,23,0,1,[LONG DESC]

[ScriptParams]
22=Local variables,-1
23=Global variables,-2
```

## Changelog
Expand All @@ -50,6 +108,7 @@ New:
- Default disguise for individual InfantryTypes (by secsome)
- Quicksave hotkey command (by secsome)
- Save Game Trigger Action (by secsome)
- Numeric Variables (by secsome)
- Allow `NotHuman=yes` infantry to use random `Death` anim sequence (by Otamaa)
- Ability for warheads to trigger specific `NotHuman=yes` infantry `Death` anim sequence (by Otamaa)
- XDrawOffset for animations (by Morton)
Expand Down
4 changes: 2 additions & 2 deletions src/Ext/Scenario/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ScenarioExt::ExtData::GetVariableStateByID(bool bIsGlobal, int nIndex, char

auto itr = dict.find(nIndex);
if (itr != dict.end())
*pOut = itr->second.Value;
*pOut = static_cast<char>(itr->second.Value);
}

void ScenarioExt::ExtData::ReadVariables(bool bIsGlobal, CCINIClass* pINI)
Expand All @@ -45,7 +45,7 @@ void ScenarioExt::ExtData::ReadVariables(bool bIsGlobal, CCINIClass* pINI)
char* buffer;
strcpy_s(var.Name, strtok_s(Phobos::readBuffer, ",", &buffer));
if (auto pState = strtok_s(nullptr, ",", &buffer))
var.Value = atoi(pState) != 0;
var.Value = atoi(pState);
else
var.Value = 0;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Ext/Scenario/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#include <map>

struct ExtendedVariable
{
char Name[0x100];
int Value;
};

class ScenarioExt
{
public:
Expand All @@ -17,7 +23,7 @@ class ScenarioExt
{
public:
std::map<int, CellStruct> Waypoints;
std::map<int, Variable> Variables[2]; // 0 for local, 1 for global
std::map<int, ExtendedVariable> Variables[2]; // 0 for local, 1 for global

ExtData(ScenarioClass* OwnerObject) : Extension<ScenarioClass>(OwnerObject),
Waypoints { },
Expand Down
Loading

0 comments on commit 3eb18e7

Please sign in to comment.