Unofficial Cog Specs 1.2
Unofficial Cog Specs 1.2
(Take everything in here with a few grains of salt)

If this helps you in editing and creating Cog patches, I would appreciate it if you would give me
 a little credit.

PATCH NOTE---Cog patches do not work with saved games

1.0:: This file covers most of the Symbols part of a .COG file, and a brief overview of Actors 
      and powerups code.
1.1:: More code info, flags, and a few new bins.  
1.2:: Bin list is completely redone and complete.  Also, more information on different cog types.
      Clarified some of the code better.  New info since version 1.1 is in (())



1. Cog basics
Cog is the programming language used in LucasArt's Jedi Knight game. It is used to determine 
everything, from shield level and ammo, to what happens to any enemy when you hit it with a 
lightsaber.  Information used by the Cog language is stored in Bins.
  JK level gobs contain all of the .COG files used in that level, which are then referenced by 
the game to initiate specific events (INF glorified).  It is very similar to Duke 3D .CON files.
------------------------------------------------------------------------------------------------
1.1 COG Types
Each .COG file is of a certain type: They are:

	00_: ((Level Specific Cogs.  These cogs are placed in the level gob, and the 00 is
 	     replaced with the level number.))
	
	actor_:Controls what happens to an enemy when events occur.   Controls what happens when
 	       		 it dies, is hit by a lightsaber, a Force Skill is used against it.

	class_:Controls different events
	
	Force_:Determines what happens when a Force power is used

	Item_:Bacta tanks, wrenches, etc. Any non-weapon that you can use

	Pow_:Power up: Anything that you pick up and keep: Ammo, weapons, shields.
	
	Weap_:Weapon: the weapons that you use are defined by these.

This document focuses on pow_ and actor_ files
------------------------------------------------------------------------------------------------
1.2 Bins
	As previously stated, bins store information used by the game.  Bin information itself 
(Values) are stored in the .plr file. in the form (bind bin# value flags).  ((There are 116 bins 
preprogrammed, with a maximum of 199.))

The following is a complete bin list:
			Bin #		min     max     flags   Cog used
Weapon Bins:
none                    0               0       0       0x004
fists                   1               0       1       0x024   cog=weap_fists.cog
bryar_pistol            2               0       1       0x0a4   cog=weap_bryar.cog
stormtrooper_rifle      3               0       1       0x0a4   cog=weap_strifle.cog
thermal_detonator       4               0       30      0x0a4   cog=weap_thermdet.cog
tusken_prod             5               0       1       0x0a4   cog=weap_crossbow.cog
repeater                6               0       1       0x0a4   cog=weap_repeater.cog
rail_detonator          7               0       1       0x0a4   cog=weap_raildet.cog
sequencer_charge        8               0       30      0x0a4   cog=weap_seqcharge.cog
concussion_rifle        9               0       1       0x0a4   cog=weap_concrifle.cog
lightsaber              10              0       1       0x0a4   cog=weap_saber.cog


Ammo, etc:

energy                  11              0       500     0x080
power                   12              0       500     0x080
battery                 13              0       200     0x020
forcemana               14              0       400     0x000
railcharges             15              0       30      0x080

Bonuses:

new_stars               16              0       32      0x000
spend_stars             17              0       32      0x000
choice                  18              0       2      0x000

Force (Skill bins store number of stars:Rank is rank #):

jedi_rank                   20              0       8.0     0x000   cog=force_well.cog
force jump                  21              0       4.0     0x108   cog=force_jump.cog
force speed                 22              0       4.0     0x108   cog=force_speed.cog
force seeing                23              0       4.0     0x108   cog=force_seeing.cog
force pull                  24              0       4.0     0x108   cog=force_pull.cog
force healing               25              0       4.0     0x108    cog=force_heal.cog
force persuasion            26              0       4.0     0x108    cog=force_persuasion.cog
force blinding              27              0       4.0     0x108    cog=force_blinding.cog
force absorb                28              0       4.0     0x118    cog=force_absorb.cog
force protection            29              0       4.0     0x118    cog=force_protection.cog
force throw                 30              0       4.0     0x108   cog=force_throw.cog
force grip                  31              0       4.0     0x108    cog=force_grip.cog
force lightning             32              0       4.0     0x108    cog=force_lightning.cog
force destruction           33              0       4.0     0x108    cog=force_destruction.cog
force deadlysight           34              0       4.0     0x108    cog=force_deadlysight.cog


Items:

bactatank               40              0       5       0x102   cog=item_bacta.cog
irgoggles               41              0       1       0x102   cog=item_irgoggles.cog
fieldlight              42              1       1       0x122   cog=item_fieldlight.cog
keyimperial             43              0       1       0x042   cog=item_keyimperial.cog
wrench                  44              0       1       0x042   cog=item_wrench.cog
datadisk                45              0       1       0x042   cog=item_datadisk.cog
keyred                  46              0       1       0x042   cog=item_keyred.cog
keyblue                 47              0       1       0x042   cog=item_keyblue.cog
keyyellow               48              0       1       0x042   cog=item_keyyellow.cog
wrchblue                49              0       1       0x042   cog=item_wrenchblue.cog
wrchyellow              50              0       1       0x042   cog=item_wrenchyellow.cog
keygreen                51              0       1       0x042   cog=item_keygreen.cog

shields                 60              0       200.0   0x030   cog=item_shields.cog
force_armor             61              0       200.0   0x000
supershields            62              0         1.0   0x010   #cog=item_supershields.cog
powerboost              63              1.0       2.0   0x000
s_dark                  64              0         1.0   0x000
s_light                 65              0         1.0   0x000
revive                  66              0         1.0   0x000

Scoring:
maxsecrets              71              0       20      0x000
peds_killed             72              0       1000    0x000
peds_total              73              0       1000    0x000
force_morality          74              -40     40      0x000
alignment               75              -100    100     0x000

Multiplay:
teamcolor               80              0       2       0x040
redflag                 81              0       1       0x048
goldflag                82              0       1       0x048
redkey                  83              0       1       0x042    cog=ctf_itemkeyred.cog
goldkey                 84              0       1       0x042    cog=ctf_itemkeygold.cog

RESERVED BINS:  99 to 115
stringOffset            99              0       99999   0x000

goal00                  100             0       1000    0x040
goal01                  101             0       1000    0x040
goal02                  102             0       1000    0x040
goal03                  103             0       1000    0x040
goal04                  104             0       1000    0x040
goal05                  105             0       1000    0x040
goal06                  106             0       1000    0x040
goal07                  107             0       1000    0x040
goal08                  108             0       1000    0x040
goal09                  109             0       1000    0x040
goal10                  110             0       1000    0x040
goal11                  111             0       1000    0x040
goal12                  112             0       1000    0x040
goal13                  113             0       1000    0x040
goal14                  114             0       1000    0x040
goal15                  115             0       1000    0x040

hotkeyOffset            150             0       99999   0x000

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
2. .COG files

.COG files are called Cog scripts.  Each script has several parts.  This is a look at each.
------------------------------------------------------------------------------------------------
2.1 Layout
The Cog Script layout is simple.  It usually begins with a header like the following:

# Jedi Knight Cog Script
#
# filename.COG
#
# *Type* Script - Brief Description
#
# [Author's Initials]
#
# Copyright
(This is all ignored by the game, because it is preceded by #'s)

It is then followed by the symbols section, then finally, the Code section.
------------------------------------------------------------------------------------------------
2.2 Symbols

Symbols are used for a variety of reasons. Mostly, they are used as a way to skip a lot of 
writing.  They are written in the following form:

symboltype			nameforsymbol			local (Not for all types)

Here is a symbol list and a description of each type.

***************
2.2.1  thing

The thing symbol is used to indicate what the item using the script is, and what can trigger it.
Thing types include Player and powerup. ((Things are more specifically assigned to certain codes 
in the Code section))

***************
2.2.2 int

int(integer) symbols are used to clarify what a word refers to.  This includes bins, ammobins, 
bin_contents, and autopickup.  If there is no =, then the value is determined in the Code. 
Therefore,

int         bin=3                            local
int         ammobin=11                       local

would set the engine to refer to bin 3 every time the word "bin" is mentioned in the code, and to
bin 11 when "ammobin" is used.  

***************
2.2.3 sound

This specifies what sounds are to be played when a message is sent to the game.  So

sound       pickupsnd=thrmlpu2.wav           local
sound       respawnsnd=Activate01.wav        local

would play the sound "thrmlpi2.wav" when the pickupsnd message is sent. 

***************
2.2.4 flex

flex is used when the script causes something to change.  For example:

flex        amount                           local

indicates that the amount of the object affected by this script will change

***************
2.2.5 model
This is the name of the .3DO file used for a weapon.

***************
2.2.6 message

The messages that will trigger the script.  Some include: Touched, taken, damaged, pulse, and 
killed.  Each message has a related section in the code part of the script.

***************
2.2.7 ai

This is used to indicate what, if any, AI should be triggered if something occurs. If it says
ai          flee_ai=noweapon.ai              local

it means that when the flle_ai is triggered, the noweapon ai kicks in.  (This is used when a 
weapon is Force Pulled away from an enemy)

***************
2.2.8 template

The template is the name of a file that appears after an event has happened.  The Stormtrooper 
actor_ script has the following for its templates:

template    powerup=+DSTrifle                local
template    limb=+stormlimb                  local

The words "powerup" and "limb" are referred to in the code of the script.

((***************
2.2.9 model

(Saber code)
model    povModel=sabv.3do             local
model    saberMesh=sabg.3do            local

The povmodel is the thing shown in 1st person view.  The mesh is the object shown in 3rd person view.
))

The symbol section is closed by a single

end
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
2.3 Cog Code
This is where it all comes together.  The commands that make magic, or at least, arms fall off. 
As stated above, each message is usually coded at the bottom
***************
2.3.1 Basics
Cog script is not that complicated (HA! Actually, it really isn't) but once you study it for four
 hours, it all starts to make sense. It reminds me of duke .con files  a bit, and the more you 
look over the different scripts, the more you'll understand.


2.3.2 Actors
					To code the message "Damaged" for an actor:
First, the code is preceded by the word code.Then comes the message title, followed by a :.  So 
to code the message "damaged",  you would have

code

damaged:

This would let the script know what is supposed to happen when the "damaged" message is sent.
Now comes the fun part: Deciding whether or not an arm should fall off.  First, you must check to
see what amount of damage there is.  To do this, use:

	damage == getparam(0);
(some lines are followed by a ; )
Now, you begin if....else statements.  So next you have 
if(GetParam(1) == 16)    
{
Which means "If damage cause  is lightsaber <16> then do what is in {'s.  So now, 
assuming that this statement is true, you must tell it what to do next.  The next thing in the 
code is:

damage = (damage * 2.0);
      victim = GetSenderRef();
      if(GetThingHealth(victim) <= damage)

Which means damage is equal to damage times two (Doubles lightsaber damage) then it sets the word victim to represent the receiver of the attack 
 then it checks to see if the health of the victim is less than or 
equal to the damage   

Now there is a random chance that the limb will be cut off.
{
         if(rand() < 0.05)
{
            AmputateJoint(victim, 5);
            newThing = CreateThingAtPos(limb, GetThingSector(victim), GetThingPos(victim), '0 0 0');
            SetThingVel(newThing, '0.0 0.7 1.4');

Which means that if a random number  is less than 0.05 then the victim's arm is cut off at 
joint 5  then a new thing is created  
which is the limb (as set above with the template symbol)<(limb, > in the victim's sector 
 at the victim's postion <'0 0 0');> then the location from it's 
current position that it moves to   So it drops  1.4 
from where it was on the z plane, and .7 to on the X plane.  Now, you must close up the three 
ifs by using 
	   }
      }
   }

Then close it with:
 ReturnEx(damage);
   Return;
Which returns except damage ; (Returns base damage).

***************
2.3.1 Powerups

Here is the Cog code for the lightsurge taken messge, copied and pasted, with my  
(Note: the // is the comment part directly from the cog)

taken:
   player = GetSourceRef(); 
   powerup = GetSenderRef();

   // Print("Light Surge");
   jkPrintUNIString(player, 65); 
   AddDynamicTint(player, 0.0, 0.0, 0.2);

   // Set mana amount to max.
   SetInv(player, bin, GetInv(player, 20) * 50);
   SetInv(player, 65, 1);
   jkSetSuperFlags(4);

   // Effect lasts 20 seconds, expand if already on.
   KillTimerEx(1);
   SetTimerEx(20, 1, player, 1);
   SetTimerEx(20 - 3 * GetSoundLen(outsnd) - 0.55, 1, player, 0);

   Return;

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------

MORE CODE STUFF

The things in ()'s are variables --- They change....

Here are some of the more basic codes,  Not linked to any word in the code:

jkPrintUNIString(player, #)---Sends message to player that matches number given from 
jkstrings.uni

PlaySoundThing(Soundname, thing, startingsoundvolume, variable, flag,)

ChangeSoundVol(channel, 0.8, 0.75) ---changes sound to .8 volume in .75 seconds


((Return; ---Stops the code: The same as END, only "Return" is used at the end of each message, 
not just the end of the code.))

((ReturnEx; ---Returns the base damage taken by actor))

These are the symbols used in the code:

=  ---used to indicate what a word in the code is linked to (
	IE:player = GetLocalPlayerThing() means that wherever the word "player" is, it is 
	referring to GetLocalPlayerThing()
|| ---used to indicate OR
&& ---used to indicate AND
== ---used to indicate EQUAl TO
!= ---used to indicate NOT EQUAL TO
>  ---used to indicate GREATER THAN
<  ---used to indicate LESS THAN
=> ---used to indicate GREATER THAN OR EQUAL TO
<= ---used to indicate LESS THAN OR EQUAL TO

The following codes are often linked to a certain word.

getparam(0) ---Gets base damage

getparam(1) ---Gets weapon type  

((type == # ---this is very similar to getparam(1), but it checks to see what the type of damage
	       was.))
((Types (used in "type ==" and get param(1) ) --- 2=Energy
						  4=Fire
						  16=Lightsaber

SetInvActivated(player, bin, value) ---Sets player bin to value (0 for off, 1 for on in force 
powers)

GetLocalPlayerThing() ---The player, often set to the word player by using the =.

IsInvActivated(player, 21)--Checks to see if player bin 21 is in use

GetInv(thing, bin) ---returns the Bin value for the specified thing.  (This is used in weapons 
to see if there is ammo)

ActivateBin(thing, bin, value) ---Activates the 0 bin using the value (usually another bin number)

GetThingHealth(thing) ---Returns the Health of the specified thing

GetSenderRef() ---returns the "Sender" of message (IE: powerup, enemy, Player)

GetSourceRef() ---Returns the receiver of message

GetThingSector(thing) ---Will return the sector of thing

AttachThingToThingEx(thingtoattach, thingtoattachto, flag) ---Attaches something to something 
else, so it stays with that thing (Force Armor to Player)

CreateThingAtPos(thing, sector,  postition in sector, postition away from center of thing 
(usually '0 0 0') ---creates a new thing at said position, then moves it to it's new position.

GetThingPos(thing) ---returns position of thing in ()'s

SetThingFlags(thing, flags) ---sets the flags of a thing to the specified flag

GetActorFlags(thing) ---Returns the Actor Flags for thing.  (For player: IR Goggles on and off, 
Field light on and off, etc.)

ClearActorFlags(thing, flag) ---removes the specified flag for the thing.

ChangeInv(thing, bin#, valuechangedby) ---Changes thing's bin value by the valuechangedby 
(-1 subtracts 1 from value, etc.)

SetPulse(seconds) ---sets number of seconds between each "PULSE" message.  

((AddDynamicTint(x.x, x.x, x.x) ---Flashes the screen the color determined by the 
RGB values (x.x) ))

((GetAttachFlags(thing) ---Gets the Attachment flags for thing.))

((GetPhysicsFlags ---Gets physics flags for sector (Gravity, movement)

((SetInv(Thing, bin, new value) ---sets the specified bin to the new value.))

((print("Watch out"); ---Will print "Watch out"))

Flags:
These flags are used in bins and in code:
Misc Flags:
	0x1000 ---makes object go boom when touched 
Sound Flags:
	0x80 ---Sound is activation Sound
	0x81 ---Sound loops for duration
Force Flags:
	0x800 ---Blinded




Joints:
0 = head
1 = neck
2 = torso
3 = primary weapon fire
4 = secondard weapon fire
5 = primary weapon aiming joint
6 = secondary weapon aiming joint
	
Brian Taylor
November 1st, 1997
Disclaimer: This document is notendorsed by LucasArts (duh) and I am not responsible for anything
 you do to your game after reading this.  .COG excerpts (C) LucasArts.

Thanks to the  people who have helped with these specs.