1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Suggested mod development improvements

Discussion in 'Modding [KAG]' started by Vermilicious, Feb 4, 2016.

  1. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    I decided to make a post here for things I encounter while working with my mod that I think should be improved upon. I'll add to the list if I discover something more.

    1. To use a custom map loader by extending PNGLoader, you will have to either override DefaultLoaders.as, or make a call to RegisterFileExtensionScript (in the InitializeGame function) by overriding the server script(s), or create your own script. Considering how easy it is to extend PNGLoader, actually enabling it should be easier, without having to override standard scripts, or create new ones just for this small thing. Mods should be as self-contained as possible. Additionally, LoadDefaultMapLoaders() is called in KAG.as without any effect (other than confusing modders). This line should be removed, or at least receive a comment that explains that this is not the place to add custom loaders.
    2. DefaultBuilding.as:22 : This script always create a window. That might not always be desirable. Not including this file in the blob configuration file can cause errors in drawing stuff correctly (transparency and layering issues). I fixed it by manually placing a tile in the same spot in my onTick function. My suggestion is to make this behavior optional, by checking for a particular tag on the blob object.
    3. CommonBuilderBlocks.as : The script only works with default game modes. There's no way to extend or manipulate the build menus defined here, without overriding the whole file, or manipulating the builder entity. This makes it impossible to make a custom game mode while keeping the mod completely self-contained. Perhaps a way to register these building options with the CRule object or RulesCore could be a solution.
    4. It is sometimes useful to use print() for debugging, but objects such as CBlob at least, does not have any toString function, so you'll have to manually build up the string every time you want to look at some basic stuff. I would suggest adding some such toString methods to common objects (or extend the print function). I realize not everything can be dumped, but for a CBlob for instance, the name, it's ID and tags would be very useful. For a Vec2f object a simple "(x,y)" string would've been nice.
    5. Character auto pickup-scripts (such as BuilderAutoPickup.as) contains hard-coded entity names for valid "pickupable" objects. If you want characters to be able to pick up other things, you will have to overwrite these files. Instead, I would suggest checking for a certain tag, which is set in onInit for the relevant entity types. That way, you can add new entity types that can be picked up without touching vanilla code.
    6. StandardPickup.as enables highlights for "pickupable" objects when the player presses the pick-up key ('C'). To override this behavior, you will either have to override this "hairy" script, or add/modify code to vanilla entities. I would've preferred of there was a flag you could set (same as the previous bullet point).
    7. It would seem that we're not allowed to create object handles (pointers) to instances of Vec2f. While normally, there's little, if any, benefit performance-wise to use pointers for such a small object (or maybe there's more stuff in there I don't know about), it also means you can't default to a null pointer in a function parameter list. I would suggest enabling handles for this type. Is there anything to lose?
     
    Last edited: Mar 9, 2016
  2. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    Self containment isn't really an option. The modding system was designed so that you could, for the most part, override files safely. This is the easiest way for us to create new code and anybody to play with it. Instead of having to make some api, containment module handling/loading etc. So unfortunately you aren't really going to get around not overriding files. If you want to add something without having to override an existing file. You could instead simply add a new file to the appropriate blob/gamemode config. Then modify some properties that are used by the blob to do what you need.

    Other than that, some day in the future clean up of certain scripts to make it more obvious how to extend them via the above method is due.
     
    Last edited: Feb 4, 2016
  3. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    For this undead mode thing I'm putting together, I've been able to contain everything except #1 and #3 in the list above. I wrote my own own RulesCore, MovementSystem, PNGLoader, rules, maps and entities (monsters and buildings). Everything is tied together with descriptors and hooks. It's one nice, tidy lump. The only files I have to override is DefaultLoaders.as and CommonBuilderBlocks.as. The first so I can even get my loader to load anything, the second because my game mode is not a vanilla mode. You are encouraged to extend functionailty, but it won't work. You can't make your own loader, and you can't invent a new game mode without messing with small pieces of code that could fairly easily have been made extendable. Why go to so much effort in parts of the system, but not small things like this. I'm not saying it has to be a particularly big problem - it isn't, but why not go the extra meter. I'm not suggesting any new API or nothing fancy. Anyway, I'm not really expecting anything. I thought I'd just put it out there. Take it or leave it. I'll make do anyway.
     
  4. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    If you have a clean solution to the problem, feel free to present it and it could be added to the base game, however I don't really see a good one that fits within the current framework. I also don't really have the time to put into developing one. Sorry.
     
  5. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Yeah I'll have to see about that, Verrazano. I want to finish my mod and stuff first :o)

    Added a bullet (#4) on toString/object debugging.
    --- Double Post Merged, Feb 28, 2016, Original Post Date: Feb 5, 2016 ---
    Added a bullet (#5) on auto pick-up scripts.
     
  6. Verrazano

    Verrazano Flat Chested Haggy Old Souless Witchy Witch Witch THD Team Global Moderator Forum Moderator Tester
    1. Practitioners of War Extreme Revolution - POWER

    Messages:
    477
    There is a print vec2f, check the functions.txt.
     
    Vermilicious likes this.
  7. Vermilicious

    Vermilicious Ballista Bolt Thrower

    Messages:
    232
    Thanks, Verrazano. I had to take a closer look at that folder. I hadn't noticed all those files earlier. Now I know.

    Added a bullet (#6) on a particular problem I came across in regards to StandardPickup.as.
    --- Double Post Merged, Mar 8, 2016, Original Post Date: Feb 29, 2016 ---
    Added bullet (#7) on object handles for Vec2f.
     
  8. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Firstly, handles are not pointers. They share some of a pointer's semantics and subvert them in other cases.

    For the same reason that you can't take handles to primitive types in AS - they aren't reference counted and therefore open up more chances for unsafe code. We're not going to bloat every vec2f in the game with a reference count, and we're not going to allow more unsafe handles.

    You can default to whatever value for parameter you like, if you want a "default", zero or some huge, negative vector are good choices depending on the application (they're in band, but in KAG in particular, large, negative, precise vectors are quite uncommon). You can also just provide an overload of the function that omits the parameter and define your (presumably more complicated) default there.

    If you want to modify the input, use a reference.

    (A lot of your woes come from you trying to write AS as C++ verbatim. They aren't the same language - they are similar but you'll do well from not bashing your head against the differences)
     
    Vermilicious likes this.