Hektor
New Member
- Reaction score
- 3
Hmm, this is just a project I'm working on. So far, all I've accomplished is Gravity.
Yes, I know it's not very optimized.
I'm just putting it together, at the moment. I'm planning on heavily optimizing it, so any tips and criticism are welcome.
(Yes, I know GetUnitDatas is used multiple times while unnecessary. I'm getting to addressing optimization still.)
Warning: Currently, all is in cJASS. A vJASS version will be up shortly after the cJASS edition is complete.
Also, one thing I was wondering, is using a key faster than StringHash?
Note: Hurrah, spoilers don't work (for people with low rep, I presume to decrease the amount of spoiler spam).
Yes, I know it's not very optimized.
I'm just putting it together, at the moment. I'm planning on heavily optimizing it, so any tips and criticism are welcome.
(Yes, I know GetUnitDatas is used multiple times while unnecessary. I'm getting to addressing optimization still.)
Warning: Currently, all is in cJASS. A vJASS version will be up shortly after the cJASS edition is complete.
Also, one thing I was wondering, is using a key faster than StringHash?
JASS:
library Uphc initializer Ini
globals
private hashtable Hash = new hashtable; // Data storage
private timer Timer = new timer;
endglobals
define {
GetUnitDatas( Gud_unit ) = { // Automated data gathering!
unit u = Gud_unit;
int Id = GetHandleId( u );
bool G = LoadBoolean( Hash, Id, Gravity );
real S = LoadReal( Hash, Id, Speed );
real M = LoadReal( Hash, Id, Mass );
real T = LoadReal( Hash, Id, Time );
real D = 0;
bool F = LoadBoolean( Hash, Id, Friction );
}
Gravity = StringHash( "Gravity" ); // Hash for Gravity
Group = StringHash( "Group" ); // Hash for Group
Speed = StringHash( "Speed" ); // Hash for Speed
Mass = StringHash( "Mass" ); // Hash for Mass
Time = StringHash( "Time" ); // Hash for Time
Friction = StringHash( "Friction" ); // Hash for Friction
GInactive = 0; // Index for Inactive
GActive = 1; // Index for Active
FInactive = 2; // Index for Inactive
FActive = 3; // Index for Inactive
DefaultGravity = 16; // Default Gravity
DefaultSpeed = DefaultMass * DefaultGravity; // Default Speed
DefaultMass = 100.00; // Default Mass
DefaultDamage = 150.00; // Default Damage
MaxNoDamageFall = 0.25; // Max fall height for no damage
MASSPERCENTAGE = 0.05; // Percentage of mass to decrease fall damage
DefaultFriction = 0.1; // Default Friction
}
private void GroupGravity( ) { // Group gravity
GetUnitDatas( GetEnumUnit() );
if Uchc_GetUnitZ( u ) <= 1 {
if T > MaxNoDamageFall {
D = T * DefaultDamage;
SetUnitState( u, UNIT_STATE_LIFE, GetUnitState(u, UNIT_STATE_LIFE) - D + MASSPERCENTAGE * M );
}
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GActive), u );
GroupAddUnit( LoadGroupHandle(Hash, Group, GInactive), u );
T = 0;
SaveReal( Hash, Id, Time, T );
return
}
T = T + TimerGetTimeout(Timer);
SaveReal( Hash, Id, Time, T );
S = Pow( DefaultMass, T )
SaveReal( Hash, Id, Speed, S);
Uchc_SetUnitZ( u, Uchc_GetUnitZ(u) - S);
}
private void GravityValidation( ) { // Gravity validation
GetUnitDatas( GetEnumUnit() );
if G == true {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GInactive), u );
GroupAddUnit( LoadGroupHandle(Hash, Group, GActive), u );
return
}
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GActive), u );
GroupAddUnit( LoadGroupHandle(Hash, Group, GInactive), u );
}
private void GroupFriction( ) { // Group friction
}
private void FrictionValidation( ) { // Friction validation
GetUnitDatas( GetEnumUnit() );
if F == true {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, FInactive), u );
GroupAddUnit( LoadGroupHandle(Hash, Group, FActive), u );
return
}
GroupRemoveUnit( LoadGroupHandle(Hash, Group, FActive), u );
GroupAddUnit( LoadGroupHandle(Hash, Group, FInactive), u );
}
private void Periodic( ) { // Main periodic
group GI = LoadGroupHandle( Hash, Group, GInactive );
group GA = LoadGroupHandle( Hash, Group, GActive );
group FI = LoadGroupHandle( Hash, Group, FInactive );
group FA = LoadGroupHandle( Hash, Group, FActive );
ForGroup( GI, function GravityValidation );
ForGroup( GA, function GravityValidation );
ForGroup( GA, function GroupGravity );
ForGroup( FI, function GravityValidation );
ForGroup( FA, function GravityValidation );
ForGroup( FA, function GroupFriction );
}
public void SetUnitFriction( unit whichUnit, bool flag ) { // Friction toggle
GetUnitDatas( whichUnit );
if flag != F {
SaveBoolean( Hash, Id, Friction, flag );
}
if flag == false {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, FActive), whichUnit );
GroupAddUnit( LoadGroupHandle(Hash, Group, FInactive), whichUnit );
} else {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, FInactive), whichUnit );
GroupAddUnit( LoadGroupHandle(Hash, Group, FActive), whichUnit );
}
}
public void SetUnitGravity( unit whichUnit, bool flag ) { // Gravity toggle
GetUnitDatas( whichUnit );
if flag != G {
SaveBoolean( Hash, Id, Gravity, flag );
}
if flag == false {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GActive), whichUnit );
GroupAddUnit( LoadGroupHandle(Hash, Group, GInactive), whichUnit );
} else {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GInactive), whichUnit );
GroupAddUnit( LoadGroupHandle(Hash, Group, GActive), whichUnit );
}
}
public void SetUnitMass( unit whichUnit, real mass ) { // Mass config
GetUnitDatas( whichUnit );
SaveReal( Hash, Id, Mass, mass );
}
public real GetUnitMass( unit whichUnit ) { // mass config
GetUnitDatas( whichUnit );
return M;
}
private bool Leave( ) { // Leave Flush
GetUnitDatas( GetTriggerUnit() )
if IsUnitType( u, UNIT_TYPE_DEAD ) {
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GInactive), u );
GroupRemoveUnit( LoadGroupHandle(Hash, Group, GActive), u );
GroupRemoveUnit( LoadGroupHandle(Hash, Group, FInactive), u );
GroupRemoveUnit( LoadGroupHandle(Hash, Group, FActive), u );
FlushChildHashtable( Hash, Id );
}
return false;
}
private bool Enter( ) { // Enter Add
GetUnitDatas( GetFilterUnit() );
if G == null {
SaveBoolean( Hash, Id, Gravity, true );
SaveReal( Hash, Id, Speed, DefaultSpeed );
SaveReal( Hash, Id, Mass, DefaultMass );
SaveReal( Hash, Id, Time, 0.00 );
SaveBoolean( Hash, Id, Friction, true );
}
if UnitAddAbility( u, 039;Amrf039; ) { // AutoFly -Azlier
UnitRemoveAbility( u, 039;Amrf039; );
}
GroupAddUnit( LoadGroupHandle(Hash, Group, GActive), u );
GroupAddUnit( LoadGroupHandle(Hash, Group, FActive), u );
return false;
}
private void Ini( ) {
region r = new region;
RegionAddRect( r, GetWorldBounds() );
TriggerRegisterEnterRegion( new trigger, r, Filter(function Enter) );
TriggerRegisterLeaveRegion( new trigger, r, Filter(function Leave) );
SaveGroupHandle( Hash, Group, GInactive, new group );
SaveGroupHandle( Hash, Group, GActive, new group );
SaveGroupHandle( Hash, Group, FInactive, new group );
SaveGroupHandle( Hash, Group, FActive, new group );
TimerStart(Timer, Uchc_defaultTimer, true, function Periodic)
}
endlibrary
JASS:
include "cj_types.j"
include "cj_typesEx.j"
include "cj_types_priv.j"
include "cj_typesEx_priv.j"
library Uchc initializer Ini
globals
public constant real defaultTimer = 0.0325;
public constant real defaultFast = 0.01;
private location heightFixer = Location(0,0);
endglobals
define {
msg(string) = DisplayTextToPlayer(GetLocalPlayer(), 0, 0, string);
}
public void SetUnitZ( unit whichUnit, real height ) {
call MoveLocation( heightFixer, GetUnitX(whichUnit), GetUnitY(whichUnit) );
call SetUnitFlyHeight( whichUnit, height-GetLocationZ(heightFixer), 0 );
}
public real GetUnitZ( unit whichUnit ) {
call MoveLocation( heightFixer, GetUnitX(whichUnit), GetUnitY(whichUnit) );
return GetUnitFlyHeight(whichUnit)-GetLocationZ(heightFixer);
}
void Ini( ) {
}
endlibrary
Note: Hurrah, spoilers don't work (for people with low rep, I presume to decrease the amount of spoiler spam).