Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → yes, PJB has retuened, and this time... AI are evil
yes, PJB has retuened, and this time... AI are evil
2004-01-13, 7:48 AM #1
right, i desided to make a simple AI script to sync AI and so on. the idea is that the target sync cog (i never did find out if i need it or not) and the AI server are in the placed cogs window

then copys of the AI_basic cog (one for eatch type of enermy template can be added to a temple with a ghost parent and no 3do. simple idea really..

but the cog wont work. and i dont know why.
if you are going to fix this cog i woudl prefer it if you just fix the cog as it is without rewriteing it from scratch. but if you cant i wont mind that mutch.

AI basic code
Code:
# JK cogscript
#
# PJ_AI_base.cog
#
# tell the AI server we have another AI
# note you need a new copy of this for every different template
# IE. the TPL assignment for the AI and the team int is the AI's 
# team, it will not attack a AI with the same team int, but can 
# attack any AI without it. works on the players team too,
# set it to -1 if you want it to allways attack anyone, finaly
# the int, dist is the maximum distance a target is away from the
# AI before it wont attack it, distance in JKU.
# cog only runs on the server's computer, so we know that its the
# right AI being synced
#  
# 13/jan/2004
# [PJB]

symbols
message		trigger
message		user0
message		user1
message		created
message		pulse
message		timer
thing		pos		local
# template	servertpl=serv	local
flex		killsleep=0	local
cog		AI_server	local
int		i=0		local
thing		AI		local

# the items below here (team maximum distance and template must be set
int		dist=5		local
int		team=-1		local
template	tpl=stormtroop2	local
end

# ========================================================================================

code
trigger:
// check if its the right trigger
if(getsourceref()!=135)return;
AI_server=getparam(0);
return;

created:
if(IsServer()==0) return;
// find the (after) killsleep, then remove the timer so we can create
// the thing later, without it being destroyed by the thinglife (timer)
pos=getsenderref();
killsleep=getlifeleft(pos);
SetLifeLeft(pos, 0); 

// now we have all we need lets send a nice user0 to the Ai server
// and watch the mayhem start, dammit i own  [http://forums.massassi.net/html/biggrin.gif]
SendMessageEx(AI_server, user0, tpl, pos, killsleep, team);
settimer(1.5);
Return;

user0:
if(IsServer()==0) return;
// this will send all the AI information to the AI_server when the AI
// needs to respawn. back and fourth we go  [http://forums.massassi.net/html/biggrin.gif]
SendMessageEx(AI_server, user2, tpl, pos, killsleep, team);
return;

user1:
if(IsServer()==0) return;
// this part of the cog will sync the AI and its target 
// (target via second server trigger?)
AI=getparam(0);
setpulse(0.1);
return;

timer:
if(IsServer()==0) return;
// this timer is to send a message to the main cog in order
// to store this cog in a heap.
SendMessage(AI_server, user1);
return;

pulse:
if(IsServer()==0) return;
// sync pos (why did LEC not do this in the engine *yawn*
syncthingpos(AI);
// sync target (this will target the first actor/player the
// ai can see, check if its on teh same team, if not attack
// unfortunatly this means that the AI will allways attack
// the thing with the lowest thing number and the correct
// peramiters, but i cant think how to check everything.
for(i=0; i <= getthingcount(); i=i+1)
{
	if(hasLOS(AI,i))
	{
		if(GetThingType(i)==2 || GetThingType(i)==10)
		{
			if(getthingtype(i)==2) if(GetThingUserData(i)==team)
			{
			if(getthingtype(i)==10) if(GetPlayerTeam(i)==team)
			{
			if(VectorDist(getthingpos(i), getthingpos(AI))<=dist)
			{
			if(team != -1)
			{
			if(getthinguserdata(i) != team)
			{
// the actors target is avalible, so we can set it as the
// target and send the message (team mode)
SendTrigger(-1, 145, AI, i, 0, 0); 
return;
			}
			}
			else if(team == -1)
{
// the actors target is avalible, so we can set it as the
// target and send the message (no team mode)
SendTrigger(-1, 145, AI, i, 0, 0); 
return;
}
			}
			}
			}
		}
	}
}
// if you get to here with not target, theres nothing for the AI to attack
// so turn its AI off.
AISetMode(AI, 0x2000); 
return;
end


AI server code

Code:
# JK cogscript
#
# PJ_AI_server.cog
#
# this is the big stuff, the main AI controle cog,
# as you can see eatch of the decore AI ghost templates cogs
# send the infromation to this cog, by adding userdata to the
# things we can find them easaly, i may also try other ways.
# again runs only on the server.  
#
# 13/jan/2004
# [PJB]

symbols
message		user0
message		user1
message		user2
message		startup
message		killed
message		timer
thing		AI		local
thing		AIT		local
int		ainum=0		local
int		totnum=0	local
cog		AI_cog		local
int		i=0		local
int		inplay=0	local
cog		me		local
end

code
startup:
me=GetSelfCog();
sendtrigger(-1,135,me,0,0,0);
if(IsServer()==0) return;
// set the timer for the heap. as all the AI
// must be registerd first. (ainum)
settimer(1);
// also find the number of things before the
// AI are created.
totnum=getthingcount();
return;

user0:
if(IsServer()==0) return;
// very basic, get the paramiters to make the thing.
ainum=ainum+1;
AI=FireProjectile(getparam(0),getparam(1), -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0); 
setthinguserdata(AI,getparam(3));
capturething(AI);
// send a user1 back to the cog to sync the thing and its target
sendmessageex(getsenderref(),user1,AI,0,0,0);
return;

user1:
if(IsServer()==0) return;
// this is where we add the information we need to the
// heap, in this case we are going to add the cog's of the 
// correct things. then when we are ready we can ask the cog
// to send the information we need, so we dont get to complex
// neat system eh?
heapset(getparam(0), getsenderref());
return;

user2:
if(IsServer()==0) return;
for(i=0; i<=inplay; i=i+1)
{
	if(hasLOS(GetPlayerThing(i),getparam(0)))
	{
	sleep(getparam(2));
	SendMessage(getsenderref(), user0);
	return;
	}
}
AI=FireProjectile(getparam(0),getparam(1), -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0); 
capturething(AI);
return;


killed:
if(IsServer()==0) return;
// the AI was killed, so respawn it at the orginal location
// (may add LOS later)
AIT=getthingparent(getsenderref());
AI_cog=heapget(AIT);
SendMessage(AI_cog, user0);

// this fun bit of code finds the number of players in the game
for(i=0;i <= 32; i=i+1)
{
if(GetPlayerThing(i)==-1) 
	{
	inplay=i-1; 
	return;
	}
Else if(i==32) inplay=32;
}
return;

timer:
if(IsServer()==0) return;
// change this to timer EX for the killsleep
HeapNew(totnum+1, (ainum*3)+totnum); 
return;
end



AI targeting code
Code:
# JK cogscript
#
# PJ_AI_target.cog
#
# this cog will change the target of the AI so its synced
#  
# 13/jan/2004
# [PJB]
		
flags=0x140 
# local cog (i hope)

symbols
message		trigger
thing		AI		local
thing		target		local
end

# ========================================================================================

code
trigger:
// check if its the right trigger
if(getsourceref()!=145)return;

// get AI and target
AI=getparam(0);
target=getparam(1);

// clear disabled mode if AI is disabled
if(AIGetMode(AI)==0x2000) AIClearMode(AI, 0x2000); 

// attack!
AISetFireTarget(AI, target); 
return;
end


i know JK is ment to be haveing a revial, i hope cog is too.

as you can see i have added decriptions of what everythign dose, and good old parsec says its clean, so i dont really know whats wong

------------------
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2004-01-13, 1:27 PM #2
Just a cursory glance (because I'm off to bed and I'm not going to dwell on 3 integrated COG scripts last thing at night [http://forums.massassi.net/html/wink.gif] ) but for the "PJ_AI_target.cog" shouldn't the flag setting be "flags=0x240" rather than 0x140 (or is that a typo, as even the DataMaster doesn't know what flag type 0x100 does)? Or do you know something the DataMaster doesn't [http://forums.massassi.net/html/wink.gif] I know this probably isn't overly signifcant in the grand scheme of things (when compared with the bulk of the actual code) but it's just what leapt out at me after one quick look... [http://forums.massassi.net/html/redface.gif]

Either way, this is something that I need to look over with fresh eyes - I'll do my best to see what I can find, though I make no promises... [http://forums.massassi.net/html/redface.gif] [http://forums.massassi.net/html/smile.gif]

Hope this helps [http://forums.massassi.net/html/biggrin.gif]

-Jackpot

PS: w00t - 300th Post! [http://forums.massassi.net/html/biggrin.gif] [http://forums.massassi.net/html/smile.gif]

------------------
"lucky_jackpot is the smily god..." - gothicX

"Life is mostly froth and bubble,
But two things stand in stone,
Kindness in another's trouble,
Courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||
2004-01-14, 9:42 AM #3
if you check the JKspecs it knows something datamaster dosent.. [http://forums.massassi.net/html/biggrin.gif]
Quote:
<font face="Verdana, Arial" size="2">
LOCAL 0x40 Cog runs on the client and server
SERVER 0x80 Cog runs only on the server, client messages are forwarded to the server
GLOBAL 0x100 Cog runs locally on all machines
NOSYNC 0x200 COG results are not broadcast to the other machines.
</font>


the thing is i was not definate wheather the AI target needed syncing, and either way i wanted to keep everythign as snyced as possible, so i set the flag to 140 (local C/S) but the 240 flag (local unsynced) was not what i wanted (incase i needed to actually create some ghost objects or something for a later (more complex) code)

either way the problem is either in the trigger/message combo of the basic and server cogs, or in the server cog. as the AI is never created at the ghost.

------------------
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2004-01-15, 7:53 AM #4
i cant fail on this... HELP ME!

------------------
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2004-01-15, 1:29 PM #5
Ok, ok, already - personally, I haven't had time to look at the code off-line - what with the hours I work, I check Massassi first thing at work (8:45) and a quick check last thing at night (it's past midnight now and I'm up at 6:00am). If you choose programming as a profession, then you'll know that if you try coding last thing at night/through the night, then you inevitably get strange bugs in your code (especially with ideas that seemed good at the time [http://forums.massassi.net/html/wink.gif] ). Trust me on this - many of my Java/C assignments have the algorithm:

Code:
assignment + deadLine + lateNight + caffeine = finalProgramcode + strangeBugsThatSeemedOKat4InTheMorning;


And given these factors, I still code COG - for fun? Geez, I must be crazy... [http://forums.massassi.net/html/wink.gif] Essentially, people have lives outside of Massassi too [http://forums.massassi.net/html/smile.gif]

But post related - I'd be wary about the "JK Specs" - they're old and outdated and not nearly as accurate and up-to-date as the DataMaster! Period.

If you place "Print()" verbs after every couple of lines, what does their progress report back - where specifically do things start to go "belly up" (just one of a great many technical terms for all aspiring programmers to learn there [http://forums.massassi.net/html/wink.gif])?

One potential problem I believe can be avoided is that in "PJ_AI_server.cog" you have "thing AI local". Given that AI is a reserved "data-type" (if you can call it that) in COG, then you're bound to encounter some glitches [http://forums.massassi.net/html/redface.gif]

Again - that's only another quick observation - try fixing that and post back letting me know the state of play. When you posted a while back about this AI system you were developing, I'll admit I was (and still am) intrigued to see if works [http://forums.massassi.net/html/biggrin.gif]

Hope this has helped [http://forums.massassi.net/html/biggrin.gif]

-Jackpot

------------------
"lucky_jackpot is the smily god..." - gothicX

"Life is mostly froth and bubble,
But two things stand in stone,
Kindness in another's trouble,
Courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||
2004-01-19, 5:29 AM #6
well, this is a different AI system, this is a simple AI sync system, that other one is a _Decore (with collide=3) AI system, that would be less laggie in MP games... this is more of an alternative to the (rather annoying and complex) AI_sync cogs that are in use today.
anyway, ill have a think about what you said and try takeing out the flags and i did orginaly have a debug int in the code, but i... removed it before i started work...

------------------
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?

↑ Up to the top!