Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to addon #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
## ArmA specific
#################
*.sqm
*.pbo

#################
## Eclipse
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
@@ -0,0 +1,21 @@
MIT License:

Copyright (C) 2014 Joni Mäkelä

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
120 changes: 66 additions & 54 deletions README.md
@@ -1,79 +1,73 @@
arma-ccip
Arma-CCIP
=========
Arma-ccip is a CCIP (continously computed impact point) solver for aircrafts in ArmA 3. It is a client side script that only runs on clients. The script calculates the approximate impact point of the currently selected weapon in the aircraft. It is an approximation, so there will be a small degree of error between the calculated impact point and the real impact point.
Arma-CCIP is a CCIP (Continously Computed Impact Point) solver for aircraft in
ArmA 3. It is a client side script that only runs on clients. The script
calculates the approximate impact point of the currently selected weapon in the
aircraft. It is an approximation, so there will be a small degree of error
between the calculated impact point and the real impact point.

Who it is for?
--
- Vehicle authors
- Other modders
- Other enthusiastic people
- Pilots and other enthusiasts

The script only calculates the impact point. There is just a crude cross on the HUD along with distance text to indicate the computed impact point. HUD development was never a focus of this project but that might change.
The script only calculates the impact point. There is just a crude cross on the
HUD along with distance text to indicate the computed impact point. HUD
development was never a focus of this project but that might change.

The script provides two variables that can be accessed to get the impact point information:

```
//these are subject to change
// These are subject to change
ccip_impactPos - contains the impact position in ASL format
ccip_resultIndex - Value will be -1 if no impact point could be solved during the iteration.
Otherwise the value will indicate which step of the Euler's method was below the ground.
```
These variables are calculated on each frame and the ccip_impactPos variable is a moving average of the past ten frames. This is done to minimize jittering of the position.
Vehicle authors and other mod makers should only need to read these two variables in order to create a proper HUD for their aircraft. Of course suggestions for additional variables are welcome.
These variables are calculated on each frame and the `ccip_impactPos` variable is
a moving average of the past ten frames. This is done to minimize jittering of
the position. Vehicle authors and other mod makers should only need to read
these two variables in order to create a proper HUD for their aircraft. Of
course suggestions for additional variables are welcome.

How does it work?
--
Approximation is done by using Euler's method to solve the projectile motion.
Approximation is done by using Euler's method to solve the projectile motion.

The following ammo types are supported more or less:

- MissileCore and its sub-types.
- BulletCore and its sub-types.
- BombCore and its sub-types.
- `MissileCore` and its sub-types.
- `BulletCore` and its sub-types.
- `BombCore` and its sub-types.

Installing and usage
--
**Note that you currently need to run this on the ArmA 3 dev branch due to the required vector functions that aren't yet on the main version.**
You just need to download the script files into your mission root so that the main function is in jonimake_ccip folder inside the mission root.
The script package has been tested with the following folder structure:
```sh
missionRoot
│ mission.sqm
└───jonimake_ccip
│ getImpactPos.sqf - BulletCore solver
│ getImpactPosBomb.sqf - BombCore solver
│ getImpactPosRocket.sqf - MissileCore solver
│ includes.sqf - contains pre-processor defs for debugging
│ jonimake_ccip.sqf - main script file
└───ccipProviders - place additional ccipProvider.sqf files here
B_Plane_CAS_01_F_ccipProvider.sqf
O_Plane_CAS_02_F_ccipProvider.sqf
I_Plane_Fighter_03_CAS_F_ccipProvider.sqf
```
Run the script by writing the following script into the vehicle init:
```
handle = this execVM "jonimake_ccip\jonimake_ccip.sqf"
```
This event handlers to the vehicle that will enable and disable the ccip solver as needed.
**Note:** Running on ArmA 3 dev branch is no longer a requirement.

[Install as a regular ArmA 3 addon](http://www.armaholic.com/forums.php?m=posts&q=20866).

Configuring allowed weapons
--
In order to enable CCIP on a certain aircraft, you have to define all CCIP compatible weapons in a file that uses the vehicle type name suffixed with _ccipProvider.sqf.
In order to enable CCIP on a certain aircraft, you have to define all CCIP
compatible weapons in a file that uses the vehicle type name suffixed with
`_ccipProvider.sqf`.

For example, the BLUFOR jet would use a file called
`B_Plane_CAS_01_F_ccipProvider.sqf` of which you can find an example below.

For example, the BLUFOR jet would use a file called B_Plane_CAS_01_F_ccipProvider.sqf of which you can find an example below.
```sqf
_allowedWeapons = [
"Rocket_04_HE_Plane_CAS_01_F",
"Rocket_04_AP_Plane_CAS_01_F",
"Gatling_30mm_Plane_CAS_01_F",
"Bomb_04_Plane_CAS_01_F"];

//These functions will be called in the jonimake_ccip.sqf file.
//The current plane is passed as _this parameter and the function
//has to return the position of the weapon in model space. This means
//you can either call _this selectionPosition "memoryposname" or just
//return the position as a three index array like the _heRocketInfo for example.
"Rocket_04_HE_Plane_CAS_01_F",
"Rocket_04_AP_Plane_CAS_01_F",
"Gatling_30mm_Plane_CAS_01_F",
"Bomb_04_Plane_CAS_01_F"
];

// These functions will be called in the jonimake_ccip.sqf file.
// The current plane is passed as _this parameter and the function
// has to return the position of the weapon in model space. This means
// you can either call _this selectionPosition "memoryposname" or just
// return the position as a three index array like the _heRocketInfo for example.
_gatlinInfo = {
_this selectionPosition "Gatling_barrels_end";
};
Expand All @@ -96,17 +90,35 @@ _pairs = [_pairs,"Gatling_30mm_Plane_CAS_01_F",_gatlinInfo,false] call BIS_fnc_a
_pairs = [_pairs,"Rocket_04_HE_Plane_CAS_01_F",_heRocketInfo,false] call BIS_fnc_addToPairs;
_pairs = [_pairs,"Rocket_04_AP_Plane_CAS_01_F",_apRocketInfo,false] call BIS_fnc_addToPairs;

[_allowedWeapons , _pairs]; //return as an array that contains the allowed weapons list and the pairs data structure
[_allowedWeapons , _pairs]; // Return as an array that contains the allowed weapons list and the pairs data structure
```

License
Authors
--
MIT License:

Copyright (C) 2014 Joni Mäkelä
- Arma-CCIP is written by Joni Mäkelä (@jonimake).
- Addon version by Lars Storjord (@lstor).

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
License
--
MIT License:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Copyright (C) 2014 Joni Mäkelä

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions addons/arma_ccip/config.cpp
@@ -0,0 +1,20 @@
class CfgPatches {
class arma_ccip {
units[] = {};
weapons[] = {};
requiredVersion = 0.1;
requiredAddons[] = {"A3_Air_F"};
author[] = {"jonimake", "Lstor"};
};
};

class CfgFunctions {
class ccip {
class ccip_functions {
class ccip_main {
file = "\arma_ccip\init.sqf";
postInit = 1;
};
};
};
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion includes.sqf → addons/arma_ccip/includes.sqf
Expand Up @@ -7,4 +7,4 @@
//#define TRACE

//visualize weapon position on aircraft
//#define WEAPON_POS_DEBUG
//#define WEAPON_POS_DEBUG
37 changes: 26 additions & 11 deletions jonimake_ccip.sqf → addons/arma_ccip/init.sqf
@@ -1,5 +1,8 @@
// CCIP script by Joni Mäkelä
// Addon version by Lars Storjord
//
// For custom vehicles please provide a provider TODO description

#include "includes.sqf"
ccip_iterations = 512;

Expand Down Expand Up @@ -27,7 +30,7 @@ sampleRatio = 1/numSamples;
ccipString = "";
ccipColor = [0,1,0,0.5];
ccipColor2 = [1,0,0,.5];
ccipIcon = getText (configfile >> "CfgWeaponCursors" >> "arifle" >> "texture");//(configfile >> "CfgWeaponIcons" >> "srifle");
ccipIcon = getText (configfile >> "CfgWeaponCursors" >> "arifle" >> "texture");
ccipFontSize = 0.0175 * SafeZoneW;
ccipIconHeight = 1;
ccipIconWidth = 1;
Expand All @@ -41,9 +44,9 @@ trajectoryPositions = [];
currentPlane = objNull;
currentProvider = [];

getImpactPos = compile preprocessFileLineNumbers "jonimake_ccip\getImpactPos.sqf";
getImpactPosRocket = compile preprocessFileLineNumbers "jonimake_ccip\getImpactPosRocket.sqf";
getImpactPosBomb = compile preprocessFileLineNumbers "jonimake_ccip\getImpactPosBomb.sqf";
getImpactPos = compile preprocessFileLineNumbers "arma_ccip\getImpactPos.sqf";
getImpactPosRocket = compile preprocessFileLineNumbers "arma_ccip\getImpactPosRocket.sqf";
getImpactPosBomb = compile preprocessFileLineNumbers "arma_ccip\getImpactPosBomb.sqf";

getDrawPos = {
_plane = _this;
Expand Down Expand Up @@ -177,14 +180,15 @@ ccip_shutdown = {
};

ccip_start = {
private "_plane";
_plane = _this select 0;
_engineState = _this select 1;
if(!_engineState) exitWith {
call ccip_shutdown;
};
if(isPlayer (driver _plane) && ! ccip_hasEventHandler) then {
currentPlane = _plane;
_providerFileName = "jonimake_ccip\ccipProviders\" + (typeOf _plane + "_ccipProvider.sqf");
_providerFileName = "arma_ccip\ccipProviders\" + (typeOf _plane + "_ccipProvider.sqf");
currentProvider = call compile preprocessFileLineNumbers _providerFileName; //returns a pairs array (hashmap/dictionary of some sorts)
["ccip_frameHandler", "onEachFrame", {
call calculateImpactPoint;
Expand All @@ -196,10 +200,21 @@ ccip_start = {
};
};

if(_this isKindOf "plane") then {
_getOutHandle = _this addEventHandler ["GetOut", {_this spawn ccip_shutdown}];
_startHandle = _this addEventHandler ["Engine", {[(_this select 0), (_this select 1)] spawn ccip_start}];
if(isPlayer driver _this) then {
_handle = [_this, isEngineOn _this] spawn ccip_start;
// Main entry point below

while {true} do {
// Check every 1 sec if player is in a plane
waitUntil { sleep 1; vehicle player != player && {(vehicle player) isKindOf "plane"} };

private "_vehicle";
_vehicle = vehicle player;

_getOutHandle = _vehicle addEventHandler ["GetOut", {_this spawn ccip_shutdown}];

if(isEngineOn _vehicle) then {
_handle = [_vehicle, true] spawn ccip_start;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the endless while loop execute this all the time when the player is inside the vehicle and the engine is on?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, you're right. Not sure how I missed that. That should definitely be fixed.

} else {
_startHandle = _vehicle addEventHandler ["Engine", {[(_this select 0), (_this select 1)] spawn ccip_start}];
};
};
};

5 changes: 5 additions & 0 deletions mod.cpp
@@ -0,0 +1,5 @@
name = "Arma-CCIP";
picture = "";
actionName = "Website";
action = "http://github.com/jonimake/arma-ccip";
description = "Arma-CCIP is a CCIP (Continuously Computed Impact Point) solver for aircraft in ArmA 3.";