News:

SMF - Just Installed!

Main Menu

Dagger hotkey

Started by d.healey, August 13, 2017, 01:31:27 AM

Previous topic - Next topic

d.healey

If you take requests could we have a hot key for throwing daggers?

Stephen

I guess, but the problem is, I don't really have much time to develop the game nowadays. I will fix any major bugs or crashes if they come up, but I'm not really adding new features at the moment.

I would like to get back into development at some point but right now I don't have a lot of spare time unfortunately.

In the meantime the game is open source so if anyone wants to have a go at adding new stuff then they are more than welcome to do so, and I will assist in whatever way I can.

d.healey

Yeah that's fair enough. Well I don't mind having a tinker with it, it's been a long time since I worked in C++ though and never on a largish project like Knights so a few pointers are appreciated.

I can see there are a number of a keyboard controller files in the main folder - I guess this is where I should be looking?

Stephen

Well, there is the Controller base class and an implementation for KeyboardController. (There was originally going to be other implementations for things like joysticks or gamepads, I never got around to that though.) This basically just gives you up/down/left/right and "fire button" functionality and mostly relates to the old style (original Amiga knights) controls.

The mouse controls (the "action bar" thing that you click on using the mouse) got added later, and this is partly implemented in the ActionBar class and partly in LocalDisplay::readControl.

The main logic for controls is in LocalDisplay::readControl so that's probably what you need to read if you want to understand how controls work.

There is also a UserControl class -- a UserControl represents something you can do in the game, like moving, or swinging a weapon, or picking up an item. (Or throwing a dagger.) Each UserControl has various pieces of information attached to it:
- the id number, which (I think) is used by the game engine to match the UserControl up to the actual code that executes the action.
- the "menu graphic" which is the icon that appears on the action bar (or the menu if using old style controls)
- the "menu direction" which controls where it appears on the old style 4-way menu
- the "tap priority" which I think controls what happens when you just tap the fire button (this is context sensitive so the highest priority action is selected)
- the action bar slot and priority, which controls where it appears on the action bar
- whether it is continuous (like lock picking) or not (like opening a door)
- the name (which acts as a "tool tip" if using the action bar)
- a couple of other things which I can't remember what they do now.

The UserControl instances are configured in Lua scripts, have a look at controls.lua and items.lua (they are hidden somewhere under the knights_data/server directory).

The responsibility of LocalDisplay::readControl is to look at the player's control inputs (keyboard, mouse etc) and work out which UserControl (if any) should be activated as a result.

The actual UserControl that LocalDisplay::readControl selects from are set up in two places:
- LocalDisplay::setAvailableControls is called by the game engine to notify it of which context-sensitive controls (such as opening a chest) are currently available.
- There is also a set of "standard_controls" (such as movement) that are always available.


Anyway, I guess that's some info about how the code works...


Note that the current Controller interface assumes there is only one fire button. An idea I had a long time ago was to have a "two fire button" system. The first button would be for "melee attack" (so swing your sword, axe or hammer) and the second would be "missile attack" (so either throw an axe, shoot a crossbow, or throw daggers depending on what the player has available). Maybe now is the time to look at implementing that...

d.healey

Thanks for the detailed info. I shall spend some time now getting to grips with the code.

K9

Same here Stephen...  Thank you for exceptional coding tips on this subject of controls and routines to explore, and your open source, site content and more.

+


Addendum, unrelated to above topic...

Been a long time since last met you in the dungeons, but I'm always thinking about you, grateful for all you've done, and doing to keep the server active for loyal fans (Moo, ImpassIve & myself routinely in Saturday/weekend quests) and great to see you're still in tune with quick response on forum.

I definitely relate to being busy, see you around.