System Get Costs and Bounty

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
local integer id = itemTypeId-(itemTypeId/8191)*8191
            loop
                exitwhen itemTypes[id] == itemTypeId or itemTypes[id] == 0
                set id = id + 1
            endloop

C'mon mate, rip Hash off. You don't do a check in your loop for increasing over 8191, and the increment insinuates high complexity for consecutive item ids upon collision (example, using theoretical values 1, 2, 3, 4, 5 and then 8192 will loop for longer for 8192, because you do +1 instead of +90 or +53 or some other value - and consecutive item ids are common in custom items, so this is worth changing).

Aside from that, looking better! ;)

Also:
Scopes fail hard in vJass I find. I don't know if this is fixable...
JASS:
scope Units
        globals
            public integer array goldCost

I believe that exposes Units_goldCost inappropriately, right? You may want to avoid scopes in libraries, as making the scope private doesn't work off memory. (One of the bugs I can't report. :()
 

Nestharus

o-o
Reaction score
84
Ok, removing all of the cons for the next update (or most of them), meaning that you'll be able to use any player in your game and all their stuff without anything getting screwed up.

Stores previous gold and bounty, sets it to 0/1000000, then sets it back
Messes with foodcap for duration
The unit person now uses 0 food =)

playerChecker can still not be altered because other players will bug up : (, and it's just safest to use 14 ^_^.

Also will do the thing with 8191 : D.

And the scopes don't really need to be there. The variables are exposed so that you could in essence use the GetItemId and GetUnitId for multiple units and access the variable directly, but it's not really documented on =).
 

Nestharus

o-o
Reaction score
84
What else do I need to add to documentation?

Has a full description

List of functions
List of variables

The internal function isn't really meant to be used (GetItemId/GetUnitId) so it's not included in the documentation as it would be used to directly access variables within the system : ).
 

Jesus4Lyf

Good Idea™
Reaction score
397
Should ideally be encapsulated then.

I'd state how it works, any cons or things you need to be aware of, and maybe put a heading on the first post. :p

Damage type should be universal, attack type normal I think - does that hit invulnerable units?
JASS:
public function GetItemId takes integer itemTypeId returns integer
            local integer playerGold
            local integer playerWood
            local integer id = itemTypeId-(itemTypeId/8191)*8191
            loop
                exitwhen itemTypes[id] == itemTypeId or itemTypes[id] == 0
                set id = id + 35
                if id > 8191 then
                    set id = 1
                endif
            endloop
            if (itemTypes[id] == 0) then
                set playerGold = GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD)
                set playerWood = GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER)
                set itemTypes[id] = itemTypeId
                set currentItemType = itemTypeId
                set currentItemId = id
                call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD, RESOURCE_LIMIT)
                call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER, RESOURCE_LIMIT)
                call AddItemToStock(costRetriever, itemTypeId, 1, 1)
                call IssueNeutralImmediateOrderById(playerChecker, costRetriever, itemTypeId)
                set goldCost[id] = RESOURCE_LIMIT - GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD)
                set woodCost[id] = RESOURCE_LIMIT - GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER)
                call RemoveItemFromStock(costRetriever, itemTypeId)
                call EnumItemsInRect(removalArea, null, function RemoveItems)
                call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD, playerGold)
                call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER, playerWood)
            endif
            return id
        endfunction
-->
JASS:
public function GetItemId takes integer itemTypeId returns integer
            local integer playerGold
            local integer playerWood
            local integer id = itemTypeId-(itemTypeId/8191)*8191
            loop
                if (itemTypes[id] == 0) then
                    set playerGold = GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD)
                    set playerWood = GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER)
                    set itemTypes[id] = itemTypeId
                    set currentItemType = itemTypeId
                    set currentItemId = id
                    call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD, RESOURCE_LIMIT)
                    call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER, RESOURCE_LIMIT)
                    call AddItemToStock(costRetriever, itemTypeId, 1, 1)
                    call IssueNeutralImmediateOrderById(playerChecker, costRetriever, itemTypeId)
                    set goldCost[id] = RESOURCE_LIMIT - GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD)
                    set woodCost[id] = RESOURCE_LIMIT - GetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER)
                    call RemoveItemFromStock(costRetriever, itemTypeId)
                    call EnumItemsInRect(removalArea, null, function RemoveItems)
                    call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_GOLD, playerGold)
                    call SetPlayerState(playerChecker, PLAYER_STATE_RESOURCE_LUMBER, playerWood)
                endif
                exitwhen itemTypes[id] == itemTypeId // or itemTypes[id] == 0
                set id = id + 35
                if id > 8191 then
                    set id = id - 8191 // Improvement. Minimal collision chances.
                endif
            endloop
            return id
        endfunction
 

Nestharus

o-o
Reaction score
84
No cons left, I removed them all : ), but I'll explain how it works sure ^_^.

Also made things private via removing scopes : ).

Well, actually there is are 2 sort of cons left I guess.. they are in the first post : )
 

Nestharus

o-o
Reaction score
84
Updated for performance improvements and use with latest player tracking : ).

boolexprutils req was removed =).
 

Jesus4Lyf

Good Idea™
Reaction score
397
Aside from requireing graveyarded resources and having this settings area that makes no sense to anyone except Nestharus, this is looking pretty good.
JASS:
Settings:
*///===================================================================
//! textmacro Gcsn_USER_SETTINGS
    set coordX = GetRectCenterX(bj_mapInitialPlayableArea)
    set coordY = GetRectCenterY(bj_mapInitialPlayableArea)
//! endtextmacro

//! textmacro Gcsn_REGISTERED_PLAYERS
    exitwhen x == GetPlayerCount()
    set p = GetPlayer(x)
//! endtextmacro

//! textmacro Gcsn_EXTRA_PLAYERS
    //call TriggerRegisterPlayerUnitEvent(decay, Player(15), EVENT_PLAYER_UNIT_DEATH, null)
//! endtextmacro

...?
This also still doesn't implement GetDeathBounty as an event response like I mentioned in that other thread. Please steal said code. If you fix all this maybe this can be approved. :)

Oh, one more thing.
The name must be changed from "states", as this has nothing to do with states. You should know that unit states and player states exist as native stuff in WC3.

Using standard naming conventions for your library would also be greatly appreciated and give people a chance in hell of finding this (actually, the name I gave the thread does that for you).
 

Nestharus

o-o
Reaction score
84
Aside from requireing graveyarded resources and having this settings area that makes no sense to anyone except Nestharus, this is looking pretty good.

The settings are is inputted all over the code, lol. Unless you'd rather hunt thru the code to change settings? : P.

And the graveyarded resource is a utility that filters players. I'd have to write the same code in the ini of Ptn into this for ini, and because I always had to write the same lines of code over and over again, I made Ptn so I wouldn't have to ^_^. Also, Ptn has had some updates =p.


This also still doesn't implement GetDeathBounty as an event response like I mentioned in that other thread. Please steal said code. If you fix all this maybe this can be approved.

All right, i'll add it in as an optional add on =).

The name must be changed from "states", as this has nothing to do with states. You should know that unit states and player states exist as native stuff in WC3.

Actually it does have states in it. You can get total resources of a player, and you can get default item charges. I figured it was pretty appropriate, but it really does states, costs, and bounty =O.

I'll think of another name I guess if you don't approve of states, but how else do describe player states : \.

Using standard naming conventions for your library would also be greatly appreciated and give people a chance in hell of using this (actually, the name I gave the thread dose that for you).

so you mean you want me to name the library GetCostsStatesAndBounty? GetCostsAndBounty isn't accurate =).

Personally I prefer typing Gcsn as it is immeasurably shorter, but it's up to you guys =).

As for naming of the functions and vars, I followed JASS convention =).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top