ID:271444
 
Hello once again,

Pre-Post Request for Lummox JR's Help?

This time I am having trouble with my combat system and targeting. The combat proc that for so long housed the complex damage calculation for macro based combat is no longer sufficient, it causes run time errors when it pulls a death check proc that requires item spawning and at this point in my alteration of it, it just won't work properly. If you ever played Ultima Online, that is a generalized basis for where I am headed with Imersia. I need help in creating a targeting system that is flexible, concise, and properly coded.

In the target system I need;

Click based selection of a target, including yourself.
A war-mode toggle;
Target nearest player;
Target nearest monster;
Target self;
Clear target;

What I need in the combat system;

A proc that will handle something to the extent of while you are in 'warmode', if you aren't 'attacking', you do have an 'enemy', and if you are within attacking 'range', attack that enemy. I have other procs that handle what kind of damage will be dealt by the aggressor and what dissipation the defender will have, a skill checking system for gains and a death-check proc, but all of these are old and poorly coded even from what I can tell and I need to just revamp the whole system so it will nolonger be a sore point.

Right now I am at a place in my coding that I can tell I could easily lose steam and send this project into the abyss of unfinished work. Alot of other content hinges on the completion of working combat, including the archery and the magic, and I feel stranded at the moment.

Thankyou in advance for your help,

-R. Shannon

-- Since I am trying to learn at the moment, if you have only moderate skill at coding, I would ask that you do not reply. I need to learn the best possibly way, the most concise, why and how. I am more familiar with Lummox JR's coding style since most of the systems I have had problems with constructing have been patched and reworked by him. But I would love the advice or input of any skilled programmer. 10 skilled viewpoints may show me different ways of getting to the final answer and may also leave room to discuss and find the best solution.

-- It doesn't take a very large stretch of the imagination to gather that I am not an accomplished coder. My first language was DM, and I have only dabbled in it for a few years. Now that I am trying to undertake a large project the only way that this can be done is if I receive instruction on why and how so that I can add it to my bank of knowledge. The hope is that next time I won't hit a brick wall, but instead will see a solution.
When you have your design boiled down to the level you have there, where you have very specific actions, just make a function for each and have each one do exactly what you stated in each point.
#define PLAYER 1
#define MONSTER 0
//macro constants to pass to targetNearest function

mob
var
mob/target
warMode = 0
proc
target(mob/M)
target = M
targetNearest(type)
/* call targetNearest(PLAYER) to target the nearest player
call targetNearest(MONSTER) to target the nearest monster */

var
mob/closestTarget
distance = world.view + 1
for(var/mob/M in oview(src))
if(!(M.client^type)) continue
// The above line uses an "exclusive or" to exclude the appropriate characters (players or monsters)
if(get_dist(src, M) < distance)
// If this mob is closer than the closest checked so far, it is now set as the closest
closestTarget = M
// at this point we either have the closest target, or closestTarget is null if there are none in view
return closestTarget
targetSelf()
target(src)
warModeOn() warMode = 1
warModeOff() warMode = 0
warModeToggle() warMode = !warMode
warMode()
//this is the proc that "handles something to the extent of while you are in 'warmode'", as you put it
Click()
usr.target(src)

When you have your ideas refined that far, you basically just set up a bunch of simple functions like that, then call them as needed. For example...
mob
verb
Target_Self()
targetSelf()
War_Mode()
warModeToggle()
mob/monster
New()
warModeOn()
spawn() AI()
proc/AI()
while(1)
target = targetNearest(PLAYER)
if(!target)
step_rand(src)
sleep(10)

Or something along those lines.

The hardest part is actually disecting the game design until you get it down to the precision of what you said you wanted.

If that's not what you were after, what exactly were you asking about? You sounded pretty confidant in what you wanted already.
In response to Loduwijk
Loduwijk wrote:
if(!(M.client^type)) continue

Uhm, perhaps I am mistaken, but isn't such operator exclusive to numbers? What would it do otherwise?
In response to DivineO'peanut
He isn't actually using the datum.type var, the arguments in a proc get read first. Consider this.
obj/proc/SetName(mob/src)
name = input(src,"What shall you call [name]") as text

Although this is a horrible way to do something the argument src is a mob. Normally if I used mob/M input wouldn't be received.
In response to Xx Dark Wizard xX
Yes; this is true, however I was asking more about the use of ^ in this: seeing as ^ is an operator exclusive to numbers(i think), how can a statement such as <code>M.client^type</code>, where, as at least one of the operators is not a number, be vaild?

Sorry if I misunderstood you.
In response to DivineO'peanut
Yes, thank you for pointing that out. I wasn't thinking of that when I made the example. I'll have to check that out later, but you're probably right. However, that can be easily remedied with a function, macro, or with the '?:' operators.