• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Below 100-line useful code challenge

Status
Not open for further replies.

Deleted member 219079

D

Deleted member 219079

SORRY MODS I'M NOT POSTING IT HERE ON OFF-TOPIC TO BE RUDE OR SOMETHING, I just.. World Editor Help Zone, no... JASS Class, h*ll no... Map Development, uh no... Triggers & Scripts, oh yes, wait, "In this forum you may ask for help on fixing a trigger or script." k not then... yeah..? Where's the WE Discussion Sub-Forum?

jondrean's Below 100-line useful code challenge


JASS:
//! textmacro NewMotion takes TYPE, DYNAMIC, PARAMETERS, PREFIX
function $TYPE$Motion takes $PARAMETERS$ returns nothing
    local motiondata data
    local timer t
    if TAKEN[GetUnitIndex($PREFIX$u)] then
        return
    endif
    set data = motiondata.create()
    set t = NewTimer()
    call SetTimerData(t,data)
    call UnitAddAbility($PREFIX$u, FLY_ID)
    call UnitRemoveAbility($PREFIX$u, FLY_ID)
    set TAKEN[GetUnitIndex($PREFIX$u)] = true
    set data.d = $DYNAMIC$
    set data.ef = $PREFIX$endfunc
    set data.g = 0
    set data.uX = GetUnitX($PREFIX$u)
    set data.uY = GetUnitY($PREFIX$u)
    set data.uZ = GetUnitZ($PREFIX$u)
    set data.u = $PREFIX$u
    set data.x = $PREFIX$x
    set data.y = $PREFIX$y
    set data.z = $PREFIX$z
    set data.b = $PREFIX$bounce
    call TimerStart(t, 0.03125, true, function Step)
endfunction
//! endtextmacro
//! textmacro InsertEnd
    set TAKEN[GetUnitIndex(data.u)]=false
    call SetUnitZ(data.u, 0)
    if data.ef != "" then
        set udg_MS_u = data.u
        call ExecuteFunc(data.ef)
    endif
    set data.u = null
    call data.destroy()
    call ReleaseTimer(t)
//! endtextmacro
library MotionSystem /*v.1.0.1*/ requires TimerUtils, PUI //or other unit indexer
    globals
        private constant location L = Location(0,0)
        private constant integer FLY_ID = 'Arav'
        private boolean array TAKEN
    endglobals
    struct motiondata
        unit u
        string ef
        real uX
        real uY
        real uZ
        real x
        real y
        real z
        real b
        real g
        boolean d
    endstruct
    private function GetUnitZ takes unit u returns real
        if GetUnitFlyHeight(u) <= 1 then
            return 0.
        endif
        call MoveLocation(L, GetUnitX(u), GetUnitY(u))
        return GetLocationZ(L) + GetUnitFlyHeight(u)
    endfunction
    private function SetUnitZ takes unit u, real height returns nothing
        call MoveLocation(L, GetUnitX(u), GetUnitY(u)) //z height of terrain belove u
        call SetUnitFlyHeight(u, height-GetLocationZ(L), 0) //minus the height of terrain, it automatically raises the unit z already
    endfunction
    private function Step takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local motiondata data = GetTimerData(t)
        set data.g = data.g + 0.5
        if not data.d then
            set data.uX = data.uX + data.x
            set data.uY = data.uY + data.y
        endif
        set data.uZ = data.uZ + data.z - data.g
        if data.uZ > 0 then
            if data.d then
                call SetUnitX(data.u, GetUnitX(data.u)+data.x)
                call SetUnitY(data.u, GetUnitY(data.u)+data.y)
            else
                call SetUnitX(data.u, data.uX)
                call SetUnitY(data.u, data.uY)
            endif
            call SetUnitZ(data.u, data.uZ)
        else
            set data.x = data.x * data.b
            set data.y = data.y * data.b
            set data.z = data.z * data.b
            set data.g = 0
            if data.z < 2 then
                //! runtextmacro InsertEnd()
            endif
        endif
    endfunction
    //! runtextmacro NewMotion ("", "false","unit u, real x, real y, real z, real bounce, string endfunc","")
    //! runtextmacro NewMotion ("Free", "false","unit u, real x, real y, real z, real bounce, string endfunc","")
    //! runtextmacro NewMotion ("GUI", "udg_MS_free","nothing","udg_MS_")
endlibrary

Example GUI usage trigger:
  • ASD
    • Events
      • Player - Player 1 (Red) types a chat message containing asd as An exact match
    • Conditions
    • Actions
      • Custom script: local real angle = 0
      • Custom script: local real speed
      • Custom script: set udg_count = GetRandomInt(15,20)
      • For each (Integer i) from 1 to count, do (Actions)
        • Loop - Actions
          • Custom script: set speed = GetRandomReal(4.6,6.0)
          • Custom script: set angle = angle + (360/udg_count) + GetRandomReal(-15.,15.)
          • Custom script: set udg_MS_u = CreateUnit(Player(0),'h000',0,0,angle)
          • Custom script: //! runtextmacro InsertCoordCalculation("Cos","udg_MS_x")
          • Custom script: //! runtextmacro InsertCoordCalculation("Sin","udg_MS_y")
          • Set MS_endfunc = Trig_END_Actions
          • Set MS_bounce = 0.60
          • Set MS_free = False
          • Set MS_z = (Random real number between 10.00 and 15.00)
          • Custom script: call GUIMotion()
UPDATE:
Video of 1.0.1 in action, running ~400 instances constantly:
Triggers for looping action:
  • LOOP
    • Events
      • Time - Elapsed game time is 2.00 seconds
    • Conditions
    • Actions
      • -------- (text macro's in the header code) --------
      • -------- //! textmacro InsertCoordCalculation takes TYPE, VARIABLE --------
      • -------- set $VARIABLE$ = speed * $TYPE$(angle * bj_DEGTORAD) --------
      • -------- //! endtextmacro --------
      • Custom script: local real angle = GetRandomReal(0,360)
      • Custom script: local real speed
      • Custom script: set speed = GetRandomReal(4.6,6.0)
      • Custom script: set udg_MS_u = CreateUnit(Player(0),'h000',0,0,angle)
      • Custom script: //! runtextmacro InsertCoordCalculation("Cos","udg_MS_x")
      • Custom script: //! runtextmacro InsertCoordCalculation("Sin","udg_MS_y")
      • Set MS_endfunc = Trig_END_Actions
      • Set MS_bounce = 0.60
      • Set MS_free = False
      • Set MS_z = (Random real number between 10.00 and 15.00)
      • Custom script: call GUIMotion()
      • Custom script: if GetPlayerState(Player(0), PLAYER_STATE_RESOURCE_FOOD_USED) < 400 then
      • Trigger - Run (This trigger) (ignoring conditions)
      • Custom script: endif
  • END
    • Events
    • Conditions
    • Actions
      • Unit - Kill MS_u
      • Custom script: if GetPlayerState(Player(0), PLAYER_STATE_RESOURCE_FOOD_USED) < 400 then
      • Trigger - Run LOOP <gen> (ignoring conditions)
      • Custom script: endif


Rules:
  1. You can use known libraries/Utils for your help
  2. Just for fun, if you're as enthuastic coder as me you may like it
  3. Try to make something which can be used for useful purposes on a map
  4. It must work
  5. It can be GUI, you just need to count it from start of events block to the last function row

Rewards:
A compliment​

Edit: Updated my own mini system to 1.0.1 (some bug fixes and on death function feature added, 100 rows)
 
Last edited by a moderator:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Change the rules to 100 lines of compiled JASS and you may be on to a real challenge, but currently nothing stops you from just linking a dozen libraries into an ultra useful pack.

5.It can be GUI, you just need to count it from start of events block to the last function row
In that case vJASS should be counted in number of optimized compiled lines as well. It is not fair that you treat GUI (a compiled language) differently from vJASS (another compiled language).
 

Deleted member 219079

D

Deleted member 219079

Hundred lines of compiled script? Compiled = went through preprocessor, or?

I posted an example on the format what I meant, an useful system, 100 lines, uses known utils/libraries and so on.
 
Level 15
Joined
Mar 31, 2009
Messages
1,397
I made a Fizzbuzz in C, does this count? :^)

JASS:
#include <stdio.h>
#include <stdint.h>
#include <string.h>
 
#define prel_size (10)
#define each_size (8 + 8 + 5)
#define prol_size (4)
 
typedef void (*program_func_t)();
uint8_t program[prel_size +
                each_size * 100 +
                prol_size];
 
#define program_eval ((program_func_t)program)
 
int seq (uint32_t* bufs, int n)
{
    bufs[1] = 0x00000000;
 
    if (n % 5 && n % 3)
    {
        sprintf((char*)&bufs[0], "%d", n);
        return 1;
    }
    else if (n % 5)
    {
        bufs[0] = 0x7a7a6966;
        return 2;
    }
    else if (n % 3)
    {
        bufs[0] = 0x7a7a7562;
        return 2;
    }
    else
    {
        bufs[0] = 0x7a7a6966;
        bufs[1] = 0x7a7a7562;
        bufs[2] = 0x00000000;
        return 3;
    }
}
void program_write ()
{
    uint8_t* buf = program;
    uint8_t i, s;
    uint32_t str_bufs[3];
 
    memcpy(buf, "\x83\xec\x10"
                "\x8d\x44\x24\x04"
                "\x89\x04\x24",
                prel_size);
    buf += prel_size;
 
    for (i = 1; i <= 100; i++)
    {
        for (s = seq(str_bufs, i); s-- > 0; )
        {
            *(buf++) = 0xc7;
            *(buf++) = 0x44;
            *(buf++) = 0x24;
            *(buf++) = (s + 1) * sizeof(uint32_t);
            *((uint32_t*)buf) = str_bufs[s];
            buf += 4;
        }
 
        *(buf++) = 0xe8;
        *((uint32_t*)buf) = (uint32_t)puts - (uint32_t)buf - 4;
        buf += sizeof(uint32_t);
    }
 
    memcpy(buf, "\x83\xc4\x10"
                "\xc3",
                prol_size);
}
 
int main ()
{
    program_write();
    program_eval();
}
 

Deleted member 219079

D

Deleted member 219079

It means it has gone through the pre-processor. This is to match the rules you placed on GUI which also counts the end of all the trigger functions (again after pre-processor).
For GUI the rule is:
Amount of rows from the start of event block to the last line, this is easily calculated if you copy as text > paste to notepad, make notepad show line numbers.

I think the rule is soft for GUI atm, gui generates a lot of trash functions and so on, which we won't count. If we counted compiled GUI, Melee Initialization wouldn't pass.


That's marvelous Blarg! :) And only 81 lines, good job!
 
Status
Not open for further replies.
Top