From baff3de5af52078a9b763a849637a1510a8babc3 Mon Sep 17 00:00:00 2001 From: Spoike Date: Thu, 16 Oct 2008 22:00:54 +0000 Subject: [PATCH] Initial commit. Needs work. Mostly functional though. Requires a cutting edge version of fteqcc... Older versions have bugs and stuff. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3045 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- quakec/csqctest/src/common/classes.qc | 45 + quakec/csqctest/src/common/combuiltins.qc | 77 + quakec/csqctest/src/common/econstants.qc | 86 + quakec/csqctest/src/common/extensions.qc | 157 ++ quakec/csqctest/src/common/mconstants.qc | 49 + quakec/csqctest/src/common/phys.qc | 334 ++++ quakec/csqctest/src/common/playerphysics.qc | 27 + quakec/csqctest/src/common/pmove.qc | 76 + quakec/csqctest/src/common/sv_user.qc | 42 + quakec/csqctest/src/cs/animation.qc | 1350 ++++++++++++++++ quakec/csqctest/src/cs/constants.qc | 107 ++ quakec/csqctest/src/cs/csbuiltins.qc | 77 + quakec/csqctest/src/cs/defs.qc | 20 + quakec/csqctest/src/cs/entrypoints.qc | 302 ++++ quakec/csqctest/src/cs/fun/osgk.qc | 40 + quakec/csqctest/src/cs/fun/skinchooser.qc | 178 ++ quakec/csqctest/src/cs/fun/tetris.qc | 671 ++++++++ quakec/csqctest/src/cs/hud.qc | 347 ++++ quakec/csqctest/src/cs/keys.qc | 114 ++ quakec/csqctest/src/cs/map.qc | 126 ++ quakec/csqctest/src/cs/menu.qc | 57 + quakec/csqctest/src/cs/movetypes.qc | 160 ++ quakec/csqctest/src/cs/player.qc | 502 ++++++ quakec/csqctest/src/cs/system.qc | 188 +++ quakec/csqctest/src/cs/test.qc | 16 + quakec/csqctest/src/cs/weapons.qc | 330 ++++ quakec/csqctest/src/csprogs.src | 40 + quakec/csqctest/src/fteext.qc | 104 ++ quakec/csqctest/src/miscext.qc | 253 +++ quakec/csqctest/src/optsall.qc | 2 + quakec/csqctest/src/optscsqc.qc | 1 + quakec/csqctest/src/optsmenu.qc | 1 + quakec/csqctest/src/optsssqc.qc | 1 + quakec/csqctest/src/ss/ai.qc | 750 +++++++++ quakec/csqctest/src/ss/boss.qc | 385 +++++ quakec/csqctest/src/ss/builtins.qc | 43 + quakec/csqctest/src/ss/buttons.qc | 139 ++ quakec/csqctest/src/ss/client.qc | 1606 +++++++++++++++++++ quakec/csqctest/src/ss/combat.qc | 285 ++++ quakec/csqctest/src/ss/defs.qc | 507 ++++++ quakec/csqctest/src/ss/demon.qc | 357 +++++ quakec/csqctest/src/ss/dog.qc | 358 +++++ quakec/csqctest/src/ss/doors.qc | 778 +++++++++ quakec/csqctest/src/ss/enforcer.qc | 345 ++++ quakec/csqctest/src/ss/fight.qc | 407 +++++ quakec/csqctest/src/ss/fish.qc | 186 +++ quakec/csqctest/src/ss/flag.qc | 8 + quakec/csqctest/src/ss/hknight.qc | 436 +++++ quakec/csqctest/src/ss/items.qc | 1370 ++++++++++++++++ quakec/csqctest/src/ss/knight.qc | 266 +++ quakec/csqctest/src/ss/misc.qc | 671 ++++++++ quakec/csqctest/src/ss/monsters.qc | 232 +++ quakec/csqctest/src/ss/ogre.qc | 460 ++++++ quakec/csqctest/src/ss/oldone.qc | 283 ++++ quakec/csqctest/src/ss/plats.qc | 361 +++++ quakec/csqctest/src/ss/player.qc | 700 ++++++++ quakec/csqctest/src/ss/shalrath.qc | 240 +++ quakec/csqctest/src/ss/shambler.qc | 363 +++++ quakec/csqctest/src/ss/soldier.qc | 322 ++++ quakec/csqctest/src/ss/subs.qc | 316 ++++ quakec/csqctest/src/ss/tarbaby.qc | 222 +++ quakec/csqctest/src/ss/triggers.qc | 688 ++++++++ quakec/csqctest/src/ss/weapons.qc | 1348 ++++++++++++++++ quakec/csqctest/src/ss/wizard.qc | 407 +++++ quakec/csqctest/src/ss/world.qc | 392 +++++ quakec/csqctest/src/ss/zombie.qc | 511 ++++++ quakec/csqctest/src/ssqc.src | 51 + 67 files changed, 21673 insertions(+) create mode 100644 quakec/csqctest/src/common/classes.qc create mode 100644 quakec/csqctest/src/common/combuiltins.qc create mode 100644 quakec/csqctest/src/common/econstants.qc create mode 100644 quakec/csqctest/src/common/extensions.qc create mode 100644 quakec/csqctest/src/common/mconstants.qc create mode 100644 quakec/csqctest/src/common/phys.qc create mode 100644 quakec/csqctest/src/common/playerphysics.qc create mode 100644 quakec/csqctest/src/common/pmove.qc create mode 100644 quakec/csqctest/src/common/sv_user.qc create mode 100644 quakec/csqctest/src/cs/animation.qc create mode 100644 quakec/csqctest/src/cs/constants.qc create mode 100644 quakec/csqctest/src/cs/csbuiltins.qc create mode 100644 quakec/csqctest/src/cs/defs.qc create mode 100644 quakec/csqctest/src/cs/entrypoints.qc create mode 100644 quakec/csqctest/src/cs/fun/osgk.qc create mode 100644 quakec/csqctest/src/cs/fun/skinchooser.qc create mode 100644 quakec/csqctest/src/cs/fun/tetris.qc create mode 100644 quakec/csqctest/src/cs/hud.qc create mode 100644 quakec/csqctest/src/cs/keys.qc create mode 100644 quakec/csqctest/src/cs/map.qc create mode 100644 quakec/csqctest/src/cs/menu.qc create mode 100644 quakec/csqctest/src/cs/movetypes.qc create mode 100644 quakec/csqctest/src/cs/player.qc create mode 100644 quakec/csqctest/src/cs/system.qc create mode 100644 quakec/csqctest/src/cs/test.qc create mode 100644 quakec/csqctest/src/cs/weapons.qc create mode 100644 quakec/csqctest/src/csprogs.src create mode 100644 quakec/csqctest/src/fteext.qc create mode 100644 quakec/csqctest/src/miscext.qc create mode 100644 quakec/csqctest/src/optsall.qc create mode 100644 quakec/csqctest/src/optscsqc.qc create mode 100644 quakec/csqctest/src/optsmenu.qc create mode 100644 quakec/csqctest/src/optsssqc.qc create mode 100644 quakec/csqctest/src/ss/ai.qc create mode 100644 quakec/csqctest/src/ss/boss.qc create mode 100644 quakec/csqctest/src/ss/builtins.qc create mode 100644 quakec/csqctest/src/ss/buttons.qc create mode 100644 quakec/csqctest/src/ss/client.qc create mode 100644 quakec/csqctest/src/ss/combat.qc create mode 100644 quakec/csqctest/src/ss/defs.qc create mode 100644 quakec/csqctest/src/ss/demon.qc create mode 100644 quakec/csqctest/src/ss/dog.qc create mode 100644 quakec/csqctest/src/ss/doors.qc create mode 100644 quakec/csqctest/src/ss/enforcer.qc create mode 100644 quakec/csqctest/src/ss/fight.qc create mode 100644 quakec/csqctest/src/ss/fish.qc create mode 100644 quakec/csqctest/src/ss/flag.qc create mode 100644 quakec/csqctest/src/ss/hknight.qc create mode 100644 quakec/csqctest/src/ss/items.qc create mode 100644 quakec/csqctest/src/ss/knight.qc create mode 100644 quakec/csqctest/src/ss/misc.qc create mode 100644 quakec/csqctest/src/ss/monsters.qc create mode 100644 quakec/csqctest/src/ss/ogre.qc create mode 100644 quakec/csqctest/src/ss/oldone.qc create mode 100644 quakec/csqctest/src/ss/plats.qc create mode 100644 quakec/csqctest/src/ss/player.qc create mode 100644 quakec/csqctest/src/ss/shalrath.qc create mode 100644 quakec/csqctest/src/ss/shambler.qc create mode 100644 quakec/csqctest/src/ss/soldier.qc create mode 100644 quakec/csqctest/src/ss/subs.qc create mode 100644 quakec/csqctest/src/ss/tarbaby.qc create mode 100644 quakec/csqctest/src/ss/triggers.qc create mode 100644 quakec/csqctest/src/ss/weapons.qc create mode 100644 quakec/csqctest/src/ss/wizard.qc create mode 100644 quakec/csqctest/src/ss/world.qc create mode 100644 quakec/csqctest/src/ss/zombie.qc create mode 100644 quakec/csqctest/src/ssqc.src diff --git a/quakec/csqctest/src/common/classes.qc b/quakec/csqctest/src/common/classes.qc new file mode 100644 index 000000000..f4f87ad8d --- /dev/null +++ b/quakec/csqctest/src/common/classes.qc @@ -0,0 +1,45 @@ +#ifndef _CLASSES_QC_ + #define _CLASSES_QC_ + + +#define eclasses eclass(CLASS_ROCKET, ParseRocketClass) eclass(CLASS_GIB, ParseGibbing) eclass(CLASS_PLAYER, ParsePlayer) eclass(CLASS_EXPLOSION, ParseExplosion) eclass(CLASS_DEADBODY, ParseBody) eclass(CLASS_NAIL, ParseNailClass) + + +#define eclass(eid,func) void(float isnew) func; + eclasses +#undef eclass + + + enum { +#define eclass(eid,func) eid, + eclasses CLASS_MAX +#undef eclass + }; + + enum { + GIB_BAD, + GIB_PLAYER, + GIB_SOLDIER, + GIB_ZOMBIE, + GIB_DEMON, + GIB_OGRE, + GIB_DOG, + GIB_WIZARD, + GIB_SHAMBLER, + GIB_KNIGHT, + GIB_HELLKNIGHT, + GIB_FISH, + GIB_ENFORCER, + GIB_SHALRATH, + GIB_MAX + }; +#else + #ifdef CSQC + var void(float isnew) ParseEntityClass[ ] = { +#define eclass(eid,func) func , + eclasses +#undef eclass +__NULL__ + }; + #endif +#endif diff --git a/quakec/csqctest/src/common/combuiltins.qc b/quakec/csqctest/src/common/combuiltins.qc new file mode 100644 index 000000000..f5a9c29f7 --- /dev/null +++ b/quakec/csqctest/src/common/combuiltins.qc @@ -0,0 +1,77 @@ +//common builtins. + +void(vector ang) makevectors = #1; // sets v_forward, etc globals +void(entity e, vector o) setorigin = #2; +void(entity e, string m) setmodel = #3; // set movetype and solid first +void(entity e, vector min, vector max) setsize = #4; + +void() break = #6; +float() random = #7; // returns 0 - 1 +void(entity e, float chan, string samp, float vol, float atten) sound = #8; +vector(vector v) normalize = #9; +void(string e) error = #10; +void(string e) objerror = #11; +float(vector v) vlen = #12; +float(vector v) vectoyaw = #13; +entity() spawn = #14; +void(entity e) remove = #15; + +// sets trace_* globals +// nomonsters can be: +// An entity will also be ignored for testing if forent == test, +// forent->owner == test, or test->owner == forent +// a forent of world is ignored +void(vector v1, vector v2, float nomonsters, entity forent) traceline = #16; + + +entity(entity start, .string fld, string match) find = #18; +string(string s) precache_sound = #19; +string(string s) precache_model = #20; +void(entity client, string s)stuffcmd = #21; +entity(vector org, float rad) findradius = #22; + +void(string s, ...) dprint = #25; +string(float f) ftos = #26; +string(vector v) vtos = #27; +void() coredump = #28; // prints all edicts +void() traceon = #29; // turns statment trace on +void() traceoff = #30; +void(entity e) eprint = #31; // prints an entire edict + +float() droptofloor= #34; // TRUE if landed on floor + +float(float v) rint = #36; // round to nearest int +float(float v) floor = #37; // largest integer <= v +float(float v) ceil = #38; // smallest integer >= v + +float(vector v) pointcontents = #41; // returns a CONTENT_* + +float(float f) fabs = #43; + +float(string s) cvar = #45; // return cvar.value +void(string s, ...) localcmd = #46; // put string into local que +entity(entity e) nextent = #47; // for looping through all ents +void(vector o, vector d, float color, float count) particle = #48;// start a particle effect +void() ChangeYaw = #49; // turn towards self.ideal_yaw + // at self.yaw_speed + +vector(vector v) vectoangles = #51; + + + + +void(string var, string val) cvar_set = #72; // sets cvar.value + + + +string(float modelindex) name_for_modelindex = #334; +float(string modelname) modelindex_for_name = #20; + +string(string s) precache_file = #68; // no effect except for -copy +string(string s) precache_model2 = #75; // registered version only +string(string s) precache_sound2 = #76; // registered version only +string(string s) precache_file2 = #77; // registered version only + + + + diff --git a/quakec/csqctest/src/common/econstants.qc b/quakec/csqctest/src/common/econstants.qc new file mode 100644 index 000000000..ae2951c91 --- /dev/null +++ b/quakec/csqctest/src/common/econstants.qc @@ -0,0 +1,86 @@ +float FALSE = 0; +float TRUE = 1; +float false = FALSE; +float true = TRUE; + +// edict.flags +float FL_FLY = 1; +float FL_SWIM = 2; +float FL_CLIENT = 8; // set for all client edicts +float FL_INWATER = 16; // for enter / leave water splash +float FL_MONSTER = 32; +float FL_GODMODE = 64; // player cheat +float FL_NOTARGET = 128; // player cheat +float FL_ITEM = 256; // extra wide size for bonus items +float FL_ONGROUND = 512; // standing on something +float FL_PARTIALGROUND = 1024; // not all corners are valid +float FL_WATERJUMP = 2048; // player jumping out of water +float FL_JUMPRELEASED = 4096; // for jump debouncing + +// edict.solid values +float SOLID_TRIGGER = 1; // touch on edge, but not blocking +float SOLID_BBOX = 2; // touch on edge, block +float SOLID_SLIDEBOX = 3; // touch on edge, but not an onground +float SOLID_BSP = 4; // bsp clip, touch on edge, block + +// edict.movetype values +float MOVETYPE_NONE = 0; // never moves +//float MOVETYPE_ANGLENOCLIP = 1; +//float MOVETYPE_ANGLECLIP = 2; +float MOVETYPE_WALK = 3; // players only +float MOVETYPE_STEP = 4; // discrete, not real time unless fall +float MOVETYPE_FLY = 5; +float MOVETYPE_TOSS = 6; // gravity +float MOVETYPE_PUSH = 7; // no clip to world, push and crush +float MOVETYPE_NOCLIP = 8; +float MOVETYPE_FLYMISSILE = 9; // fly with extra size against monsters +float MOVETYPE_BOUNCE = 10; +float MOVETYPE_BOUNCEMISSILE = 11; // bounce with extra size + +float SOLID_NOT=0; + +vector VEC_ORIGIN = '0 0 0'; +vector VEC_HULL_MIN = '-16 -16 -24'; +vector VEC_HULL_MAX = '16 16 32'; + +vector VEC_HULL2_MIN = '-32 -32 -24'; +vector VEC_HULL2_MAX = '32 32 64'; + +// items +float IT_AXE = 4096; +float IT_SHOTGUN = 1; +float IT_SUPER_SHOTGUN = 2; +float IT_NAILGUN = 4; +float IT_SUPER_NAILGUN = 8; +float IT_GRENADE_LAUNCHER = 16; +float IT_ROCKET_LAUNCHER = 32; +float IT_LIGHTNING = 64; +float IT_EXTRA_WEAPON = 128; + +float IT_SHELLS = 256; +float IT_NAILS = 512; +float IT_ROCKETS = 1024; +float IT_CELLS = 2048; + +float IT_ARMOR1 = 8192; +float IT_ARMOR2 = 16384; +float IT_ARMOR3 = 32768; +float IT_SUPERHEALTH = 65536; + +float IT_KEY1 = 131072; +float IT_KEY2 = 262144; + +float IT_INVISIBILITY = 524288; +float IT_INVULNERABILITY = 1048576; +float IT_SUIT = 2097152; +float IT_QUAD = 4194304; + +float IT2_24 = 1; +float IT2_25 = 2; +float IT2_26 = 4; +float IT2_27 = 8; +float IT2_28 = 16; +float IT2_RUNE1 = 32; +float IT2_RUNE2 = 64; +float IT2_RUNE3 = 128; +float IT2_RUNE4 = 256; diff --git a/quakec/csqctest/src/common/extensions.qc b/quakec/csqctest/src/common/extensions.qc new file mode 100644 index 000000000..dbb37bc9e --- /dev/null +++ b/quakec/csqctest/src/common/extensions.qc @@ -0,0 +1,157 @@ +#ifdef SSQC //this is core for csqc +float(string s) checkextension = #99; +#endif + +//DP_QC_TRACEBOX +void(vector v1, vector min, vector max, vector v2, float nomonsters, entity forent) tracebox = #90; + +//DP_QC_REGISTERCVAR +void(string name, string value) registercvar = #93; + +//DP_QC_FINDFLOAT +entity(entity start, .float fld, float match) findfloat = #98; +entity(entity start, .entity fld, entity match) findentity = #98; + +//FRIK_FILE (file subset) +float FILE_READ = 0; +float FILE_WRITE = 1; +float FILE_APPEND = 2; +float(string filename, float mode) fopen = #110; +void(float fhandle) fclose = #111; +string(float fhandle) fgets = #112; +void(float fhandle, string s) fputs = #113; + +//FRIK_FILE (strings subset) +float(string s) strlen = #114; +string(...) strcat = #115; +string(string s, float start, float length) substring = #116; +vector(string s) stov = #117; +string(string s) strzone = #118; +void(string s) strunzone = #119; +//QW_ENGINE FRIK_FILE +#ifndef QUAKEWORLD +float(string s) stof = #81; +#endif + + +//KRIMZON_SV_PARSECLIENTCOMMAND (excluding clientcommand which is inherantly sv only) +float(string s) tokenize = #441; +string(float argnum) argv = #442; + +//DP_QC_SINCOSSQRTPOW +//idea: id Software, LordHavoc +//darkplaces implementation: id Software, LordHavoc +//builtin definitions: +float(float val) sin = #60; +float(float val) cos = #61; +float(float val) sqrt = #62; +float(float a, float b) pow = #97; +//description: +//useful math functions, sine of val, cosine of val, square root of val, and raise a to power b, respectively. + +//FTE_STRINGS +float(string str, string match) strstrofs = #221; +float(string str, float ofs) str2chr = #222; +string(float c, ...) chr2str = #223; +string(float ccase, float redalpha, float redchars, string str) strconv = #224; +string(string info, string key, string value) infoadd = #226; +string(string info, string key) infoget = #227; +float(string s1, string s2, float len) strncmp = #228; +float(string s1, string s2) strcasecmp = #229; +float(string s1, string s2, float len) strncasecmp = #230; + +//DP_QC_FS_SEARCH +//idea: Black +//darkplaces implementation: Black +//builtin definitions: +float(string pattern, float caseinsensitive, float quiet) search_begin = #444; +void(float handle) search_end = #445; +float(float handle) search_getsize = #446; +string(float handle, float num) search_getfilename = #447; +//description: +//search_begin performs a filename search with the specified pattern (for example "maps/*.bsp") and stores the results in a search slot (minimum of 128 supported by any engine with this extension), the other functions take this returned search slot number, be sure to search_free when done (they are also freed on progs reload). +//search_end frees a search slot (also done at progs reload). +//search_getsize returns how many filenames were found. +//search_getfilename returns a filename from the search. + +//DP_QC_CVAR_STRING +//idea: Paul Timofeyev +//DarkPlaces implementation: Paul Timofeyev, LordHavoc +//builtin definitions: +string(string s) cvar_string = #448; +//description: +//returns the value of a cvar, as a tempstring. + + + +//This file contains optional client-specific extensions which may not exist in all CSQC implementations. + +//UNNAMED_FTE_CS_SKINS_AND_SHADERS +#ifdef CSQC +float(float modelindex, string skinname) skinforname = #237; +float(string skinname) shaderforname = #238; +#endif + +//UNNAMED_FTE_CS_TAG_SUPPORT +#ifdef CSQC +vector(entity ent, float tagnum) RotateVectorsByTag = #234; +void(vector angle) RotateVectorsByAngle = #235; +void(vector fwd, vector right, vector up) RotateVectorsByVectors = #236; +#endif + +//DP_MD3_TAGSINFO +float(entity ent, string tagname) gettagindex = #451; +vector(entity ent, float tagindex) gettaginfo = #452; + + + +//DP_GECKO_SUPPORT +#if defined(CSQC) || defined(MENU) +//idea: Res2k, BlackHC +//darkplaces implementation: Res2k, BlackHC +//FTE implementation: Spike (curtesy of liboffscreengecko) +//constant definitions: +float GECKO_BUTTON_DOWN = 0; +float GECKO_BUTTON_UP = 1; +// either use down and up or just press but not all of them! +float GECKO_BUTTON_PRESS = 2; +// use this for mouse events if needed? +float GECKO_BUTTON_DOUBLECLICK = 3; +//builtin definitions: +float(string name) gecko_create( string name ) = #487; +void(string name) gecko_destroy( string name ) = #488; +void(string name) gecko_navigate( string name, string URI ) = #489; +float(string name) gecko_keyevent( string name, float key, float eventtype ) = #490; +void gecko_mousemove( string name, float x, float y ) = #491; +void gecko_resize( string name, float w, float h ) = #492; +vector gecko_get_texture_extent( string name ) = #493; +//engine-called QC prototypes: +//string(string name, string query) Qecko_Query; +//description: +//provides an interface to the offscreengecko library and allows for internet browsing in games +#else +#warning no gecko +#endif + + +#ifdef SSQC +.float dimension_seen; +.float dimension_see; +float dimension_send; +#endif + +//DP_TE_STANDARDEFFECTBUILTINS) +void(vector org) te_gunshot = #418; +void(vector org) te_spike = #419; +void(vector org) te_superspike = #420; +void(vector org) te_explosion = #421; +void(vector org) te_tarexplosion = #420; +void(vector org) te_wizspike = #423; +void(vector org) te_knightspike = #424; +void(vector org) te_lavasplash = #425; +void(vector org) te_teleport = #426; +void(vector org, float colorstart, float colorlength) te_explosion2 = #427; +void(entity own, vector start, vector end) te_lightning1 = #428; +void(entity own, vector start, vector end) te_lightning2 = #429; +void(entity own, vector start, vector end) te_lightning3 = #430; +void(entity own, vector start, vector end) te_beam = #431; \ No newline at end of file diff --git a/quakec/csqctest/src/common/mconstants.qc b/quakec/csqctest/src/common/mconstants.qc new file mode 100644 index 000000000..cf25018cc --- /dev/null +++ b/quakec/csqctest/src/common/mconstants.qc @@ -0,0 +1,49 @@ +OBIT_DIED +OBIT_FELL +OBIT_LAVA_BIG +OBIT_LAVA_SMALL1 +OBIT_LAVA_SMALL2 +OBIT_SLIME1 +OBIT_SLIME2 +OBIT_DROWN1 +OBIT_DROWN2 +OBIT_TRIEDTOLEAVE +OBIT_FIREBALL +OBIT_SPIKED +OBIT_SQUISHED +OBIT_BLEWUP +OBIT_MONST_ZOMBIE +OBIT_MONST_SCRAG +OBIT_MONST_TARBABY +OBIT_MONST_SHAMBLER +OBIT_MONST_SHALRATH +OBIT_MONST_OLDONE +OBIT_MONST_OGRE +OBIT_MONST_KNIGHT +OBIT_MONST_HELLKNIGHT +OBIT_MONST_FISH +OBIT_MONST_ENFORCER +OBIT_MONST_DRAGON +OBIT_MONST_DOG +OBIT_MONST_FIEND +OBIT_MONST_ARMY +OBIT_WEAP_DISCHARGE +OBIT_WEAP_SHAFT +OBIT_WEAP_ROCKETGIB +OBIT_WEAP_ROCKETRIDE +OBIT_WEAP_GRENADEGIB +OBIT_WEAP_GRENADEEAT +OBIT_WEAP_PUNCTURED +OBIT_WEAP_NAILED +OBIT_WEAP_BUCKSHOT +OBIT_WEAP_BOOMSTICK +OBIT_WEAP_AXE +OBIT_TEAMKILL1 +OBIT_TEAMKILL2 +OBIT_TEAMKILL3 +OBIT_TEAMKILL4 +OBIT_SELF_BORED +OBIT_SELF_REPIN +OBIT_SELF_DISCHARGE +OBIT_TELEFRAG +OBIT_TELEFRAG_REFLECT \ No newline at end of file diff --git a/quakec/csqctest/src/common/phys.qc b/quakec/csqctest/src/common/phys.qc new file mode 100644 index 000000000..30dec0b81 --- /dev/null +++ b/quakec/csqctest/src/common/phys.qc @@ -0,0 +1,334 @@ +//note that this file uses various engine pastes and is thus subject to the terms of the GNU GPL. +//use with caution + +float lastclientthink, sv_maxspeed, sv_friction, sv_accelerate, sv_stopspeed; +float sv_edgefriction, cl_rollangle, cl_divspeed; + +vector phys_origin; //in/out +float phys_movetype; //in +float phys_health; //in +float phys_fixangle; //in +float phys_onground; //in/out +float phys_waterjump; //in/out +vector phys_angles; //out +vector phys_v_angles; //in +vector phys_velocity; //in/out +vector phys_movement; //in +vector phys_punchangle; //in/out +float phys_gravity; //in (should be sv_gravity * self.gravity) + +#define bound(min,val,max) if (val < min) val = min; else if (val > max) val = max + +#define sv_stepheight 22 + +var void() thinkfunc; + +float(entity ent, float ftime) SV_FlyMove = +{ +} + +void() WalkMove = +{ + float clip, oldonground, originalmove_clip, originalmove_flags, originalmove_groundentity; + vector upmove, downmove, start_origin, start_velocity, stepnormal, originalmove_origin, originalmove_velocity; + +// SV_CheckVelocity(ent); + + // do a regular slide move unless it looks like you ran into a step + oldonground = phys_onground; + phys_onground = false; + + start_origin = phys_origin; + start_velocity = phys_velocity; + + clip = SV_FlyMove (ent, sv.frametime, NULL); + + SV_SetOnGround (ent); + SV_CheckVelocity(ent); + + VectorCopy(phys_origin, originalmove_origin); + VectorCopy(phys_velocity, originalmove_velocity); + originalmove_clip = clip; + originalmove_flags = (int)ent->fields.server->flags; + originalmove_groundentity = phys_groundentity; + + if (phys_waterjump) + return; + +// if (sv_nostep.integer) +// return; + + // if move didn't block on a step, return + if (clip & 2) + { + // if move was not trying to move into the step, return + if (fabs(start_velocity[0]) < 0.03125 && fabs(start_velocity[1]) < 0.03125) + return; + + if (phys_movetype != MOVETYPE_FLY) + { + // return if gibbed by a trigger + if (phys_movetype != MOVETYPE_WALK) + return; + + // only step up while jumping if that is enabled +// if (!(sv_jumpstep.integer && sv_gameplayfix_stepwhilejumping.integer)) + if (!oldonground && phys_waterlevel == 0) + return; + } + + // try moving up and forward to go up a step + // back to start pos + VectorCopy (start_origin, phys_origin); + VectorCopy (start_velocity, phys_velocity); + + // move up + VectorClear (upmove); + upmove[2] = sv_stepheight; + // FIXME: don't link? + SV_PushEntity(ent, upmove); + + // move forward + phys_velocity[2] = 0; + clip = SV_FlyMove (ent, sv.frametime, stepnormal); + phys_velocity[2] += start_velocity[2]; + +// SV_CheckVelocity(ent); + + // check for stuckness, possibly due to the limited precision of floats + // in the clipping hulls + if (clip + && fabs(originalmove_origin[1] - phys_origin[1]) < 0.03125 + && fabs(originalmove_origin[0] - phys_origin[0]) < 0.03125) + { + //Con_Printf("wall\n"); + // stepping up didn't make any progress, revert to original move + VectorCopy(originalmove_origin, phys_origin); + VectorCopy(originalmove_velocity, phys_velocity); + //clip = originalmove_clip; + phys_flags = originalmove_flags; + phys_groundentity = originalmove_groundentity; + // now try to unstick if needed + //clip = SV_TryUnstick (ent, oldvel); + return; + } + + //Con_Printf("step - "); + + // extra friction based on view angle + if (clip & 2 && sv_wallfriction.integer) + SV_WallFriction (ent, stepnormal); + } + // skip out if stepdown is enabled, moving downward, not in water, and the move started onground and ended offground +// else if (!(sv_gameplayfix_stepdown.integer && phys_waterlevel < 2 && start_velocity[2] < (1.0 / 32.0) && oldonground && !((int)ent->fields.server->flags & FL_ONGROUND))) +// return; +/* + // move down + VectorClear (downmove); + downmove[2] = -sv_stepheight + start_velocity[2]*sv.frametime; + // FIXME: don't link? + downtrace = SV_PushEntity (ent, downmove); + + if (downtrace.fraction < 1 && downtrace.plane.normal[2] > 0.7) + { + // LordHavoc: disabled this check so you can walk on monsters/players + //if (phys_solid == SOLID_BSP) + { + //Con_Printf("onground\n"); + phys_onground = true; + phys_groundentity = PRVM_EDICT_TO_PROG(downtrace.ent); + } + } + else + { + //Con_Printf("slope\n"); + // if the push down didn't end up on good ground, use the move without + // the step up. This happens near wall / slope combinations, and can + // cause the player to hop up higher on a slope too steep to climb + VectorCopy(originalmove_origin, ent->fields.server->origin); + VectorCopy(originalmove_velocity, ent->fields.server->velocity); + //clip = originalmove_clip; + ent->fields.server->flags = originalmove_flags; + ent->fields.server->groundentity = originalmove_groundentity; + } + + SV_SetOnGround (ent); + SV_CheckVelocity(ent); +*/ +}; + +// LordHavoc: +// Highly optimized port of SV_ClientThink from engine code to QuakeC. + +// note that the engine will call this function if it finds it, +// so modify for your own mods and enjoy... + +void() RunPlayerPhysics = +{ + local vector wishvel, wishdir, v; + local float wishspeed, f; + + if (phys_movetype == MOVETYPE_NONE) + return; + + if (phys_punchangle != '0 0 0') + { + f = vlen(phys_punchangle) - 10 * frametime; + if (f > 0) + phys_punchangle = normalize(phys_punchangle) * f; + else + phys_punchangle = '0 0 0'; + } + + // if dead, behave differently + if (phys_health <= 0) + return; + + // show 1/3 the pitch angle and all the roll angle + phys_angles_z = bound(-1, phys_velocity * v_right * cl_divspeed, 1) * cl_rollangle; + if (!phys_fixangle) + { + phys_angles_x = (phys_v_angle_x + phys_punchangle_x) * -0.333; + phys_angles_y = phys_v_angle_y + phys_punchangle_y; + } + + if (phys_waterjump) + { + phys_velocity_x = phys_movedir_x; + phys_velocity_y = phys_movedir_y; + if (time > phys_teleport_time || phys_waterlevel == 0) + { + phys_waterjump = false; + phys_teleport_time = 0; + } + return; + } + + makevectors(phys_v_angle); + + // swim + if (phys_waterlevel >= 2) + if (phys_movetype != MOVETYPE_NOCLIP) + { + phys_onground = false; + + if (phys_movement == '0 0 0') + wishvel = '0 0 -60'; // drift towards bottom + else + wishvel = v_forward * phys_movement_x + v_right * phys_movement_y + '0 0 1' * phys_movement_z; + + wishspeed = vlen (wishvel); + if (wishspeed > sv_maxspeed) + wishspeed = sv_maxspeed; + + wishspeed = wishspeed * 0.7; + + // water friction + if (phys_velocity != '0 0 0') + { + f = vlen(phys_velocity) * (1 - frametime * sv_friction); + if (f > 0) + phys_velocity = normalize(phys_velocity) * f; + else + phys_velocity = '0 0 0'; + } + else + f = 0; + + // water acceleration + if (wishspeed <= f) + return; + + f = min(wishspeed - f, sv_accelerate * wishspeed * frametime); + phys_velocity = phys_velocity + normalize(wishvel) * f; + return; + } + + // hack to not let you back into teleporter + if (time < phys_teleport_time && phys_movement_x < 0) + wishvel = v_right * phys_movement_y; + else + { + if (phys_onground) + makevectors (phys_v_angle_y * '0 1 0'); + + wishvel = v_forward * phys_movement_x + v_right * phys_movement_y; + } + + if (phys_movetype != MOVETYPE_WALK) + wishvel_z = phys_movement_z; + else + wishvel_z = 0; + + wishdir = normalize(wishvel); + wishspeed = vlen(wishvel); + if (wishspeed > sv_maxspeed) + wishspeed = sv_maxspeed; + + if (phys_movetype == MOVETYPE_NOCLIP) // noclip + { + phys_onground = false; + phys_velocity = wishdir * wishspeed; + } + else if (phys_onground) // walking + { + // friction + if (phys_velocity_x || phys_velocity_y) + { + v = phys_velocity; + v_z = 0; + f = vlen(v); + + // if the leading edge is over a dropoff, increase friction + v = phys_origin + normalize(v) * 16 + '0 0 1' * phys_mins_z; + + traceline(v, v + '0 0 -34', TRUE, self); + + // apply friction + if (trace_fraction == 1.0) + { + if (f < sv_stopspeed) + f = 1 - frametime * (sv_stopspeed / f) * sv_friction * sv_edgefriction; + else + f = 1 - frametime * sv_friction * sv_edgefriction; + } + else + { + if (f < sv_stopspeed) + f = 1 - frametime * (sv_stopspeed / f) * sv_friction; + else + f = 1 - frametime * sv_friction; + } + + if (f < 0) + phys_velocity = '0 0 0'; + else + phys_velocity = phys_velocity * f; + } + + // acceleration + f = wishspeed - (phys_velocity * wishdir); + if (f > 0) + phys_velocity = phys_velocity + wishdir * min(f, sv_accelerate * frametime * wishspeed); + } + else // airborn + { + if (wishspeed < 30) + f = wishspeed - (phys_velocity * wishdir); + else + f = 30 - (phys_velocity * wishdir); + if (f > 0) + phys_velocity = phys_velocity + wishdir * (min(f, sv_accelerate) * wishspeed * frametime); + } + + PlayerPreThink(); + if (thinkfunc) + thinkfunc(); + + if (!SV_CheckWater (ent) && !phys_waterjump) ) + phys_velocity_z -= phys_gravity * frametime; +// SV_CheckStuck (ent); + SV_WalkMove (ent); + PlayerPostThink(); +} + diff --git a/quakec/csqctest/src/common/playerphysics.qc b/quakec/csqctest/src/common/playerphysics.qc new file mode 100644 index 000000000..852f00944 --- /dev/null +++ b/quakec/csqctest/src/common/playerphysics.qc @@ -0,0 +1,27 @@ + +float movement_time; +float movement_type; +vector movement_angles; +vector movement_velocity; +vector movement_origin; +vector movement_quantities; +float movement_buttons; +float movement_gravity; +float movement_maxspeed; + +void() RunPlayerPhysics = +{ + local vector vel; + local float speed; + + makevectors(movement_angles); + + + vel = v_forward*movement_quantities_x + + v_right*movement_quantities_y + + v_up*movement_quantities_z; + vel = movement_velocity+vel*movement_time; + speed = vlen(vel); + if (speed > maxspeed) + vel = vel * (maxspeed/speed); +}; \ No newline at end of file diff --git a/quakec/csqctest/src/common/pmove.qc b/quakec/csqctest/src/common/pmove.qc new file mode 100644 index 000000000..a822d5ef6 --- /dev/null +++ b/quakec/csqctest/src/common/pmove.qc @@ -0,0 +1,76 @@ + +float clientcommandframe; +float input_timelength; +vector input_angles; +vector input_movevalues; +float input_buttons; +float input_impulse; +//float input_lightlevel; +//float input_weapon; +//float input_servertime; + +float pmove_type; +vector pmove_org; +vector pmove_vel; +vector pmove_mins; +vector pmove_maxs; +float pmove_jump_held; +float pmove_waterjumptime; + +float movevars_friction; +float movevars_gravity; + +float movevars_stepheight = 22; + +#ifdef OWNPLAYERPHYSICS + +void PMove_Move(vector dest) //move forwards (preferably on the level) (does step ups) +{ + vector src; + float stepped; + tracebox(pmove_org, pmove_mins, pmove_maxs, dest, false, self); //try going straight there + + if (trace_fraction < 1) + { //step up + src = trace_endpos; + trace_endpos_z += movevars_stepheight; + tracebox(src, pmove_mins, pmove_maxs, dest, false, self); + stepped = trace_endpos_z - src_z; + dest_z += stepped; + + //move forwards + tracebox(trace_endpos, pmove_mins, pmove_maxs, dest, false, self); + + //move down + dest_z -= stepped; + tracebox(trace_endpos, pmove_mins, pmove_maxs, dest, false, self); + } + pmove_org = trace_endpos; +}; + +void PMove(void) +{ + makevectors(input_angles); + + + pmove_vel *= movevars_friction*input_timelength; + pmove_vel += input_timelength*( + v_forward * input_movevalues_x + + v_right * input_movevalues_y + + v_up * input_movevalues_z); + + switch(pmove_type) + { + case MOVETYPE_WALK: + pmove_vel_z += movevars_gravity*input_timelength; + PMove_Move(pmove_org + pmove_vel*input_timelength); + break; + case MOVETYPE_NOCLIP: + pmove_org += pmove_vel*input_timelength; + break; + case MOVETYPE_NONE: + break; + } +}; + +#endif diff --git a/quakec/csqctest/src/common/sv_user.qc b/quakec/csqctest/src/common/sv_user.qc new file mode 100644 index 000000000..0551771d6 --- /dev/null +++ b/quakec/csqctest/src/common/sv_user.qc @@ -0,0 +1,42 @@ +void() SV_PlayerPhysics = +{ + if (time != lastclientthink) + { + lastclientthink = time; + sv_maxspeed = cvar("sv_maxspeed"); + sv_friction = cvar("sv_friction"); + sv_accelerate = cvar("sv_accelerate"); + sv_stopspeed = cvar("sv_stopspeed"); + sv_edgefriction = cvar("edgefriction"); + // LordHavoc: this * 4 is an optimization + cl_rollangle = cvar("cl_rollangle") * 4; + // LordHavoc: this 1 / is an optimization + cl_divspeed = 1 / cvar("cl_rollspeed"); + } + + + phys_movetype = self.movetype; + phys_health = self.health; + phys_fixangle = self.fixangle; + phys_onground = self.flags & FL_ONGROUND; + phys_waterjump = self.flags * FL_WATERJUMP; +// phys_angles = self.angles; + phys_v_angles = self.v_angles; + phys_velocity = self.velocity; + phys_movement = self.movement; + phys_punchangle = self.punchangle; + + RunPlayerPhysics(); + + if (phys_onground) + self.flags = self.flags | FL_ONGROUND; + else + self.flags = self.flags - (self.flags & FL_ONGROUND); + if (phys_waterjump) + self.flags = self.flags | FL_WATERJUMP; + else + self.flags = self.flags - (self.flags & FL_WATERJUMP); + self.angles = phys_angles; + self.velocity = phys_velocity; + self.punchangle = phys_punchangle; +}; \ No newline at end of file diff --git a/quakec/csqctest/src/cs/animation.qc b/quakec/csqctest/src/cs/animation.qc new file mode 100644 index 000000000..f62322b21 --- /dev/null +++ b/quakec/csqctest/src/cs/animation.qc @@ -0,0 +1,1350 @@ +//This file provides support for Q3-compatible player models. + +/* + This module provides: + bool(string newmodelskin) Anim_SetModel + This function applies the named model (eg: "sarge" or "sarge/red") to self. + Returns false on failure. If it fails, the entity will be untouched. + void() Anim_Draw + This function adds self's segmented models to the scene. + This is intended to be called from inside a predraw function. + void() Anim_UnsetModel + This frees everything assosiated with self, but Does not flush the animation file. + entity() Anim_DupModel + Duplicates the animation state/model from self entity to a newly spawned entity. + This is expected to be used for bodyqueues. + float(string fname) Anim_ReadAnimationFile + An explicit call is not required, except as perhaps a precache. + fname is eg: "sarge", but NOT "sarge/red". + Returns -1 on failure. + Fails if list is full or animation.cfg is not found. Does not fail if a model is not found. + float() Anim_GetGender + Returns which gender the 'self' player model is. + float(string skinname) Anim_GetHeadModelIndex + Returns a modelindex assosiated with the given model/skin name. + Intended for the hud. + float(string skinname) Anim_GetHeadSkinNumber + Returns a skin number for use with the modelindex returned by Anim_GetHeadModelIndex to give the correct model/skin for the given model/skin parameter. + Intended for the hud. + vector(string skinname) Anim_GetHeadOffset + Retrieves the q3 head offset for displaying the head in a nice neat box on the hud. + + if only I were allowed to use pointers... these three head functions would be a single more efficient function + +*/ + + + +//These $frame lines of course state the quake player frames that we're using as cues for which animation to play. +//(less work that way) + +// +// running +// +$frame axrun1 axrun2 axrun3 axrun4 axrun5 axrun6 + +$frame rockrun1 rockrun2 rockrun3 rockrun4 rockrun5 rockrun6 + +// +// standing +// +$frame stand1 stand2 stand3 stand4 stand5 + +$frame axstnd1 axstnd2 axstnd3 axstnd4 axstnd5 axstnd6 +$frame axstnd7 axstnd8 axstnd9 axstnd10 axstnd11 axstnd12 + + +// +// pain +// +$frame axpain1 axpain2 axpain3 axpain4 axpain5 axpain6 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + + +// +// death +// + +$frame axdeth1 axdeth2 axdeth3 axdeth4 axdeth5 axdeth6 +$frame axdeth7 axdeth8 axdeth9 + +$frame deatha1 deatha2 deatha3 deatha4 deatha5 deatha6 deatha7 deatha8 +$frame deatha9 deatha10 deatha11 + +$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8 +$frame deathb9 + +$frame deathc1 deathc2 deathc3 deathc4 deathc5 deathc6 deathc7 deathc8 +$frame deathc9 deathc10 deathc11 deathc12 deathc13 deathc14 deathc15 + +$frame deathd1 deathd2 deathd3 deathd4 deathd5 deathd6 deathd7 +$frame deathd8 deathd9 + +$frame deathe1 deathe2 deathe3 deathe4 deathe5 deathe6 deathe7 +$frame deathe8 deathe9 + +// +// attacks +// +$frame nailatt1 nailatt2 + +$frame light1 light2 + +$frame rockatt1 rockatt2 rockatt3 rockatt4 rockatt5 rockatt6 + +$frame shotatt1 shotatt2 shotatt3 shotatt4 shotatt5 shotatt6 + +$frame axatt1 axatt2 axatt3 axatt4 axatt5 axatt6 + +$frame axattb1 axattb2 axattb3 axattb4 axattb5 axattb6 + +$frame axattc1 axattc2 axattc3 axattc4 axattc5 axattc6 + +$frame axattd1 axattd2 axattd3 axattd4 axattd5 axattd6 + +//these are the animation sequence names used in quake3. +enum { + BOTH_DEATH1, + BOTH_DEAD1, + BOTH_DEATH2, + BOTH_DEAD2, + BOTH_DEATH3, + BOTH_DEAD3, + + TORSO_GESTURE, + + TORSO_ATTACK, + TORSO_ATTACK2, + + TORSO_DROP, + TORSO_RAISE, + + TORSO_STAND, + TORSO_STAND2, + + LEGS_WALKCR, + LEGS_WALK, + LEGS_RUN, + LEGS_BACK, + LEGS_SWIM, + + LEGS_JUMP, + LEGS_LAND, + + LEGS_JUMPB, + LEGS_LANDB, + + LEGS_IDLE, + LEGS_IDLECR, + LEGS_TURN, + + NUMANIMS +}; + + +//we use qc arrays to store all the information. this results in a lot of prog space used. +#define MAXMODELS 50 //if progs size becomes an issue, reduce this. + +//a size optimisation. +#define anim_firstframe A +#define anim_numframes B +#define anim_loopingframes C +#define anum_framespersecond D + +//a q3 animation.cfg file contains 4 items per sequence. +nosave float anim_firstframe[NUMANIMS*MAXMODELS]; //first frame in the sequence +nosave float anim_numframes[NUMANIMS*MAXMODELS]; //number of frames in this sequence. +nosave float anim_loopingframes[NUMANIMS*MAXMODELS]; //number of frames to play while looping (jumps to total-looping) +nosave float anum_framespersecond[NUMANIMS*MAXMODELS];//number of frames to play per second. + +nosave float anim_gender[MAXMODELS]; //one of the SEX_ enum values. +nosave string anim_name[MAXMODELS]; //names the (skinless) player model, so they can be cached and shared. +nosave float anim_headmodel[MAXMODELS]; +nosave vector anim_headoffset[MAXMODELS]; + +//the genders you can have. +//we're generous with three. +enum { + GENDER_NEUTER, + GENDER_MALE, + GENDER_FEMALE +}; + +//note: q3 assumes male. +//we assume male too, due to the player model that is typically used if we have no q3 models. +#define GENDER_DEFAULT GENDER_MALE + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//This block of code is to replace builtins which may be missing in your engine of choice. +//Its all generic maths/tag stuff, so consider it just noise :) +//this doesn't affect how the model is built. + +#ifdef WORKINDP +vector getlerpedtaginfo(entity ent, float tagnum) +{ + //personally I consider it a bug that this function is needed. + //this function exactly duplicates the gettaginfo builtin + //but ensures that interpolation based on frame2 happens. + //this matches how the renderer will lerp frames. + + //at the time of writing, this is needed for DP to be smooth. + //fte does not support gettaginfo at all (I've been lazy due to the heirachical nature). + //this is called by RotateVectorsByTag_GTI, so it not required in fte as FTE has a working RotateVectorsByTag instead. + + float frame2ness = ent.lerpfrac; + float frame1ness = 1-frame2ness; + float f1=ent.frame; + float f2=ent.frame2; +//it doesn't matter what the ent's lerpfrac currently is. + vector f1o, f1f, f1r, f1u; + vector f2o, f2f, f2r, f2u; + vector v_origin; + + //make sure both frames are set, in case the builtin is fixed + ent.frame = f1; + ent.frame2 = f1; + f1o = gettaginfo(ent, tagnum); + f1r=v_right;f1f=v_forward;f1u=v_up; + + ent.frame = f2; + ent.frame2 = f2; + v_origin = gettaginfo(ent, tagnum); + + //restore the entity + ent.frame = f1; + ent.frame2 = f2; + + //lerp the current frame2 with the cached frame1 values + v_forward = f1f*frame1ness+v_forward*frame2ness; + v_right = f1r*frame1ness+v_right*frame2ness; + v_up = f1u*frame1ness+v_up*frame2ness; + v_origin = f1o*frame1ness+v_origin*frame2ness; + + return v_origin; +} + +#define RotateVectorsByTag RotateVectorsByTag_GTI +vector RotateVectorsByTag_GTI(entity ent, float tagnum) +{ + vector saveang=ent.angles; + vector saveorg=ent.origin; + + vector oldx=v_forward, oldy=('0 0 0'-v_right), oldz=v_up; + vector oldo=ent.origin; + + ent.angles = '0 0 0'; + ent.origin = '0 0 0'; + vector ango=getlerpedtaginfo(ent, tagnum); + ent.angles = saveang; + ent.origin = saveorg; +//note: v_right is actually left, in tags. + vector angx=v_forward, angy=v_right, angz=v_up; + + angx = normalize(angx); + angy = normalize(angy); + angz = normalize(angz); + + //multiply out the tag matrix with the previous matrix. + v_forward_x = angx_x*oldx_x + angx_y*oldy_x + angx_z*oldz_x; + v_forward_y = angx_x*oldx_y + angx_y*oldy_y + angx_z*oldz_y; + v_forward_z = angx_x*oldx_z + angx_y*oldy_z + angx_z*oldz_z; + v_right_x = angy_x*oldx_x + angy_y*oldy_x + angy_z*oldz_x; + v_right_y = angy_x*oldx_y + angy_y*oldy_y + angy_z*oldz_y; + v_right_z = angy_x*oldx_z + angy_y*oldy_z + angy_z*oldz_z; + v_up_x = angz_x*oldx_x + angz_y*oldy_x + angz_z*oldz_x; + v_up_y = angz_x*oldx_y + angz_y*oldy_y + angz_z*oldz_y; + v_up_z = angz_x*oldx_z + angz_y*oldy_z + angz_z*oldz_z; + + v_right = '0 0 0'-v_right; + + //transform the tag's origin + saveorg = oldo; + saveorg_x += ango_x * oldx_x; + saveorg_y += ango_x * oldx_y; + saveorg_z += ango_x * oldx_z; + saveorg_x += ango_y * oldy_x; + saveorg_y += ango_y * oldy_y; + saveorg_z += ango_y * oldy_z; + saveorg_x += ango_z * oldz_x; + saveorg_y += ango_z * oldz_y; + saveorg_z += ango_z * oldz_z; + return saveorg; +} +#define RotateVectorsByAngle RotateVectorsByAngle_QC +void RotateVectorsByAngle_QC(vector angle) +{ + vector oldx=v_forward, oldy='0 0 0'-v_right, oldz=v_up; + angle_x = -angle_x; + makevectors(angle); + vector angx=v_forward, angy='0 0 0'-v_right, angz=v_up; + + v_forward_x = angx_x*oldx_x + angx_y*oldy_x + angx_z*oldz_x; + v_forward_y = angx_x*oldx_y + angx_y*oldy_y + angx_z*oldz_y; + v_forward_z = angx_x*oldx_z + angx_y*oldy_z + angx_z*oldz_z; + v_right_x = angy_x*oldx_x + angy_y*oldy_x + angy_z*oldz_x; + v_right_y = angy_x*oldx_y + angy_y*oldy_y + angy_z*oldz_y; + v_right_z = angy_x*oldx_z + angy_y*oldy_z + angy_z*oldz_z; + v_up_x = angz_x*oldx_x + angz_y*oldy_x + angz_z*oldz_x; + v_up_y = angz_x*oldx_y + angz_y*oldy_y + angz_z*oldz_y; + v_up_z = angz_x*oldx_z + angz_y*oldy_z + angz_z*oldz_z; + + v_right = '0 0 0'-v_right; +} +#define RotateVectorsByVectors RotateVectorsByVectorsDP + +// +#define skinforname(i,n) 0 +#endif + +//end noisy maths. +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//a utility function required by sexedsound so we don't try playing missing sounds (its common for male models to be missing some) +float(string str) fileexists = +{ + //we use searches because its more likly to be cached than reading a 200kb file from the disk every time. + local float search; + search = search_begin(str, false, true); + if (search < 0) + { + return false; + } + search_end(search); + return true; +}; + +//plays a CHAN_VOICE sound around the given entity. +void(entity ent, string soundname) sexedsound = +{ + string str, full; + if (self == player_local) + if (cvar("cg_noselfsounds")) + return; //option to disable sounds from local player + + str = strcat("player/", anim_name[self.modelnum], "/", soundname); + full = strcat("sound/", str); + if (fileexists(full)) + { + precache_sound(str); + sound(self, CHAN_VOICE, str, 1, 1); + } + else + { + str = strcat("player/sarge/", soundname); // :( + precache_sound(str); + sound(self, CHAN_VOICE, str, 1, 1); + } +}; + + +//our player's frames changed to some new sequence. +//our animation function will animate acordingly. +void(float anum) ForceToAnim = +{ + if (anum <= TORSO_STAND2) + { + self.torsoent.animnum = anum; + self.torsoent.framechangetime = time; + } + if (anum <= BOTH_DEAD3 || anum >= LEGS_WALKCR) + { + self.legsent.animnum = anum; + self.legsent.framechangetime = time; + } +}; + +//this function is per-segment. +//it updates the frame/frame2/lerpfrac values and loops/caps the animation. +//returns true if the end of the current animation was reached. +float(entity ent) animate = +{ +//true if looped + float anum; + float ft; + float fnum; + float numframes; + float fps; + float firstframe; + float loopingframes; + float ret; + + anum = (ent.modelnum * NUMANIMS) + ent.animnum; + + ft = time - ent.framechangetime; + numframes = anim_numframes[anum]; + fps = anum_framespersecond[anum]; + + ft *= fps; + fnum = floor(ft); + ft = ft - fnum; //time into the frame. + if (fnum >= numframes) + { + loopingframes = anim_loopingframes[anum]; + + if (loopingframes) + { + fnum -= numframes - loopingframes; + fnum = fnum - floor(fnum/loopingframes)*loopingframes; + fnum += numframes - loopingframes; + } + else + { //stop at the end of it. + fnum = numframes-1; + ft = 1; + } + + if (numframes == 1) + ent.frame2 = ent.frame; + + ret = true; + } + fnum += anim_firstframe[anum]; + + if (ent.frame2 == -1) + { //special flag to make it snap for the initial frame + ent.frame = fnum; + ent.frame2 = fnum; + } + else if (ent.frame != fnum) + { + ent.frame2 = ent.frame; + ent.frame = fnum; + } + ent.lerpfrac = 1-ft; + if (ent.lerpfrac<=0) + ent.frame2 = ent.frame; + + return ret; +}; + +.float wasinair; +//this function checks to see if the player is jumping/flying/dead/moving, and just updates the legs to match the current events and time. +void() LegsUpdateAnim = +{ + float inair; + float onground; + tracebox(self.origin, self.mins, self.maxs, self.origin-'0 0 2', FALSE, self); + + if (trace_fraction == 1) + inair = self.velocity_z; + + if (self.legsent.animnum > BOTH_DEAD3) + if ((self.wasinair!=0) != (inair!=0)) + { + if (trace_fraction == 1) //in air + { + if (self.velocity_z > 5) + { + makevectors(self.angles); + if (v_forward * self.velocity >= 0) + ForceToAnim(LEGS_JUMP); + else + ForceToAnim(LEGS_JUMPB); + } + } + else + { + if (inair < -5 || self.wasinair < -5) + { + if (self.animnum == LEGS_JUMPB) + ForceToAnim(LEGS_LANDB); + else + ForceToAnim(LEGS_LAND); + } + } + self.wasinair = inair; + } + + if (vlen(self.velocity) > 0.1) + { + if (self.legsent.animnum == LEGS_IDLE) + { + if (self.velocity * v_forward > 0) + ForceToAnim(LEGS_RUN); + else + ForceToAnim(LEGS_BACK); + } + } + else + { + if (self.legsent.animnum == LEGS_RUN || self.legsent.animnum == LEGS_BACK) + ForceToAnim(LEGS_IDLE); + } + + if (animate(self.legsent)) + { + if (self.legsent.animnum <= BOTH_DEAD3) + { + return; //don't play the idle anim when dead. + } + if (self.wasinair) + { + return; //don't change the legs anim whilst flying. + } + + if (self.velocity_x || self.velocity_y) + { + if (self.velocity * v_forward > 0) + ForceToAnim(LEGS_RUN); + else + ForceToAnim(LEGS_BACK); + } + else + { + ForceToAnim(LEGS_IDLE); + } + + animate(self.legsent); + } +}; + +//updates the torso's animations. basically just shoots/gestures/or otherwise just updates to the current time. +void() TorsoUpdateAnim = +{ + if (animate(self.torsoent)) + { + if (self.frame >= $axdeth1 && self.frame <= $deathe9) + return; //dead. + + if (self.frame == $nailatt1 || self.frame == $nailatt2 || + self.frame == $light1 || self.frame == $light2) + ForceToAnim(TORSO_ATTACK); //these ones loop + else if (random() < 0.005 && !(self.velocity_x || self.velocity_y) && (chasecam || self != player_local)) + { //randomly taunt, when standing still, when not first-person (making the sounds is just confusing when first person) + sexedsound(self, "taunt.wav"); + ForceToAnim(TORSO_GESTURE); + } + else if ((self.frame >= $axrun1 && self.frame <= $axrun6) || + (self.frame >= $axstnd1 && self.frame <= $axstnd12) || + (self.frame >= $axpain1 && self.frame <= $axpain6)) + ForceToAnim(TORSO_STAND2); + else + ForceToAnim(TORSO_STAND); + animate(self.legsent); + } +}; + +//adds a q3-shell around the model based on which powerups they have active. +//and just basically acts as a wrapper to addentity. +void(entity ent) AddModelWithEffects = +{ + if (self.sveffects & SVE_INVIS) + ent.forceshader = shaderforname("powerups/invisibility"); + + addentity(ent); + if (self.sveffects & SVE_QUAD) + { + ent.fatness = -2; + ent.forceshader = shaderforname("powerups/quad"); + addentity(ent); + } + if (self.sveffects & SVE_GOD) + { + ent.fatness = -2; + ent.forceshader = shaderforname("powerups/regen"); + addentity(ent); + } + ent.fatness = 0; + ent.forceshader = 0; +}; + +.float ideal_yaw; +.float yaw_speed; +.float tag_index; + +//this function is called inside your base entity's predraw function (which should then return false) +void() Anim_Draw = +{ + vector tf, tr, tu; + vector ang; + float move; + string weaponname; + + self.modelindex = 0; //should never have been anything else. + + + if (player_local == self && !chasecam) + { + //we still add the local player entity, although only to mirrors. + self.legsent.renderflags = RF_USEAXIS|RF_EXTERNALMODEL; + self.torsoent.renderflags = RF_USEAXIS|RF_EXTERNALMODEL; + self.headent.renderflags = RF_USEAXIS|RF_EXTERNALMODEL; + self.weaponent.renderflags = RF_USEAXIS|RF_EXTERNALMODEL; + } + else + { + self.legsent.renderflags = RF_USEAXIS; + self.torsoent.renderflags = RF_USEAXIS; + self.headent.renderflags = RF_USEAXIS; + self.weaponent.renderflags = RF_USEAXIS; + } + + if (!(self.frame >= $axdeth1 && self.frame <= $deathe9)) + { + //if they're still alive + //animate the legs a bit so they turn to the player, but not for 1-degree turns. little more realism there. + + ang_y = self.angles_y; + if (self.velocity_x||self.velocity_y) + { + makevectors(ang); + tf = self.velocity; + tf_z = 0; + tf = normalize(tf); + if (v_forward*tf > -0.01) + self.legsent.ideal_yaw = vectoyaw(tf); + else + self.legsent.ideal_yaw = vectoyaw(tf)+180; + } + else + { + move = ang_y - self.legsent.ideal_yaw; + if (move < -180) + move += 360; + if (move > 180) + move -= 360; + + if (move*move > 30*30) + ForceToAnim(LEGS_TURN); + + if (self.legsent.animnum == LEGS_TURN || self.legsent.animnum == LEGS_JUMP) + self.legsent.ideal_yaw = ang_y; + } + other = self; + self = self.legsent; + self.yaw_speed = 5;//180*frametime; + + //clamp the legs to never be more than 90 degrees + move = other.angles_y-self.angles_y; + if (move < -180) + move += 360; + if (move > 180) + move -= 360; + //turn the legs + if (move*move > 95*95) //snap + { + if (move>0) + move=20; + else + move=-20; + self.angles_y = other.angles_y - move; + self = other; + } + else + ChangeYaw(); + self = other; + } + + + if (self.frame != self.frame2) + { + //see if the player changed to any animations. + if (self.frame >= $axdeth1 && self.frame <= $axdeth8 && self.legsent.animnum != BOTH_DEATH1) + { + sexedsound(self, "death1.wav"); + ForceToAnim(BOTH_DEATH1); + } + else if (self.frame == $axdeth9 && self.frame2 != $axdeth8) + ForceToAnim(BOTH_DEAD1); //suddenly appeared with this frame (otherwise we just flow into it) + + else if (self.frame == $deatha1 && self.frame <= $deatha10 && self.legsent.animnum != BOTH_DEATH2) + { + sexedsound(self, "death2.wav"); + ForceToAnim(BOTH_DEATH2); + } + else if (self.frame == $deatha11 && self.frame2 != $deatha10) + ForceToAnim(BOTH_DEAD2); //suddenly appeared with this frame (otherwise we just flow into it) + + else if (self.frame == $deathb1 && self.frame <= $deathb8 && self.legsent.animnum != BOTH_DEATH3) + { + sexedsound(self, "death3.wav"); + ForceToAnim(BOTH_DEATH3); + } + else if (self.frame == $deathb9 && self.frame2 != $deathb8) + ForceToAnim(BOTH_DEAD3); //suddenly appeared with this frame (otherwise we just flow into it) + + else if (self.frame == $deathc1 && self.frame <= $deathc14 && self.legsent.animnum != BOTH_DEATH1) + { + sexedsound(self, "death1.wav"); + ForceToAnim(BOTH_DEATH1); + } + else if (self.frame == $deathc15 && self.frame2 != $deathc14) + ForceToAnim(BOTH_DEAD1); //suddenly appeared with this frame (otherwise we just flow into it) + + else if (self.frame == $deathd1 && self.frame <= $deathd8 && self.legsent.animnum != BOTH_DEATH2) + { + sexedsound(self, "death2.wav"); + ForceToAnim(BOTH_DEATH2); + } + else if (self.frame == $deathd9 && self.frame2 != $deathd8) + ForceToAnim(BOTH_DEAD2); //suddenly appeared with this frame (otherwise we just flow into it) + + else if (self.frame == $deathe1 && self.frame <= $deathe8 && self.legsent.animnum != BOTH_DEATH3) + { + sexedsound(self, "death3.wav"); + ForceToAnim(BOTH_DEATH3); + } + else if (self.frame == $deathe9 && self.frame2 != $deathe8) + ForceToAnim(BOTH_DEAD3); //suddenly appeared with this frame (otherwise we just flow into it) + + else if ((self.frame == $nailatt1 || self.frame == $nailatt2) && + (self.frame2 != $nailatt1 && self.frame2 != $nailatt2)) + ForceToAnim(TORSO_ATTACK); + else if ((self.frame == $light1 || self.frame == $light2) && + (self.frame2 != $light1 && self.frame2 != $light2)) + ForceToAnim(TORSO_ATTACK); + else if (self.frame == $rockatt1) + ForceToAnim(TORSO_ATTACK); + else if (self.frame == $shotatt1) + ForceToAnim(TORSO_ATTACK); + else if (self.frame == $axatt1) + ForceToAnim(TORSO_ATTACK2); + else if (self.frame == $axattb1) + ForceToAnim(TORSO_ATTACK2); + else if (self.frame == $axattc1) + ForceToAnim(TORSO_ATTACK2); + else if (self.frame == $axattd1) + ForceToAnim(TORSO_ATTACK2); + else if (self.frame2 >= $axdeth1 && self.frame2 <= $deathe9 && !(self.frame >= $axdeth1 && self.frame <= $deathe9)) + { //respawned + ForceToAnim(LEGS_IDLE); + ForceToAnim(TORSO_STAND); + } + self.frame2 = self.frame; + } + + //add a dynamic light around the player if they have any powerups. + if (self.sveffects & SVE_QUAD) + ang_z = 1; + if (self.sveffects & SVE_GOD) + ang_x = 1; + ang_y = 0; + if (ang != '0 0 0') + { + adddynamiclight(self.origin, 400, ang); + } + + //if they're meant to be transparent, propogate that. + self.legsent.alpha = self.torsoent.alpha = self.headent.alpha = self.weaponent.alpha = self.alpha; + //LegsUpdateAnim needs its origin early, for stff + self.legsent.origin = self.origin; + + //update the animation lerps + makevectors(self.legsent.angles); + LegsUpdateAnim(); + TorsoUpdateAnim(); + + //add the legs into the scene, with their lagged angles. + AddModelWithEffects(self.legsent); + //legs are in place, matricies are set up for them. + + //work out where to put the torso by querying the tag + self.torsoent.origin = RotateVectorsByTag(self.legsent, self.torsoent.tag_index);//figure out the torso position + //torso's angles are not lagged, and must always point directly at the target, so rotate by the extra angles. + ang = self.angles; + ang_y = self.angles_y - self.legsent.angles_y; //keep the angle on the legs + ang_x*=2; + if (self.legsent.animnum > BOTH_DEAD3) + RotateVectorsByAngle(ang); //rotate the torso (when dead the whole thing acts as one model with no custom angles inside) + AddModelWithEffects(self.torsoent); + //torso is now added to the scene. + + //save the direction we're looking in for the weapon which is added after the head. + tf = v_forward; + tr = v_right; + tu = v_up; + + //now work out where to put the head + self.headent.origin = RotateVectorsByTag(self.torsoent, self.headent.tag_index);// + ang_y = sin(time)*22.5; + ang_x = cos(time*0.4532)*11.25; + if (self.legsent.animnum > BOTH_DEAD3) + RotateVectorsByAngle(ang); //make the head around a bit + AddModelWithEffects(self.headent); + //head is now in place + + if (self.frame >= $axdeth1 && self.frame <= $deathe9) + return; //don't show the weapon in death frames. + + //and revert the matrix back to how it was before the head. + v_forward = tf; + v_right = tr; + v_up = tu; + + move = self.sveffects&15; + switch (move) + { + case 12: //axe + weaponname = "models/weapons2/gauntlet/gauntlet"; + break; + default: + case 0: //shotgun + weaponname = "models/weapons2/railgun/railgun"; //well... the sniper's prefered weapon, at least. :p + break; + case 1: //super shotgun + weaponname = "models/weapons2/shotgun/shotgun"; + break; + case 2: //nailgun + weaponname = "models/weapons2/machinegun/machinegun"; + break; + case 3: //super nailgun + weaponname = "models/weapons2/plasma/plasma"; + break; + case 4: //grenade launcher + weaponname = "models/weapons2/grenadel/grenadel"; + break; + case 5: //rocket launcher + weaponname = "models/weapons2/rocketl/rocketl"; + break; + case 6: //lightning gun + weaponname = "models/weapons2/lightning/lightning"; + break; + } + + setmodel(self.weaponent, strcat(weaponname, ".md3")); + + //rotate by a tag on the torso + self.weaponent.origin = RotateVectorsByTag(self.torsoent, self.weaponent.tag_index);//place the weapon in the hand + //and add it. + AddModelWithEffects(self.weaponent); + + //this check is a little wrong. + if (self.torsoent.animnum == TORSO_ATTACK || self.torsoent.animnum == TORSO_ATTACK2) + { + move = gettagindex(self.weaponent, "tag_flash"); + if (move) + { + //they're shooting something. make a muzzleflash appear at the end of their weapon. + self.weaponent.origin = RotateVectorsByTag(self.weaponent, move); + setmodel(self.weaponent, strcat(weaponname, "_flash.md3")); + AddModelWithEffects(self.weaponent); + } + } +}; + +//remove our attached models, restoring the player model to being a boring player. +void() Anim_UnsetModel = +{ + if (self.torsoent) + remove(self.torsoent); + if (self.headent) + remove(self.headent); + if (self.legsent) + remove(self.legsent); + if (self.weaponent) + remove(self.weaponent); + + self.torsoent = world; + self.headent = world; + self.legsent = world; + self.weaponent = world; + self.modelnum = -1; + + setmodel(self, self.model); +}; + +float() Anim_GetGender = +{ + if (self.headent) + return anim_gender[self.headent.modelnum]; + return GENDER_DEFAULT; +}; + +//Attempts to read the animation file for the named q3 player model +//-1 on failure. +float(string modname) Anim_ReadAnimationFile = +{ + local float modnum; + local string str; + local float file; + local float sequencenum; + local float stupid; + + if (modname == "") + return -1; + + for (modnum = 0; modnum < MAXMODELS; modnum++) + { + if (anim_name[modnum] == modname) + return modnum; //already loaded + if (anim_name[modnum] == "") + break; //empty slot + } + if (modnum == MAXMODELS) + { //list is full + print("Too many models\n"); + return -1; + } + else + { + str = strcat("models/players/", modname, "/animation.cfg"); + + file = fopen(str, FILE_READ); + if (file < 0) + { + print("fopen ", modname, " failed\n"); + return false; + } + + modname= strzone(modname); + anim_name[modnum] = modname; + + //precache them. + precache_model(strcat("models/players/", modname, "/upper.md3")); + precache_model(strcat("models/players/", modname, "/lower.md3")); + precache_model(strcat("models/players/", modname, "/head.md3")); + + anim_headmodel[modnum] = modelindex_for_name(strcat("models/players/", modname, "/head.md3")); + + //default general values + anim_gender[modnum] = GENDER_DEFAULT; + anim_headoffset[modnum] = '0 0 0'; + + for (;;) + { + str = fgets(file); + if not (str) break; + + tokenize(str); + str = argv(0); + if (str == "") + continue; + else if (str == "sex") + { + str = argv(1); + if (str == "m" || str == "M") + anim_gender[modnum] = GENDER_MALE; + else if (str == "f" || str == "F") + anim_gender[modnum] = GENDER_FEMALE; + else //n or N + anim_gender[modnum] = GENDER_NEUTER; + } + else if (str == "headoffset") + { + vector v; + v_x = stof(argv(1)); + v_y = stof(argv(2)); + v_z = stof(argv(3)); + anim_headoffset[modnum] = v; + } + else if (str == "footsteps") + { + //we don't play footsteps anyway + } + else if (str2chr(str,0) >= '0' && str2chr(str,0) <= '9') + { + if (sequencenum == NUMANIMS) + print("animation file \"" "models/players/", modname, "/animation.cfg" "\" contains too many animations\n"); + else + { + if (sequencenum == LEGS_WALKCR) //for some stupid reason, the leg frames start where the torso leaves + { + stupid = stof(str); + stupid = stupid - anim_firstframe[(modnum * NUMANIMS) + TORSO_GESTURE]; + } + anim_firstframe[(modnum * NUMANIMS) + sequencenum] = stof(str) - stupid; + anim_numframes[(modnum * NUMANIMS) + sequencenum] = stof(argv(1)); + anim_loopingframes[(modnum * NUMANIMS) + sequencenum] = stof(argv(2)); + anum_framespersecond[(modnum * NUMANIMS) + sequencenum] = stof(argv(3)); + sequencenum++; + } + } + else + print("animation.cfg contains unrecognised token ", str, "\n"); + } + + fclose(file); + + if (sequencenum != NUMANIMS) + print("animation.cfg is incompleate\n"); + } + return modnum; +} + +//attempts to apply a player model/skin to the given entity. +//this may load the configuration.cfg +//skinname is of the form: ranger/default +float(string skinname) Anim_SetModel = +{ + local string lowermodelname; + local string uppermodelname; + local string headmodelname; + + local string lowerskinname; + local string upperskinname; + local string headskinname; + + local float lowermodnum; + local float uppermodnum; + local float headmodnum; + + local string str; + local float slashpos; + local float file; + local float sequencenum; + local float stupid; + + tokenize(skinname); + lowermodelname = argv(2); + uppermodelname = argv(1); + headmodelname = argv(0); + + slashpos = strstrofs(lowermodelname, "/"); +#ifdef WORKINDP + lowerskinname = substring(lowermodelname, slashpos+1, strlen(lowermodelname) - (slashpos+1)); +#else + lowerskinname = substring(lowermodelname, slashpos+1, -1); +#endif + lowermodelname = substring(lowermodelname, 0, slashpos); + + slashpos = strstrofs(uppermodelname, "/"); +#ifdef WORKINDP + upperskinname = substring(uppermodelname, slashpos+1, strlen(uppermodelname) - (slashpos+1)); +#else + upperskinname = substring(uppermodelname, slashpos+1, -1); +#endif + uppermodelname = substring(uppermodelname, 0, slashpos); + + slashpos = strstrofs(headmodelname, "/"); +#ifdef WORKINDP + headskinname = substring(headmodelname, slashpos+1, strlen(headmodelname) - (slashpos+1)); +#else + headskinname = substring(headmodelname, slashpos+1, -1); +#endif + headmodelname = substring(headmodelname, 0, slashpos); + + //seeing as we support loading each part from a different player model (well, q3 does) + //we load it three times. + lowermodnum = Anim_ReadAnimationFile(lowermodelname); + uppermodnum = Anim_ReadAnimationFile(uppermodelname); + headmodnum = Anim_ReadAnimationFile(headmodelname); + + //all failed + if (lowermodnum < 0 && uppermodnum < 0 && headmodnum < 0) + return false; //failed to load the animation. + + //make sure that all three parts are valid or something. + if (headmodnum < 0) + { + if (lowermodnum < 0) + { + headmodnum = uppermodnum; + headmodelname = uppermodelname; + headskinname = upperskinname; + } + else + { + headmodnum = lowermodnum; + headmodelname = lowermodelname; + headskinname = lowerskinname; + } + } + if (lowermodnum < 0) + { + lowermodnum = headmodnum; + lowermodelname = headmodelname; + lowerskinname = headskinname; + } + if (uppermodnum < 0) + { + uppermodnum = headmodnum; + uppermodelname = headmodelname; + upperskinname = headskinname; + } + + //spawn the attaching ents + if (!self.torsoent) + self.torsoent = spawn(); + if (!self.headent) + self.headent = spawn(); + if (!self.legsent) + self.legsent = spawn(); + if (!self.weaponent) + self.weaponent = spawn(); + + //give them the correct model + setmodel(self.legsent, strcat("models/players/", anim_name[lowermodnum], "/lower.md3")); + setmodel(self.torsoent, strcat("models/players/", anim_name[uppermodnum], "/upper.md3")); + setmodel(self.headent, strcat("models/players/", anim_name[headmodnum], "/head.md3")); + +// precache_model(AXEMODELNAME); +// precache_model(WEAPONMODELNAME); + + + self.legsent.owner = self; + self.headent.owner = self; + self.torsoent.owner = self; + self.weaponent.owner = self; + + self.drawmask = MASK_NORMAL; //general view. + + //find the tags so we don't do it every single frame + self.torsoent.tag_index = gettagindex(self.legsent, "tag_torso"); + self.headent.tag_index = gettagindex(self.torsoent, "tag_head"); + self.weaponent.tag_index = gettagindex(self.torsoent, "tag_weapon"); + + self.modelnum = headmodnum; + self.legsent.modelnum = lowermodnum; + self.headent.modelnum = headmodnum; + self.torsoent.modelnum = uppermodnum; + self.weaponent.modelnum = lowermodnum; + + self.legsent.colormap = self.colormap; + self.headent.colormap = self.colormap; + self.torsoent.colormap = self.colormap; + self.weaponent.colormap = self.colormap; + + if (!lowerskinname) + lowerskinname = "default"; + if (!upperskinname) + upperskinname = "default"; + if (!headskinname) + headskinname = "default"; + + //find which skin number to use for the given skin file + if (stof(lowerskinname)) + self.legsent.skin = stof(lowerskinname); + else + self.legsent.skin = skinforname(self.legsent.modelindex, strcat("models/players/", anim_name[lowermodnum], "/lower_", lowerskinname, ".skin")); + if (stof(upperskinname)) + self.torsoent.skin = stof(upperskinname); + else + self.torsoent.skin = skinforname(self.torsoent.modelindex, strcat("models/players/", anim_name[uppermodnum], "/upper_", upperskinname, ".skin")); + if (stof(headskinname)) + self.headent.skin = stof(headskinname); + else + self.headent.skin = skinforname(self.headent.modelindex, strcat("models/players/", anim_name[headmodnum], "/head_", headskinname, ".skin")); + + //setup the initial sequences. + ForceToAnim(LEGS_IDLE); + ForceToAnim(TORSO_STAND); + + //so it takes effect fully and immediatly... well, the first time its drawn, anyway. + self.legsent.framechangetime = -50; + self.torsoent.framechangetime = -50; + self.legsent.frame2 = -1; + self.torsoent.frame2 = -1; + + self.frame2 = -1; + self.lerpfrac = 0; + + return true; +}; + +entity(entity src) CloneModel = +{ + local entity dest; + dest = spawn(); + + dest.modelnum = src.modelnum; + dest.animnum = src.animnum; + dest.colormap = src.colormap; + dest.tag_index = src.tag_index; + dest.skin = src.skin; + dest.predraw = src.predraw; + dest.frame = src.frame; + dest.frame2 = src.frame2; + dest.model = src.model; + dest.modelindex = src.modelindex; + dest.drawmask = src.drawmask; + dest.origin = src.origin; + dest.angles = src.angles; + dest.mins = src.mins; + dest.maxs = src.maxs; + + return dest; +}; + +entity() Anim_DupModel = +{ + local entity o, n; + o = self; + n = self = CloneModel(o); + + self.legsent = CloneModel(o.legsent); + self.headent = CloneModel(o.headent); + self.torsoent = CloneModel(o.torsoent); + self.weaponent = CloneModel(o.weaponent); + self.velocity = o.velocity; + + + self = o; + return n; +}; + +float(string skinname) Anim_GetHeadModelIndex = +{ + float slashpos; + string modelname; + float modnum; + + tokenize(skinname); + modelname = argv(0); + if (modelname == "") + return 0; //an invalid modelindex. + + slashpos = strstrofs(modelname, "/"); + modelname = substring(modelname, 0, slashpos); + + //seeing as we support loading each part from a different player model (well, q3 does) + //we load it three times. + modnum = Anim_ReadAnimationFile(modelname); + if (modnum < 0) + return 0; + + return anim_headmodel[modnum]; +}; + +float(string skinname) Anim_GetHeadSkinNumber = +{ + float slashpos; + string modelname; + float modnum; + + tokenize(skinname); + modelname = argv(0); + if (modelname == "") + return 0; //0 = default + + slashpos = strstrofs(modelname, "/"); +#ifdef WORKINDP + skinname = substring(modelname, slashpos+1, strlen(modelname) - (slashpos+1)); +#else + skinname = substring(modelname, slashpos+1, -1); +#endif + modelname = substring(modelname, 0, slashpos); + + if (stof(skinname)) + return stof(skinname); + + //seeing as we support loading each part from a different player model (well, q3 does) + //we load it three times. + modnum = Anim_ReadAnimationFile(modelname); + if (modnum < 0) + return 0; + + if (!skinname) + skinname = "default"; + + return skinforname(anim_headmodel[modnum], strcat("models/players/", modelname, "/head_", skinname, ".skin")); +}; + +vector(string skinname) Anim_GetHeadOffset = +{ + float slashpos; + string modelname; + float modnum; + + tokenize(skinname); + modelname = argv(0); + if (modelname == "") + return 0; //an invalid modelindex. + + slashpos = strstrofs(modelname, "/"); + modelname = substring(modelname, 0, slashpos); + + //seeing as we support loading each part from a different player model (well, q3 does) + //we load it three times. + modnum = Anim_ReadAnimationFile(modelname); + if (modnum < 0) + return 0; + return anim_headoffset[modnum]; +} + + + +float(float channel, string soundname, vector pos, float vol, float attenuation) CSQC_ServerSound = +{ //the server started a sound on an entity that the csqc has control over. + if (!self.headent) + { + return false; + } + + if (soundname == "player/plyrjmp8.wav") + { + if (self == player_local) + if (cvar("cg_noselfjumpsound")) + return true; //option to disable jump noise for local player. + sexedsound(self, "jump1.wav"); + return true; + } + if (soundname == "player/gasp1.wav") + { + sexedsound(self, "gasp.wav"); + return true; + } + if (soundname == "player/gasp2.wav") + { + sexedsound(self, "gasp.wav"); + return true; + } + if (soundname == "player/land.wav") + { + sexedsound(self, "fall1.wav"); + return true; + } + if (soundname == "player/land2.wav") + { + sexedsound(self, "fall1.wav"); + return true; + } + + if (soundname == "player/pain1.wav") + { + sexedsound(self, "pain25_1.wav"); + return true; + } + if (soundname == "player/pain2.wav") + { + sexedsound(self, "pain50_1.wav"); + return true; + } + if (soundname == "player/pain3.wav") + { + sexedsound(self, "pain75_1.wav"); + return true; + } + if (soundname == "player/pain4.wav") + { + sexedsound(self, "pain100_1.wav"); + return true; + } + if (soundname == "player/pain5.wav") + { + sexedsound(self, "pain75_1.wav"); + return true; + } + if (soundname == "player/pain6.wav") + { + sexedsound(self, "pain100_1.wav"); + return true; + } + + if (soundname == "player/h2odeath.wav") + { + sexedsound(self, "drown.wav"); + return true; + } + if (soundname == "player/death1.wav") //normal deaths come from the player animations. + return true; + if (soundname == "player/death2.wav") + return true; + if (soundname == "player/death3.wav") + return true; + if (soundname == "player/death4.wav") + return true; + if (soundname == "player/death5.wav") + return true; + + return false; +}; + +float(float sventnum, float channel, string soundname, float vol, float att, vector org) CSQC_Event_Sound = +{ + self = findfloat(world, entnum, sventnum); + if (self) + return CSQC_ServerSound(channel, soundname, org, vol, att); + return false; +}; diff --git a/quakec/csqctest/src/cs/constants.qc b/quakec/csqctest/src/cs/constants.qc new file mode 100644 index 000000000..4c9c73dbd --- /dev/null +++ b/quakec/csqctest/src/cs/constants.qc @@ -0,0 +1,107 @@ +//FIXME: most of this should be in common/constants.qc + +// +// constants +// + +// point content values + +float CONTENT_EMPTY = -1; +float CONTENT_SOLID = -2; +float CONTENT_WATER = -3; +float CONTENT_SLIME = -4; +float CONTENT_LAVA = -5; +float CONTENT_SKY = -6; + +// sound channels +// channel 0 never willingly overrides +// other channels (1-7) allways override a playing sound on that channel +float CHAN_AUTO = 0; +float CHAN_WEAPON = 1; +float CHAN_VOICE = 2; +float CHAN_ITEM = 3; +float CHAN_BODY = 4; + +float ATTN_NONE = 0; +float ATTN_NORM = 1; +float ATTN_IDLE = 2; +float ATTN_STATIC = 3; + + +// entity effects + +float EF_BRIGHTFIELD = 1; +float EF_MUZZLEFLASH = 2; +float EF_BRIGHTLIGHT = 4; +float EF_DIMLIGHT = 8; + + + + +float MASK_ENGINE = 1; //this is special. Any entities known by the engine but not the csqc will be added. +//you can add any other masks below, remember, use bits. +float MASK_ENGINEVIEWMODEL = 2; //asks the engine to add the viewmodels too +float MASK_NORMAL = 4; + + + +float INPUT_KEYDOWN = 0; +float INPUT_KEYUP = 1; +float INPUT_MOUSEMOVE = 2; + + + +//stats 0-31 are filled by the engine. +//they are for the 'fixed function' stuff, that works without requiring csqc. +//these stats need to be standardized amoung engines, so you're not allowed to mod them, so nur. +#define STAT_HEALTH 0 +#define STAT_WEAPONMODEL 2 //weapon model index, as evalutated by server code. +#define STAT_AMMO 3 +#define STAT_ARMOR 4 +#define STAT_WEAPONFRAME 5 +#define STAT_SHELLS 6 +#define STAT_NAILS 7 +#define STAT_ROCKETS 8 +#define STAT_CELLS 9 +#define STAT_ACTIVEWEAPON 10 //the one shown on the hud +#define STAT_ITEMS 15 +//stats 32 onwards are filled by the csqc. + + +#define FL_ONGROUND 1 + + + +enum +{ + VF_MIN = 1, + VF_MIN_X = 2, + VF_MIN_Y = 3, + VF_SIZE = 4, + VF_SIZE_X = 5, + VF_SIZE_Y = 6, + VF_VIEWPORT = 7, + VF_FOV = 8, + VF_FOVX = 9, + VF_FOVY = 10, + VF_ORIGIN = 11, + VF_ORIGIN_X = 12, + VF_ORIGIN_Y = 13, + VF_ORIGIN_Z = 14, + VF_ANGLES = 15, + VF_ANGLES_X = 16, + VF_ANGLES_Y = 17, + VF_ANGLES_Z = 18, + VF_DRAWWORLD = 19, + VF_DRAWENGINESBAR = 20, + VF_DRAWCROSSHAIR = 21 +}; + +enumflags { + RF_VIEWMODEL, + RF_EXTERNALMODEL, + RF_DEPTHHACK, + RF_ADDATIVE, + RF_USEAXIS +}; + diff --git a/quakec/csqctest/src/cs/csbuiltins.qc b/quakec/csqctest/src/cs/csbuiltins.qc new file mode 100644 index 000000000..b38475442 --- /dev/null +++ b/quakec/csqctest/src/cs/csbuiltins.qc @@ -0,0 +1,77 @@ + +//csqc only builtins. + +void() clearscene = #300; // (EXT_CSQC) +void(float mask) addentities = #301; // (EXT_CSQC) +void(entity ent) addentity = #302; // (EXT_CSQC) +float(float property, ...) setviewprop = #303; // (EXT_CSQC) +void() renderscene = #304; // (EXT_CSQC) + +void(vector org, float radius, vector lightcolours) adddynamiclight = #305; // (EXT_CSQC) + +//void(string texturename) R_BeginPolygon = #306; // (EXT_CSQC_???) +//void(vector org, vector texcoords, vector rgb, float alpha) R_PolygonVertex = #307; // (EXT_CSQC_???) +//void() R_EndPolygon = #308; // (EXT_CSQC_???) + +//maths stuff that uses the current view settings. +vector (vector v) unproject = #310; // (EXT_CSQC) +vector (vector v) project = #311; // (EXT_CSQC) + +//2d (immediate) operations +void(float width, vector pos1, vector pos2) drawline = #315; // (EXT_CSQC) +float(string name) iscachedpic = #316; // (EXT_CSQC) +string(string name, float trywad) precache_pic = #317; // (EXT_CSQC) +vector(string picname) draw_getimagesize = #318; // (EXT_CSQC) +void(string name) freepic = #319; // (EXT_CSQC) +float(vector position, float character, vector scale, vector rgb, float alpha, ...) drawcharacter = #320; // (EXT_CSQC, [EXT_CSQC_???]) +float(vector position, string text, vector scale, vector rgb, float alpha, ...) drawstring = #321; // (EXT_CSQC, [EXT_CSQC_???]) +float(vector position, string pic, vector size, vector rgb, float alpha, ...) drawpic = #322; // (EXT_CSQC, [EXT_CSQC_???]) +float(vector position, vector size, vector rgb, float alpha, ...) drawfill = #323; // (EXT_CSQC, [EXT_CSQC_???]) +void(float x, float y, float width, float height) drawsetcliparea = #324; // (EXT_CSQC_???) +void(void) drawresetcliparea = #325; // (EXT_CSQC_???) + +float(float stnum) getstatf = #330; // (EXT_CSQC) +float(float stnum) getstati = #331; // (EXT_CSQC) +float(float stnum, float first, float count) getstatbits = #331; // (EXT_CSQC) +string(float firststnum) getstats = #332; // (EXT_CSQC) +void(entity e, float mdlindex) setmodelindex = #333; // (EXT_CSQC) +string(float mdlindex) modelnameforindex = #334; // (EXT_CSQC) + +float(string effectname) particleeffectforname = #335; // (EXT_CSQC) +#ifdef WORKINDP +void(entity ent, float effectnum, vector start, vector end) trailparticles = #336; // (EXT_CSQC), +#else +void(float effectnum, entity ent, vector start, vector end) trailparticles = #336; // (EXT_CSQC), +#endif +void(float effectnum, vector origin, ...) pointparticles = #337; // (EXT_CSQC) + +void(string s, ...) cprint = #338; // (EXT_CSQC) +void(string s, ...) print = #339; // (EXT_CSQC) + +string(float keynum) keynumtostring = #340; // (EXT_CSQC) +float(string keyname) stringtokeynum = #341; // (EXT_CSQC) +string(float keynum) getkeybind = #342; // (EXT_CSQC) + +float(float framenum) getinputstate = #345; // (EXT_CSQC) +void(float sens) setsensitivityscaler = #346; // (EXT_CSQC) + +void() runstandardplayerphysics = #347; // (EXT_CSQC) + +string(float playernum, string keyname) getplayerkeyvalue = #348; // (EXT_CSQC) + +float() isdemo = #349; // (EXT_CSQC) +float() isserver = #350; // (EXT_CSQC) + +void(vector origin, vector forward, vector right, vector up) SetListener = #351; // (EXT_CSQC) +void(string cmdname) registercommand = #352; // (EXT_CSQC) +float(entity ent) wasfreed = #353; // (EXT_CSQC) (should be availabe on server too) + +//note that 'ReadEntity' is pretty hard to implement reliably. Modders should use a combination of ReadShort, and findfloat, and remember that it might not be known clientside (pvs culled or other reason) +float() readbyte = #360; // (EXT_CSQC) +float() readchar = #361; // (EXT_CSQC) +float() readshort = #362; // (EXT_CSQC) +float() readlong = #363; // (EXT_CSQC) +float() readcoord = #364; // (EXT_CSQC) +float() readangle = #365; // (EXT_CSQC) +string() readstring = #366; // (EXT_CSQC) +string() readfloat = #367; // (EXT_CSQC) \ No newline at end of file diff --git a/quakec/csqctest/src/cs/defs.qc b/quakec/csqctest/src/cs/defs.qc new file mode 100644 index 000000000..0434d9bf3 --- /dev/null +++ b/quakec/csqctest/src/cs/defs.qc @@ -0,0 +1,20 @@ +float chasecam; +entity player_local; + +.entity headent; +.entity torsoent; +.entity legsent; +.entity weaponent; +.float modelnum; +.float animnum; +.float framechangetime; +.float lerptime; + +.float sveffects; //lower 4 is weapon, next is nopred, upper 3 is powerups +#define SVE_INVIS 128 +#define SVE_GOD 64 +#define SVE_QUAD 32 +#define SVE_NOPRED 16 +#define SVE_WEAPONSMASK 15 + +.float gibbable; \ No newline at end of file diff --git a/quakec/csqctest/src/cs/entrypoints.qc b/quakec/csqctest/src/cs/entrypoints.qc new file mode 100644 index 000000000..9a76db85c --- /dev/null +++ b/quakec/csqctest/src/cs/entrypoints.qc @@ -0,0 +1,302 @@ + +void(float isnew) RefreshPlayer; + +float(string centertext) centerprinted = +{ +//warning! +//centertext is a temporary string! +//warning! + + return false; //we don't want to handle it, let the engine do it. +}; + +.float classnum; + +void(float isnew) CSQC_Ent_Update = +{ + local float classtype; + local var void(float isnew) fnc; + + classtype = readbyte(); + +//remove if the class changed. + if (self.classnum != classtype) + { + if (self.removefunc) + self.removefunc(); + isnew = true; + self.classnum = classtype; + } + + fnc = ParseEntityClass[classtype]; + if (!fnc) + error("Unrecognised entity class: Your csqc needs updating"); + fnc(isnew); + +// if (isnew) +// print("csqc ", self.model, " updated at ", vtos(self.origin), "\n"); +}; + +void() regcommands = +{ + registercommand("tetris"); + registercommand("skinchooser"); + registercommand("randomskin"); + registercommand("test"); + registercommand("+showscores"); + registercommand("-showscores"); + registercommand("+showteamscores"); + registercommand("-showteamscores"); + + registercommand("osgk"); + registercommand("cin_command"); + registercommand("cin_resize"); + registercommand("cin_mousemove"); + registercommand("cin_keypress"); +}; + +float(string str) CSQC_ConsoleCommand = +{ + local float args; + args = tokenize(str); + switch(argv(0)) + { + case "tetris": + Menu_Tetris(); + break; + case "skinchooser": + Menu_SkinChooser(); + break; + case "randomskin": + SelectRandomSkin(); + break; + case "test": + test(); + break; + case "+showscores": + case "-showscores": + case "+showteamscores": + case "-showteamscores": + break; + case "osgk": + Menu_OSGK(argv(1)); + break; + case "cin_command": + gecko_navigate(argv(1), argv(2)); + break; + case "cin_keypress": + gecko_keyevent(argv(1), stof(argv(2)), 2); + break; + case "cin_resize": + gecko_resize(argv(1), stof(argv(2)), stof(argv(3))); + break; + case "cin_mousemove": + gecko_mousemove(argv(1), stof(argv(2)), stof(argv(3))); + break; + default: + return false; + } + return true; +}; + +void() CSQC_Ent_Remove = //the ent disappeared on the server. +{ + if (self == player_local) + print("WARNING: Player disappeared!\n"); + +// print("csqc ", ftos(self.modelindex), "(", self.model, ") removed\n"); + + if (self.removefunc) + self.removefunc(); + remove(self); +}; + +entity viewentity; +//note that a better way of animating weapon firing would be as a response to an event, or as a clientside predicted thing. +void(entity ve) DoThatViewModelThing = +{ + float newframe, newmodel; + + newframe = getstati(STAT_WEAPONFRAME); + newmodel = getstati(STAT_WEAPONMODEL); + + if (newmodel != ve.modelindex) + { //changed entirly. + ve.modelindex = newmodel; + ve.frame2 = ve.frame = newframe; + ve.lerptime = time; + } + else if (newframe != ve.frame) + { + ve.frame2 = ve.frame; + ve.frame = newframe; + ve.lerptime = time; + } + ve.lerpfrac = 1-(time-ve.lerptime)*10; + + ve.origin = '0 0 0'; + ve.angles = '0 0 0'; + ve.angles_x *= -1; +}; + +void() drawloadingscreen = +{ +//work in progress here +// drawfill('0 0', '320 240', '1 1 1', 1); +// drawstring('0 0', "loading screen", '1 1', '1 1 1', 1); +}; + +void() CSQC_Init = +{ + //set some cvars to their defaults, and create them at the same time + if (cvar_string("cg_giblevel") == "") localcmd("set cg_giblevel 1\n"); + if (cvar_string("cg_thirdPerson") == "") localcmd("set cg_thirdPerson 0\n"); + if (cvar_string("cg_forceskin") == "") localcmd("set cg_forceskin \"\"\n"); + if (cvar_string("cg_hudtype") == "") localcmd("set cg_hudtype 0\n"); + if (cvar_string("cg_nopred") == "") localcmd("set cg_nopred 0\n"); + if (cvar_string("v_viewheight") == "") localcmd("set v_viewheight 0\n");//normally an engine cvar in quakeworld. + if (cvar_string("cg_nostep") == "") localcmd("set cg_nostep 0\n"); + if (cvar_string("cg_noerror") == "") localcmd("set cg_noerror 0\n"); + if (cvar_string("cg_noselfsounds") == "") localcmd("set cg_noselfsounds 0\n"); + if (cvar_string("cg_noselfjumpsound") == "") localcmd("set cg_noselfjumpsound 0\n"); + + viewentity = spawn(); + viewentity.renderflags = RF_VIEWMODEL; + + drawloadingscreen (); + + ResetPlayerPrediction(); + regcommands(); +}; + +void(entity ent) CSQC_DrawViewModel = +{ + if (player_local.sveffects & SVE_INVIS) + ent.forceshader = shaderforname("powerups/invisibility"); + else + ent.forceshader = 0; + + ent.fatness = 0; + DoThatViewModelThing(ent); + addentity(ent); + if (player_local.sveffects & SVE_QUAD) + { + ent.fatness = -2; + ent.forceshader = shaderforname("powerups/quad"); + addentity(ent); + } + if (player_local.sveffects & SVE_GOD) + { + ent.fatness = -2.8; + ent.forceshader = shaderforname("powerups/regen"); + addentity(ent); + } +} + +void(float isnew) CSQC_Delta_Update = +{ + self.drawmask = MASK_NORMAL; + setmodelindex(self, self.modelindex); +// if (isnew) +// { +// print("delt ", self.model, " updated at ", vtos(self.origin), "\n"); +// } + + if (self.entnum <= maxclients) + RefreshPlayer(isnew); + else if (self.colormap) + self.modelindex = 0; //don't show dead bodies, we do dying ourselves. +}; + +//a bit of fun +void() CSQC_Input_Frame = +{ +/* if (input_buttons == 1) + input_buttons = 2; + else if (input_buttons == 2) + input_buttons = 1;*/ +}; + +void() CSQC_Delta_Remove = +{ + if (self == player_local) + player_local = world; + +// print("delt ", ftos(self.modelindex), "(", self.model, ") removed\n"); + if (self.removefunc) + self.removefunc(); + remove(self); +}; + +void(float flags, float simtime) readserverentitystate = #369; +#define RSES_AUTOLERP 0 +#define RSES_NOLERP 1 +#define RSES_AUTOROTATE 0 +#define RSES_NOROTATE 2 +#define RSES_AUTOTRAILS 0 +#define RSES_NOTRAILS 4 +#define RSES_AUTOLIGHTS 0 +#define RSES_NOLIGHTS 8 + +void(float width, float height, float do2d) CSQC_UpdateView = +{ + float lagged; + float i; + float hudtype = cvar("cg_hudtype"); + + chasecam = cvar("cg_thirdPerson"); + if (getstati(STAT_HEALTH) <= 0) + chasecam = 1; + +#ifndef WORKINDP + readserverentitystate(RSES_AUTOLERP|RSES_AUTOROTATE|RSES_AUTOTRAILS|RSES_AUTOLIGHTS, 0); +#endif + + clearscene(); + + if (hudtype) + { + setviewprop(VF_DRAWENGINESBAR, 0); + } + else + { + setviewprop(VF_DRAWENGINESBAR, 1); + } + setviewprop(VF_DRAWCROSSHAIR, 1); + + if (player_local) + { + UpdateLocalMovement(); + + setviewprop(VF_ORIGIN, vieworg); + setviewprop(VF_ANGLES, view_angles); + + makevectors(view_angles); + SetListener(vieworg, v_forward, v_right, v_up); + + if (!chasecam) + CSQC_DrawViewModel(viewentity); + } + + //force fullscreen views. + setviewprop(VF_MIN, '0 0 0'); + setviewprop(VF_SIZE_X, width); + setviewprop(VF_SIZE_Y, height); + +#ifdef WORKINDP + addentities(MASK_NORMAL|MASK_ENGINE); +#else + addentities(MASK_NORMAL); +#endif + + renderscene(); + + if (do2d) + { + if (hudtype) + Hud_Draw(hudtype, width, height); + + Menu_Think(); + } +}; + diff --git a/quakec/csqctest/src/cs/fun/osgk.qc b/quakec/csqctest/src/cs/fun/osgk.qc new file mode 100644 index 000000000..d12fc8439 --- /dev/null +++ b/quakec/csqctest/src/cs/fun/osgk.qc @@ -0,0 +1,40 @@ +string osgkname; + +void(float event, float button, float mousex, float mousey) OSGKMenuEvent = +{ + float f; + string str; + if (event == ME_DRAW) + { + //nothing. + return; + } + + if (event == ME_MOUSEMOVE) + { + gecko_mousemove(osgkname, mousex/640, mousey/480); + return; + } + if (event == ME_KEYDOWN) + { + if (button == K_ESCAPE) + { + Menu_Main(); + return; + } + gecko_keyevent(osgkname, button, 2); + } +/* if (event == ME_KEYUP) + { + gecko_keyevent(osgkname, button, 1); + } +*/}; + + +void(string posgkname) Menu_OSGK +{ + if (osgkname) + strunzone(osgkname); + osgkname = strzone(posgkname); + Menu_Activate(OSGKMenuEvent); +}; diff --git a/quakec/csqctest/src/cs/fun/skinchooser.qc b/quakec/csqctest/src/cs/fun/skinchooser.qc new file mode 100644 index 000000000..cecacebad --- /dev/null +++ b/quakec/csqctest/src/cs/fun/skinchooser.qc @@ -0,0 +1,178 @@ +var float c_modellist = -1; +var float c_skinlist = -1; + +float c_modelnum; +float c_skinnum; + +string(float num) ModelForNum = +{ + string str; + float slashpos; + str = search_getfilename(c_modellist, num); +#ifdef WORKINDP + str = substring(str, 15, strlen(str)-15); // models/players/ +#else + str = substring(str, 15, -1); // models/players/ +#endif + slashpos = strstrofs(str, "/"); + return substring(str, 0, slashpos); +} +string(float num) SkinForNum = +{ + string str; + float slashpos; + str = search_getfilename(c_skinlist, num); +#ifdef WORKINDP + str = substring(str, 15, strlen(str)-15); // models/players/ +#else + str = substring(str, 15, -1); // models/players/ +#endif + slashpos = strstrofs(str, "/"); +#ifdef WORKINDP + return substring(str, slashpos+7, strlen(str)-slashpos-7-5); // /upper_ .skin-1 +#else + return substring(str, slashpos+7, -6); // /upper_ .skin-1 +#endif +} + +void() CheckSkinNumber = +{ + if (c_skinnum < 0) + c_skinnum = search_getsize(c_skinlist)-1; + else if (c_skinnum >= search_getsize(c_skinlist)) + c_skinnum = 0; +}; + +void() FindPlayerSkins = +{ + string str; + + if (c_modelnum < 0) + c_modelnum = search_getsize(c_modellist)-1; + else if (c_modelnum >= search_getsize(c_modellist)) + c_modelnum = 0; + + str = ModelForNum(c_modelnum); + + if (c_skinlist >= 0) + search_end(c_skinlist); + c_skinlist = search_begin(strcat("models/players/", str, "/upper_*.skin"), true, true); + + if (c_skinlist < 0) + { + print("You have no skins available\n"); + return; + } + + for (c_skinnum = search_getsize(c_skinlist)-1; c_skinnum>0; c_skinnum--) + { + if (SkinForNum(c_skinnum) == "default") + break; //we found the default, use it as default. :p + } +}; + +void() FindPlayerModels = +{ + if (c_modellist >= 0) + search_end(c_modellist); + c_modellist = search_begin("models/players/*/animation.cfg", true, true); + c_modelnum = 0; + c_skinnum = 0; + + FindPlayerSkins(); +}; + +void() DrawSkinChooser = +{ + string modname; + string skinname; + modname = ModelForNum(c_modelnum); + skinname = SkinForNum(c_skinnum); + cprint(modname, "/", skinname); + + chasecam = true; +} + +void(float event, float button, float mousex, float mousey) SkinChooserMenuEvent = +{ + float f; + string str; + if (event == ME_DRAW) + { + DrawSkinChooser(); + return; + } + + if (event == ME_MOUSEMOVE) + { + return; + } + if (event == ME_KEYDOWN) + { + if (button == K_ESCAPE) + { + cprint(""); + Menu_Main(); + + if (c_skinlist >= 0) + search_end(c_skinlist); + if (c_modellist >= 0) + search_end(c_modellist); + return; + } + if (button == K_ENTER) + { + str = SkinForNum(c_skinnum); + str = strcat(ModelForNum(c_modelnum), "/", str); + localcmd("skin "); + localcmd(str); + localcmd("\n"); + } + if (button == K_LEFTARROW) + { + c_skinnum--; + CheckSkinNumber(); + } + if (button == K_RIGHTARROW) + { + c_skinnum++; + CheckSkinNumber(); + } + if (button == K_UPARROW) + { + c_modelnum--; + FindPlayerSkins(); + } + if (button == K_DOWNARROW) + { + c_modelnum++; + FindPlayerSkins(); + } + } +}; + + +void() Menu_SkinChooser +{ + c_modellist = -1; + c_skinlist = -1; + FindPlayerModels(); + + Menu_Activate(SkinChooserMenuEvent); +}; + +void() SelectRandomSkin = +{ + local string str; + + FindPlayerModels(); + c_modelnum = floor(random()*search_getsize(c_modellist)); + FindPlayerSkins(); + c_skinnum = floor(random()*search_getsize(c_skinlist)); + + str = SkinForNum(c_skinnum); + str = strcat(ModelForNum(c_modelnum), "/", str); + localcmd("skin "); + localcmd(str); + localcmd("\n"); +}; diff --git a/quakec/csqctest/src/cs/fun/tetris.qc b/quakec/csqctest/src/cs/fun/tetris.qc new file mode 100644 index 000000000..1eeecd470 --- /dev/null +++ b/quakec/csqctest/src/cs/fun/tetris.qc @@ -0,0 +1,671 @@ +/* +Quake tetris, origionally created by FrikaC + +Ported to csqc by Spike, primarily for testing in a fun way. +*/ + +vector tet_org; + +float tetris_on, tet_time, tet_autodown, tet_old_keys, tet_keys; +vector piece_pos; +float piece_type, next_piece, tet_score, tet_lines; + +var float tet_high_score = 0; + +float TET_LINES = 20; +float TET_WIDTH = 10; +//character values +float TET_BORDER = 132; +float TET_BLOCKS = 132; // +1 = first color, +2, +3; +float TET_SPACE = 32; // blankness + + + +float TETKEY_UP = 1; +float TETKEY_DOWN = 2; +float TETKEY_LEFT = 4; +float TETKEY_RIGHT = 8; +float TETKEY_ROTLEFT = 16; +float TETKEY_ROTRIGHT = 32; +float KEYS_IMMEDIATE = 60;//32 + 16 + 8 + 4; + +float PIECES = 7; + +float line[20]; + + +string printline; + +/* +********************************* + +Library Functions + +********************************* +*/ +void (string snd) tetsnd = +{ + localcmd("play "); + localcmd(snd); + localcmd("\n"); + +}; + +float () Tetris_Level = +{ + return floor(tet_lines / 20) + 1; +}; + +#define SetLine(l,v) line[l] = v +#define GetLine(l) line[l] + +float(float x, float dat) GetXBlock = +{ + if (x == 0) + return dat & 3; + else if (x == 1) + return (dat & 12) / 4; + else if (x == 2) + return (dat & 48) / 16; + else if (x == 3) + return (dat & 192) / 64; + else if (x == 4) + return (dat & 768) / 256; + else if (x == 5) + return (dat & 3072) / 1024; + else if (x == 6) + return (dat & 12288) / 4096; + else if (x == 7) + return (dat & 49152) / 16384; + else if (x == 8) + return (dat & 196608) / 65536; + else if (x == 9) + return (dat & 786432) / 262144; + else + return 0; +}; + +float(float x, float dat, float new) SetXBlock = +{ + if (x == 0) + return (dat - (dat & 3)) | new; + else if (x == 1) + return (dat - (dat & 12)) | (new*4); + else if (x == 2) + return (dat - (dat & 48)) | (new*16); + else if (x == 3) + return (dat - (dat & 192)) | (new*64); + else if (x == 4) + return (dat - (dat & 768)) | (new*256); + else if (x == 5) + return (dat - (dat & 3072)) | (new*1024); + else if (x == 6) + return (dat - (dat & 12288)) | (new*4096); + else if (x == 7) + return (dat - (dat & 49152)) | (new*16384); + else if (x == 8) + return (dat - (dat & 196608)) | (new*65536); + else if (x == 9) + return (dat - (dat & 786432)) | (new*262144); + else + return dat; +}; + + +float(float x, float y) GetSquare = +{ + return GetXBlock(x, GetLine(y)); +}; + +void (float x, float y, float val) SetSquare = +{ + float dat; + + dat = GetLine(y); + dat = SetXBlock(x, dat, val & 3); + SetLine(y, dat); +}; + + + +vector(float pc) PieceShape = +{ +// third value is width? + +/* +1 = +## +## +*/ + if (pc == 1) + return '5 5 2'; // 1 * 4 + 1 * 16 +/* +2 = + +#### +*/ + else if (pc == 2) + return '85 0 4'; + +/* +3 = + +### +# +*/ + else if (pc == 3) + return '21 1 3'; +/* +4 = + +# +### +*/ + else if (pc == 4) + return '1 21 3'; +/* +5 = +## + ## +*/ + else if (pc == 5) + return '5 20 3'; + +/* +6 = + ## +## +*/ + else if (pc == 6) + return '20 5 3'; + +/* +7 = + # +### +*/ + else if (pc == 7) + return '4 21 3'; + + + else + return '0 0 0'; + +} + +// do x 1..4 and y 1..4 in case of rotation +float(float x, float y, float rot, float pc) PieceMetric = +{ + float t; + vector piece_dat; + float wid; + piece_dat = PieceShape(pc); + wid = piece_dat_z; + + // return bits of a piece + if (rot == 1) // 90 degrees + { + t = y; + y = x; + x = wid - t; + } +// else if (rot == 2)//180 +// { +// x = wid-1 - x; +// y = 3 - y; +// } +// else if (rot == 3) // 270 +// { +// t = y; +// y = wid-1 - x; +// x = t; +// } +print(ftos(x)); +print(", "); +print(ftos(y)); +print("\n"); + if (x < 0 || y < 0 || x >= 4 || y >= 4) + return 0; + if (y == 0) + return GetXBlock(x, piece_dat_x); // first row + else if (y == 1) + return GetXBlock(x, piece_dat_y); // second row + else + return 0; // illegal parms +}; +/* +********************************* + +Draw + +********************************* +*/ + + +/* some prydon gate functions to make life easier.... + +somewhat modified because we don't need all the fanciness Prydon Gate is capable of + +*/ + +void(float c1, float c2, float c3, float c4, float c5, float c6) p6 = +{ + printline = strcat(printline, chr2str(c1, c2, c3, c4, c5, c6)); +}; + +float(float num, float dig) pnum = +{ + local string str; + str = ftos(num); + printline = strcat(printline, str); + num = strlen(str); + while(num < dig) + { + printline = strcat(printline, " "); + num++; + } + return 6; +}; + +void (float ln) DrawLine = +{ + float x, d; + printline = strcat(printline, chr2str(TET_BORDER)); + + for (x = 0; x < TET_WIDTH; x = x + 1) + { + d = GetSquare(x, ln); + if (d) + printline = strcat(printline, chr2str(TET_BLOCKS + d)); + else + printline = strcat(printline, chr2str(TET_SPACE)); + } + printline = strcat(printline, chr2str(TET_BORDER)); +} + +void (float pc, float ln) DrawPiece = +{ + float x, d, piece_ln, color; + vector piece_dat; + color = pc & 3; + if (color == 0) // 4 + color = 1; + printline = strcat(printline, chr2str(TET_SPACE)); + + piece_dat = PieceShape(pc); + if (ln == 1) + piece_ln = piece_dat_x; + else + piece_ln = piece_dat_y; + for (x = 0; x < 4; x = x + 1) + { + d = GetXBlock(x, piece_ln) * color; + if (d) + printline = strcat(printline, chr2str(TET_BLOCKS + d)); + else + printline = strcat(printline, chr2str(TET_SPACE)); + } + printline = strcat(printline, chr2str(TET_SPACE)); +} +void() Draw_Tetris = +{ + float i; + + // decoration + for (i = 0; i < (TET_WIDTH + 2); i = i + 1) + printline = strcat(printline, chr2str(TET_BORDER)); + p6(' ', ' ', ' ', ' ', ' ', ' '); + printline = strcat(printline, "\n"); + for (i = 0; i < TET_LINES; i = i + 1) + { + if (tetris_on == 2 && i == 11) + { + p6(TET_BORDER, 'G', 'A', 'M', 'E', ' '); + p6('O', 'V', 'E', 'R', ' ', TET_BORDER); + } + else + DrawLine(i); + if (i == 1) + p6(' ', 'N', 'E', 'X', 'T', ' '); + else if (i == 3) + DrawPiece(next_piece, 1); + else if (i == 4) + DrawPiece(next_piece, 2); + else if (i == 6) + p6(' ', 'L', 'I', 'N', 'E', 'S'); + else if (i == 7) + pnum(tet_lines, 6); + else if (i == 9) + p6(' ', 'S', 'C', 'O', 'R', 'E'); + else if (i == 10) + pnum(tet_score, 6); + else if (i == 12) + p6(' ', 'H', 'I', 'G', 'H', ' '); + else if (i == 13) + p6(' ', 'S', 'C', 'O', 'R', 'E'); + else if (i == 14) + pnum(tet_high_score, 6); + else if (i == 16) + p6(' ', 'L', 'E', 'V', 'E', 'L'); + else if (i == 17) + pnum(Tetris_Level(), 6); + else + p6(' ', ' ', ' ', ' ', ' ', ' '); + printline = strcat(printline, "\n"); + } + // decoration + + for (i = 0; i < (TET_WIDTH + 2); i = i + 1) + printline = strcat(printline, chr2str(TET_BORDER)); + p6(' ', ' ', ' ', ' ', ' ', ' '); + + + printline = strcat(printline, "\n"); + + cprint(printline); + printline = ""; +} +/* +********************************* + +Game Functions + +********************************* +*/ + +// reset the game +void() ResetTetris = +{ + float i; + + for (i=0; i tet_high_score) + tet_high_score = tet_score; +}; +float CheckMetrics(float piece, float orgx, float orgy, float rot) = +{ + // check to see if the piece, if moved to the locations will overlap + + float x, y; + + orgx = orgx; + orgy = orgy; + + for (y = 0; y < 4; y = y + 1) + { + for (x = 0; x < 4; x = x + 1) + { + if (PieceMetric(x, y, rot, piece)) + { + if (GetSquare(x + orgx, y + orgy)) + return FALSE; // uhoh, gonna hit something. + if (x+orgx<0 || x+orgx >= TET_WIDTH || y+orgy<0 || y+orgy>= TET_LINES) + return FALSE; // ouside the level + } + } + } + return TRUE; +} + +void ClearPiece(float piece, float orgx, float orgy, float rot) = +{ + + float x, y; + orgx = orgx; + orgy = orgy; + + for (y = 0; y < 4; y = y + 1) + { + for (x = 0; x < 4; x = x + 1) + { + if (PieceMetric(x, y, rot, piece)) + { + SetSquare(x + orgx, y + orgy, 0); + } + } + } +} +void CementPiece(float piece, float orgx, float orgy, float rot) = +{ + float color; + float x, y; + + orgx = orgx; + orgy = orgy; + + color = piece & 3; + if (color == 0) // 4 + color = 1; + + for (y = 0; y < 4; y = y + 1) + { + for (x = 0; x < 4; x = x + 1) + { + if (PieceMetric(x, y, rot, piece)) + { + SetSquare(x + orgx, y + orgy, color); + } + } + } +} + +float LINE_LOW = 349525; +float LINE_HIGH = 699050; // above number times 2 + +void() CompletedLines = +{ + float y, cleared, ln; + + cleared = 0; + y = TET_LINES-1; + while(y >= 0) + { + ln = GetLine(y); + if (((ln & LINE_LOW) | ((ln & LINE_HIGH)/2)) == LINE_LOW) + cleared = cleared + 1; + else + y = y - 1; + ln = GetLine(y - cleared); + SetLine(y, ln); + } + if (cleared == 4) + tetsnd("tetris"); + else if (cleared) + tetsnd("tetline"); + else + tetsnd("tetland"); + tet_lines = tet_lines + cleared; + TetAddScore(cleared * cleared * 10); +}; + +void(float keys) HandleGame = +{ + vector check_pos, piece_data; + float brand_new, nudge, i; + brand_new = 0; + nudge = 0; + if ((tet_time > time) && !(keys & KEYS_IMMEDIATE)) + return; + tet_time = time + 0.1; + // first off, we need to see if we need a new piece + + if (tetris_on==2) + return; + + if (piece_type == 0) + { + piece_pos = '5 1 0'; // that's about middle top, we count from 1 ARGH + if (next_piece) + piece_type = next_piece; + else + piece_type = RandomPiece(); + next_piece = RandomPiece(); + keys = 0; // no movement first frame + tet_autodown = time + 1; + brand_new = 1; + } + else + ClearPiece(piece_type, piece_pos_x, piece_pos_y, piece_pos_z); + + // next we need to check the piece metrics against what's on the level + // based on the key order + + check_pos = piece_pos; + + if (keys & TETKEY_RIGHT) + { + check_pos_x = check_pos_x + 1; + tetsnd("tetmove"); + } + else if (keys & TETKEY_LEFT) + { + check_pos_x = check_pos_x - 1; + tetsnd("tetmove"); + } + else if (keys & TETKEY_ROTRIGHT) + { + check_pos_z = check_pos_z + 1; + // nudge stuff + piece_data = PieceShape(piece_type); + nudge = piece_data_z - 2; + tetsnd("tetrot"); + } + else if (keys & TETKEY_ROTLEFT) + { + check_pos_z = check_pos_z - 1; + // nudge stuff + piece_data = PieceShape(piece_type); + nudge = piece_data_z - 2; + tetsnd("tetrot"); + } + // bounds check + if (check_pos_z > 3) + check_pos_z = 0; + else if (check_pos_z < 0) + check_pos_z = 3; + + // reality check + // more nudge stuff + if (CheckMetrics(piece_type, check_pos_x, check_pos_y, check_pos_z)) + piece_pos = check_pos; + else if (brand_new) + { + tetris_on = 2; + return; + } + else if (nudge) + { + for (i = nudge; i >= (0-nudge); i = i - 1) + { + if (CheckMetrics(piece_type, check_pos_x + i, check_pos_y, check_pos_z)) + { + piece_pos = check_pos + '1 0 0' * i; + break; + } + } + } + check_pos = piece_pos; + if (keys & TETKEY_DOWN) + check_pos_y = check_pos_y + 1; + else if (tet_autodown < time) + { + check_pos_y = check_pos_y + 1; + tet_autodown = time + 1 / Tetris_Level(); + } + if (CheckMetrics(piece_type, check_pos_x, check_pos_y, check_pos_z)) + piece_pos = check_pos; + else + { + CementPiece(piece_type, piece_pos_x, piece_pos_y, piece_pos_z); + TetAddScore(1); + CompletedLines(); + piece_type = 0; + return; + } + CementPiece(piece_type, piece_pos_x, piece_pos_y, piece_pos_z); +}; + +/* +********************************* + +Important Linking Into Quake stuff + +********************************* +*/ + +void(float event, float button, float mousex, float mousey) TetrisMenuEvent = +{ + local float key; + + if (event == ME_DRAW) + { + HandleGame(tet_keys); + Draw_Tetris(); + return; + } + + if (event == ME_MOUSEMOVE) //0 is a mouse move + return; + + if (button == K_ESCAPE && event == ME_KEYDOWN) + { + cprint(""); + Menu_Main(); + return; + } + if (button == K_LEFTARROW) + key = TETKEY_LEFT; + if (button == K_RIGHTARROW) + key = TETKEY_RIGHT; + if (button == K_UPARROW) + key = TETKEY_ROTRIGHT; + if (button == K_CTRL) + key = TETKEY_ROTLEFT; + if (button == K_SPACE) + key = TETKEY_DOWN; + if (button == K_DOWNARROW) + key = TETKEY_DOWN; + + if (!key) //we didn't recognise it. + return; + + if (event == ME_KEYDOWN) + tet_keys = tet_keys | key; + if (event == ME_KEYUP) + tet_keys -= tet_keys&key; + + HandleGame(tet_keys); + + tet_keys -= tet_keys & KEYS_IMMEDIATE; + tet_old_keys = tet_keys; +}; + +void() Menu_Tetris = +{ + tetris_on = 1; + ResetTetris(); + Menu_Activate(TetrisMenuEvent); + MenuEventFunc = TetrisMenuEvent; +}; diff --git a/quakec/csqctest/src/cs/hud.qc b/quakec/csqctest/src/cs/hud.qc new file mode 100644 index 000000000..d0b3efeb7 --- /dev/null +++ b/quakec/csqctest/src/cs/hud.qc @@ -0,0 +1,347 @@ + +string number[10] = { + "num_0", + "num_1", + "num_2", + "num_3", + "num_4", + "num_5", + "num_6", + "num_7", + "num_8", + "num_9" +}; +string anumber[10] = { + "anum_0", + "anum_1", + "anum_2", + "anum_3", + "anum_4", + "anum_5", + "anum_6", + "anum_7", + "anum_8", + "anum_9" +}; +void Hud_Init(void) +{ + float i; + precache_pic("sbar", true); + for (i = 0; i < 10; i++) + { + precache_pic(number[i], true); + precache_pic(anumber[i], true); + } +}; + +vector screensize; +float items, items2; + +void Hud_DrawLargeValue(vector pos, float value, float threshhold) +{ + float c; + float len; + string s; + if (value < 0) + value = 0; //hrm + if (value>999) + value = 999; + + s = ftos(floor(value)); + len = strlen(s); + + pos_x += 24 * (3-len); + + + if (value <= threshhold) + { //use alternate (red) numbers + + while(len>0) + { + len--; + c = str2chr(s, len); + + drawpic(pos+len * '24 0 0', anumber[c-'0'], '24 24 0', '1 1 1', 1, 0); + } + } + else + { //use normal numbers + + while(len>0) + { + len--; + c = str2chr(s, len); + + drawpic(pos+len * '24 0 0', number[c-'0'], '24 24 0', '1 1 1', 1, 0); + } + } +}; + +void Hud_DrawAmmoCount(float type, vector pos, float drawback) +{ + string s; + float value; + float len; + float c; + value = getstati(STAT_SHELLS+type); + if (value < 0) + value = 0; //hrm + if (value>999) + value = 999; + + s = ftos(floor(value)); + len = strlen(s); + + pos_x += 8 * (3-len); + while(len>0) + { + len--; + c = str2chr(s, len); + drawcharacter(pos+len * '8 0 0', (18-'0') + c, '8 8 0', '1 1 1', 1, 0); + } +}; + +string weaponnames[7] = { + "inv_shotgun", + "inv_sshotgun", + "inv_nailgun", + "inv_sshotgun", + "inv_rlaunch", + "inv_srlaunch", + "inv_lightng" +}; +void Hud_DrawWeapon(float num, vector pos) +{ + drawpic(pos, weaponnames[num], '24 16 0', '1 1 1', 1, 0); +}; +void Hud_DrawWeaponWide(float num, vector pos) //for LG +{ + drawpic(pos, weaponnames[num], '48 16 0', '1 1 1', 1, 0); +}; + +void Hud_DrawSBar(void) +{ + vector sbar; + sbar = screensize_y * ' 0 1 0' - '0 24 0'; + drawpic(sbar, "sbar", '320 24 0', '1 1 1', 0.333, 0); + + if (items & IT_INVULNERABILITY) + { + drawpic(sbar, "disc", '24 24 0', '1 1 1', 1, 0); + Hud_DrawLargeValue(sbar+'24 0 0', 999, 25); + } + else + { + Hud_DrawLargeValue(sbar+'24 0 0', getstati(STAT_ARMOR), 25); + if (items & IT_ARMOR3) + drawpic(sbar, "sb_armor3", '24 24 0', '1 1 1', 1, 0); + else if (items & IT_ARMOR2) + drawpic(sbar, "sb_armor2", '24 24 0', '1 1 1', 1, 0); + else if (items & IT_ARMOR1) + drawpic(sbar, "sb_armor1", '24 24 0', '1 1 1', 1, 0); + } + + Hud_DrawLargeValue(sbar+'136 0 0', getstati(STAT_HEALTH), 25); + + if (items & IT_SHELLS) + drawpic(sbar+'224 0 0', "sb_shells", '24 24 0', '1 1 1', 1, 0); + else if (items & IT_NAILS) + drawpic(sbar+'224 0 0', "sb_nails", '24 24 0', '1 1 1', 1, 0); + else if (items & IT_ROCKETS) + drawpic(sbar+'224 0 0', "sb_rocket", '24 24 0', '1 1 1', 1, 0); + else if (items & IT_CELLS) + drawpic(sbar+'224 0 0', "sb_cells", '24 24 0', '1 1 1', 1, 0); + Hud_DrawLargeValue(sbar+'248 0 0', getstati(STAT_AMMO), 10); +}; + +void Hud_DrawIBar(void) +{ + vector pos; + pos= screensize_y * ' 0 1 0' - '0 48 0'; + drawpic(pos, "ibar", '320 24 0', '1 1 1', 0.333, 0); + + if (items & IT_SHOTGUN) + Hud_DrawWeapon(0, pos+'0 8 0'); + if (items & IT_SUPER_SHOTGUN) + Hud_DrawWeapon(1, pos+'24 8 0'); + if (items & IT_NAILGUN) + Hud_DrawWeapon(2, pos+'48 8 0'); + if (items & IT_SUPER_NAILGUN) + Hud_DrawWeapon(3, pos+'72 8 0'); + if (items & IT_GRENADE_LAUNCHER) + Hud_DrawWeapon(4, pos+'96 8 0'); + if (items & IT_ROCKET_LAUNCHER) + Hud_DrawWeapon(5, pos+'120 8 0'); + if (items & IT_LIGHTNING) + Hud_DrawWeaponWide(6, pos+'144 8 0'); + + Hud_DrawAmmoCount(0, pos + '6 0 0', false); + Hud_DrawAmmoCount(1, pos + '54 0 0', false); + Hud_DrawAmmoCount(2, pos + '102 0 0', false); + Hud_DrawAmmoCount(3, pos + '150 0 0', false); + + if (items & IT_KEY1) + drawpic(pos+'192 8 0', "sb_key1", '16 16 0', '1 1 1', 1, 0); + if (items & IT_KEY2) + drawpic(pos+'208 8 0', "sb_key2", '16 16 0', '1 1 1', 1, 0); + + if (items & IT_INVISIBILITY) + drawpic(pos+'224 8 0', "sb_invis", '16 16 0', '1 1 1', 1, 0); + if (items & IT_INVULNERABILITY) + drawpic(pos+'240 8 0', "sb_invuln", '16 16 0', '1 1 1', 1, 0); + if (items & IT_SUIT) + drawpic(pos+'256 8 0', "sb_suit", '16 16 0', '1 1 1', 1, 0); + if (items & IT_QUAD) + drawpic(pos+'272 8 0', "sb_quad", '16 16 0', '1 1 1', 1, 0); + + if (items2 & 32) + drawpic(pos+'288 8 0', "sb_sigil1", '8 16 0', '1 1 1', 1, 0); + if (items2 & 64) + drawpic(pos+'296 8 0', "sb_sigil2", '8 16 0', '1 1 1', 1, 0); + if (items2 & 128) + drawpic(pos+'304 8 0', "sb_sigil3", '8 16 0', '1 1 1', 1, 0); + if (items2 & 256) + drawpic(pos+'312 8 0', "sb_sigil4", '8 16 0', '1 1 1', 1, 0); +}; + +string q3numbers[10] = +{ + "gfx/2d/numbers/zero_32b.tga", + "gfx/2d/numbers/one_32b.tga", + "gfx/2d/numbers/two_32b.tga", + "gfx/2d/numbers/three_32b.tga", + "gfx/2d/numbers/four_32b.tga", + "gfx/2d/numbers/five_32b.tga", + "gfx/2d/numbers/six_32b.tga", + "gfx/2d/numbers/seven_32b.tga", + "gfx/2d/numbers/eight_32b.tga", + "gfx/2d/numbers/nine_32b.tga" +}; +void Hud_DrawQ3Number(vector pos, float value, vector colours) +{ + float c; + float len; + string s; + if (value < 0) + value = 0; //hrm + if (value>999) + value = 999; + + s = ftos(floor(value)); + len = strlen(s); + + pos_x += 24 * (3-len); + + while(len>0) + { + len--; + c = str2chr(s, len); + + drawpic(pos+len * '24 0 0', q3numbers[c-'0'], '24 24 0', colours, 1, 0); + } +}; + +entity hud3ditem; + +void Hud_Draw3dScene(vector topleft, vector size) +{ + clearscene(); + + setviewprop(VF_DRAWWORLD, 0); + setviewprop(VF_DRAWENGINESBAR, 0); + setviewprop(VF_DRAWCROSSHAIR, 0); + setviewprop(VF_MIN, topleft); + setviewprop(VF_SIZE, size); + setviewprop(VF_FOV, '30 30'); + setviewprop(VF_ORIGIN, '0 0 0'); + setviewprop(VF_ANGLES, '0 0 0'); + + addentity(hud3ditem); + renderscene(); +} + +void Hud_Draw3dItem(vector topleft, vector size, string modelname, vector org, vector ang) +{ + if (!hud3ditem) + hud3ditem = spawn(); + + hud3ditem.origin = org; + hud3ditem.angles = ang; + setmodel(hud3ditem, modelname); + + Hud_Draw3dScene(topleft, size); +} + +void Hud_DrawQ3Head(vector topleft, vector size, string skinname, vector ang) +{ + float headmodelindex; + vector headoffset; + float headskinnumber; + + vector org; + + tokenize(skinname); + skinname = argv(0); + + headmodelindex = Anim_GetHeadModelIndex(skinname); + headskinnumber = Anim_GetHeadSkinNumber(skinname); + headoffset = Anim_GetHeadOffset(skinname); + + if (!headmodelindex) + return; //eep. + + if (!hud3ditem ) + hud3ditem = spawn(); + + setmodelindex(hud3ditem, headmodelindex); + hud3ditem.skin = headskinnumber; + + org_z = -0.5 * (hud3ditem.mins_z + hud3ditem.maxs_z); + org_y = 0.5 * (hud3ditem.mins_y + hud3ditem.maxs_y); + org_x = (hud3ditem.maxs_z - hud3ditem.mins_z) * (0.7 / /*tan(30)*/0.268); + + org += headoffset; + + hud3ditem.origin = org; + hud3ditem.angles = ang; + + Hud_Draw3dScene(topleft, size); + hud3ditem.skin = 0; +} + +void Hud_Q3(void) +{ + vector sbar; + sbar = screensize_y * ' 0 1 0' - '0 24 0'; + + Hud_Draw3dItem(sbar+'224 0', '24 24', "models/powerups/ammo/rocketam.md3", '70 0 0', '0 90 0' + ('0 1 0'*20)*sin(time)); + Hud_Draw3dItem(sbar+'0 0', '24 24', "models/powerups/armor/armor_red.md3", '80 0 -10', '0 1 0'*360*(time/6)); + Hud_DrawQ3Head(sbar+'112 0', '24 24', cvar_string("cg_forceskin"), '0 180 0'+'0 20 0'*sin(time)); + + Hud_DrawQ3Number(sbar+'24 0 0', getstati(STAT_ARMOR), '1 1 1'); + Hud_DrawQ3Number(sbar+'136 0 0', getstati(STAT_HEALTH), '1 1 1'); + Hud_DrawQ3Number(sbar+'248 0 0', getstati(STAT_AMMO), '1 1 1'); +} + +void Hud_Draw(float hudtype, float width, float height) +{ + vector sbar; + screensize_x = width; + screensize_y = height; + screensize_z = 0; + + items = getstatbits(STAT_ITEMS, 0, 23); + items2 = getstatbits(STAT_ITEMS, 23, 9); + + //if hudtype == 0 then the engine already drew it. + if (hudtype == 2) + { + Hud_Q3(); + return; + } + else + { + Hud_DrawSBar(); + Hud_DrawIBar(); + } +}; diff --git a/quakec/csqctest/src/cs/keys.qc b/quakec/csqctest/src/cs/keys.qc new file mode 100644 index 000000000..6081a8d4d --- /dev/null +++ b/quakec/csqctest/src/cs/keys.qc @@ -0,0 +1,114 @@ +float K_TAB = 9; +float K_ENTER = 13; +float K_ESCAPE = 27; +float K_SPACE = 32; + +// normal keys should be passed as lowercased ascii + +float K_BACKSPACE = 127; +float K_UPARROW = 128; +float K_DOWNARROW = 129; +float K_LEFTARROW = 130; +float K_RIGHTARROW = 131; + +float K_ALT = 132; +float K_CTRL = 133; +float K_SHIFT = 134; +float K_F1 = 135; +float K_F2 = 136; +float K_F3 = 137; +float K_F4 = 138; +float K_F5 = 139; +float K_F6 = 140; +float K_F7 = 141; +float K_F8 = 142; +float K_F9 = 143; +float K_F10 = 144; +float K_F11 = 145; +float K_F12 = 146; +float K_INS = 147; +float K_DEL = 148; +float K_PGDN = 149; +float K_PGUP = 150; +float K_HOME = 151; +float K_END = 152; + +float K_KP_HOME = 160; +float K_KP_UPARROW = 161; +float K_KP_PGUP = 162; +float K_KP_LEFTARROW = 163; +float K_KP_5 = 164; +float K_KP_RIGHTARROW = 165; +float K_KP_END = 166; +float K_KP_DOWNARROW = 167; +float K_KP_PGDN = 168; +float K_KP_ENTER = 169; +float K_KP_INS = 170; +float K_KP_DEL = 171; +float K_KP_SLASH = 172; +float K_KP_MINUS = 173; +float K_KP_PLUS = 174; + +float K_PAUSE = 255; + +// +// joystick buttons +// +float K_JOY1 = 768; +float K_JOY2 = 769; +float K_JOY3 = 770; +float K_JOY4 = 771; + +// +// aux keys are for multi-buttoned joysticks to generate so they can use +// the normal binding process +// +float K_AUX1 = 772; +float K_AUX2 = 773; +float K_AUX3 = 774; +float K_AUX4 = 775; +float K_AUX5 = 776; +float K_AUX6 = 777; +float K_AUX7 = 778; +float K_AUX8 = 779; +float K_AUX9 = 780; +float K_AUX10 = 781; +float K_AUX11 = 782; +float K_AUX12 = 783; +float K_AUX13 = 784; +float K_AUX14 = 785; +float K_AUX15 = 786; +float K_AUX16 = 787; +float K_AUX17 = 788; +float K_AUX18 = 789; +float K_AUX19 = 790; +float K_AUX20 = 791; +float K_AUX21 = 792; +float K_AUX22 = 793; +float K_AUX23 = 794; +float K_AUX24 = 795; +float K_AUX25 = 796; +float K_AUX26 = 797; +float K_AUX27 = 798; +float K_AUX28 = 799; +float K_AUX29 = 800; +float K_AUX30 = 801; +float K_AUX31 = 802; +float K_AUX32 = 803; + +// +// mouse buttons generate virtual keys +// +float K_MOUSE1 = 512; +float K_MOUSE2 = 513; +float K_MOUSE3 = 514; +float K_MOUSE4 = 515; +float K_MOUSE5 = 516; +float K_MOUSE6 = 517; +float K_MOUSE7 = 518; +float K_MOUSE8 = 519; +float K_MOUSE9 = 520; +float K_MOUSE10 = 521; + +float K_MWHEELDOWN = K_MOUSE4; +float K_MWHEELUP = K_MOUSE5; diff --git a/quakec/csqctest/src/cs/map.qc b/quakec/csqctest/src/cs/map.qc new file mode 100644 index 000000000..a38d14be9 --- /dev/null +++ b/quakec/csqctest/src/cs/map.qc @@ -0,0 +1,126 @@ +.string target; +.string targetname; + +string() getentitytoken = #355; + +void() spawn_trigger_teleport = +{ + setmodel(self, self.model); + self.model = ""; + + print("teleport at ", vtos(self.mins), vtos(self.maxs), " to ", self.target, "\n"); +}; + +void() spawn_info_teleport_destination = +{ + print("teleport_dest at ", vtos(self.origin), " called ", self.targetname, "\n"); +}; + +float() parsenewmapentity = +{ + local string field, value; + local entity nent; + local void() spawnfunc; + nent = spawn(); + +// print("new entity\n"); + while (1) + { + field = getentitytoken(); + if not (field) + break; + + if (field == "}") + { + if (!nent.classname) + break; + if (spawnfunc) + { + self = nent; + spawnfunc(); + } + return true; + } + + value = getentitytoken(); + if not (value) + break; + +// print("ent field ", field, " has value ", value, "\n"); + + if (field == "classname") + { + if (value == "trigger_teleport") + spawnfunc = spawn_trigger_teleport; + if (value == "info_teleport_destination") + spawnfunc = spawn_info_teleport_destination; + nent.classname = value; + } + else if (field == "targetname") + nent.targetname = value; + else if (field == "target") + nent.target = value; + else if (field == "origin") + nent.origin = stov(value); + else if (field == "angles") + nent.angles = stov(value); + else if (field == "angle") + { + nent.angles_x = 0; + nent.angles_y = stof(value); + nent.angles_z = 0; + } + else if (field == "model") + nent.model = value; +/* else if (field == "light"); + else if (field == "mangle"); + else if (field == "killtarget"); + else if (field == "wad"); + else if (field == "height"); + else if (field == "lip"); + else if (field == "count"); + else if (field == "dmg"); + else if (field == "delay"); + else if (field == "message"); + else if (field == "worldtype"); + else if (field == "sounds"); + else if (field == "map"); + else if (field == "spawnflags"); + else if (field == "wait"); + else if (field == "style"); + else if (field == "health"); + else if (field == "speed"); + else + print("ignoring field ", field, "\n"); +*/ + } + + remove(nent); + + return false; +}; + +void() CSQC_WorldLoaded = +{ + local string tok; + + while (1) + { + tok = getentitytoken(); + + if (tok == "") + break; + + if (tok != "{") + { + print("bad entity data\n"); + return; + } + + if (!parsenewmapentity()) + { + print("bad entity data\n"); + return; + } + } +}; diff --git a/quakec/csqctest/src/cs/menu.qc b/quakec/csqctest/src/cs/menu.qc new file mode 100644 index 000000000..fa38db7e5 --- /dev/null +++ b/quakec/csqctest/src/cs/menu.qc @@ -0,0 +1,57 @@ +float inmenu; + +enum { + ME_KEYDOWN, + ME_KEYUP, + ME_MOUSEMOVE, + ME_DRAW = 200 +}; + +var void(float event, float button, float mousex, float mousey) MenuEventFunc = __NULL__; + +void(void(float, float, float, float) fnc) Menu_Activate = +{ + inmenu = TRUE; + MenuEventFunc = fnc; +}; + +vector mousepos; +float (float event, float parama, float paramb) CSQC_InputEvent = +{ + if (!inmenu) + return false; //let the engine do what it wants. + + if (event == INPUT_MOUSEMOVE) + { + mousepos_x += parama; + if (mousepos_x < 0) + mousepos_x = 0; + if (mousepos_x >= 640) + mousepos_x = 640; + mousepos_y += paramb; + if (mousepos_y < 0) + mousepos_y = 0; + if (mousepos_y >= 480) + mousepos_y = 480; + } + + MenuEventFunc(event, parama, mousepos_x, mousepos_y); + + return true; +}; + +void() Menu_Think = +{ + if (!inmenu) + return; + + MenuEventFunc(ME_MOUSEMOVE, 0, mousepos_x, mousepos_y); + + MenuEventFunc(ME_DRAW, 0, mousepos_x, mousepos_y); +}; + +//We don't have a main menu for the csqc yet, so just pop it instead, so submenus can close properly. +void() Menu_Main = +{ + inmenu = FALSE; +}; diff --git a/quakec/csqctest/src/cs/movetypes.qc b/quakec/csqctest/src/cs/movetypes.qc new file mode 100644 index 000000000..07735c76f --- /dev/null +++ b/quakec/csqctest/src/cs/movetypes.qc @@ -0,0 +1,160 @@ +//Emulates the movetype using the 'predraw' function. + +.float starttime; + +#define RunThink() do {if (self.nextthink && self.nextthink <= time){float otime;otime = time;time = self.nextthink;self.think();time = otime;}} while(0) + +void(entity e1, entity e2) Impact = +{ + entity oself; + entity oother; + oself = self; + oother = other; + if (e1.touch && e1.solid) + { + self = e1; + other = e2; + self.touch(); + } + if (e2.touch && e2.solid) + { + self = e2; + other = e1; + self.touch(); + } + self = oself; + other = oother; +}; + +//returns the time that it didn't manage to move. +float(float time_left) FlyMove = +{ + float impacts; + vector end; + + for(impacts = 4; impacts; impacts--) + { + end = self.origin + self.velocity*time_left; + tracebox(self.origin, self.mins, self.maxs, end, FALSE, self); + if (trace_startsolid) + return time_left; + + self.origin = trace_endpos; + if (trace_fraction == 1) + { + return 0; //w00t + } + + if (trace_plane_normal_z > 0.7) + self.flags |= FL_ONGROUND; + + Impact(self, trace_ent); + if (wasfreed(self)) + return 0; + + //slide them along the wall. + self.velocity = self.velocity - (trace_plane_normal*self.velocity)*trace_plane_normal; + + + time_left -= time_left * trace_fraction; + } + return time_left; +}; +void(vector end) PushSelf = +{ + end += self.origin; + tracebox(self.origin, self.mins, self.maxs, end, FALSE, self); + if (trace_startsolid) + return; + + self.origin = trace_endpos; + if (trace_fraction == 1) + return; + + Impact(self, trace_ent); +}; + +//MOVETYPE_BOUNCE and MOVETYPE_TOSS +void() BounceProject = +{ + local vector dest; + local float td; + + RunThink(); + + td = time - self.starttime; + self.starttime = time; + + if (self.flags & FL_ONGROUND) + return; + + self.velocity = self.velocity - '0 0 800'*td; + dest = self.origin + self.velocity * td; + tracebox(self.origin, self.mins, self.maxs, dest, TRUE, self); + if (trace_startsolid) + { + trace_fraction = 0; + trace_endpos = self.origin; + } + if (trace_fraction < 1) + { + dest = trace_endpos; + self.avelocity = self.avelocity*0.5; + //bounce the gib off the surface. + if (self.movetype == MOVETYPE_BOUNCE) + self.velocity = self.velocity - (trace_plane_normal*self.velocity)*trace_plane_normal*1.5; //vectorize the bounce vector, and multiply with the bounce value + else + self.velocity = self.velocity - (trace_plane_normal*self.velocity)*trace_plane_normal; //vectorize the bounce vector, and multiply with the bounce value + + if (trace_plane_normal_z > 0.7 && self.velocity_z < 60) + { + self.velocity = '0 0 0'; + self.flags |= FL_ONGROUND; + } + } + self.angles = self.angles + self.avelocity*td; + + //Do the trail thing, if possible. + + self.origin = dest; + setorigin(self, self.origin); +}; + +void() WalkProject = +{ + float tl, td; + RunThink(); + + td = time - self.starttime; + self.starttime = time; + + tl = FlyMove(td); + if (self.flags & FL_WATERJUMP) //waterjumps, yay. + return; + + if (!trace_plane_normal_z) + { //a vertical wall + PushSelf('0 0 22'); //so step up + self.velocity_z = 0; + FlyMove(tl); //continue going forwards + PushSelf('0 0 -22'); //and step down again + } + setorigin(self, self.origin); +}; + +void() NoclipProject = +{ + float td; + RunThink(); + + td = time - self.starttime; + self.starttime = time; + + self.angles += self.avelocity*td; + self.origin += self.velocity*td; +}; + +void() NomoveProject = +{ + RunThink(); +}; \ No newline at end of file diff --git a/quakec/csqctest/src/cs/player.qc b/quakec/csqctest/src/cs/player.qc new file mode 100644 index 000000000..cea285c00 --- /dev/null +++ b/quakec/csqctest/src/cs/player.qc @@ -0,0 +1,502 @@ +// +// running +// +$frame axrun1 axrun2 axrun3 axrun4 axrun5 axrun6 + +$frame rockrun1 rockrun2 rockrun3 rockrun4 rockrun5 rockrun6 + +// +// standing +// +$frame stand1 stand2 stand3 stand4 stand5 + +$frame axstnd1 axstnd2 axstnd3 axstnd4 axstnd5 axstnd6 +$frame axstnd7 axstnd8 axstnd9 axstnd10 axstnd11 axstnd12 + + +// +// pain +// +$frame axpain1 axpain2 axpain3 axpain4 axpain5 axpain6 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + + +// +// death +// + +$frame axdeth1 axdeth2 axdeth3 axdeth4 axdeth5 axdeth6 +$frame axdeth7 axdeth8 axdeth9 + +$frame deatha1 deatha2 deatha3 deatha4 deatha5 deatha6 deatha7 deatha8 +$frame deatha9 deatha10 deatha11 + +$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8 +$frame deathb9 + +$frame deathc1 deathc2 deathc3 deathc4 deathc5 deathc6 deathc7 deathc8 +$frame deathc9 deathc10 deathc11 deathc12 deathc13 deathc14 deathc15 + +$frame deathd1 deathd2 deathd3 deathd4 deathd5 deathd6 deathd7 +$frame deathd8 deathd9 + +$frame deathe1 deathe2 deathe3 deathe4 deathe5 deathe6 deathe7 +$frame deathe8 deathe9 + +// +// attacks +// +$frame nailatt1 nailatt2 + +$frame light1 light2 + +$frame rockatt1 rockatt2 rockatt3 rockatt4 rockatt5 rockatt6 + +$frame shotatt1 shotatt2 shotatt3 shotatt4 shotatt5 shotatt6 + +$frame axatt1 axatt2 axatt3 axatt4 axatt5 axatt6 + +$frame axattb1 axattb2 axattb3 axattb4 axattb5 axattb6 + +$frame axattc1 axattc2 axattc3 axattc4 axattc5 axattc6 + +$frame axattd1 axattd2 axattd3 axattd4 axattd5 axattd6 + +#define ERRORTIME 20 +#define STEPTIME 10 + +.vector lastorg; +.vector lastvel; +.float haddied; + +vector player_org, vieworg; +vector player_vel; +float player_jump_held; +float player_sequence; +float player_steptime; +float player_step; +entity player_local; //refers to the local player +float player_localentnum; +float recframe; + +vector pmove_error; +float pmove_errortime; +float pmove_step; +float pmove_steptime; + +.void() removefunc; + +float pmoveframe; +void() ResetPlayerPrediction = +{ +//reset the pmove to lerp from the new position + pmove_org = player_org; + pmove_vel = player_vel; + pmoveframe = player_sequence+1; //the recieved frame has the move already done (server side) + pmove_jump_held = player_jump_held; + pmove_steptime = player_steptime; + pmove_step = player_step; + + if (pmoveframe < clientcommandframe-128) + pmoveframe = clientcommandframe-128; //avoid an infinate loop + +//print("reset, porg is ", ftos(pmove_org_z), "\n"); +}; + +void(float endframe) RunMovement = +{ + float oz; + + if (servercommandframe >= player_sequence+63) + { + //we're meant to be updating the player faster than this + //hopefully its just that we're throttled... + player_sequence = servercommandframe-63; + + return; + } + + oz = pmove_org_z; +ResetPlayerPrediction (); + if (getstati(STAT_HEALTH) <= 0) + { + pmoveframe = clientcommandframe; + //just update the angles + if (!getinputstate(pmoveframe-1)) + { + } + return; //dead, so don't run prediction. :D + } + + if (cvar("cg_nopred") || cvar("cl_nopred")) + { + pmoveframe = clientcommandframe; + //just update the angles + if (!getinputstate(pmoveframe-1)) + { + } + return; + } +//print("start, porg is ", ftos(pmove_org_z), "\n"); + while(pmoveframe < endframe) + { + if (!getinputstate(pmoveframe)) + { +#ifndef WORKINDP + break; +#endif + } + runstandardplayerphysics(); + pmoveframe++; + } +//print(" ran, porg is ", ftos(pmove_org_z), "\n"); + + if (pmove_org_z > oz+8 && pmove_org_z < oz+24 && pmove_vel_z == 0) + { + //evaluate out the remaining old step + if (pmove_steptime - time > 0) + pmove_step = (pmove_steptime - time)*STEPTIME*pmove_step; + else + pmove_step = 0; + + //work out the new step + pmove_step += (oz-pmove_org_z); + pmove_steptime = time + 1/STEPTIME; + } + + //add in anything that was applied after (for low packet rate protocols) + input_angles = view_angles; +}; + +void() UpdateLocalMovement = +{ + local float viewheight; + + RunMovement(clientcommandframe); + + //allow the user to move the viewheight down 6 units so it's at +16, where projectiles come from. + viewheight = cvar("v_viewheight"); + if (viewheight < -7) + viewheight = -7; + if (viewheight > 7) + viewheight = 7; + + vieworg = pmove_org; //the default view height + vieworg_z += 22 + viewheight; + + //correct the view position to compensate for any errors, slowly over time, 0.1 seconds. + if (pmove_errortime - time > 0) + vieworg += (pmove_errortime - time)*ERRORTIME * pmove_error; + + if (!cvar("cg_nostep")) + if (pmove_steptime - time > 0) + vieworg_z += (pmove_steptime - time)*STEPTIME * pmove_step; + + if (chasecam) + { + makevectors(input_angles); + traceline(pmove_org, vieworg - v_forward * 72+v_up*32, FALSE, self); + vieworg = trace_endpos + v_forward*8; + } +}; + +.string oldskin; +void() RemovePlayer; + +void() Player_Interpolate = +{ //do some frame interpolation. + if (self.modelnum != -1 && self.model!="") + Anim_Draw(); + else + { + self.lerpfrac = 1-(time-self.lerptime)*10; + + if (chasecam || self.entnum != player_localentnum) + self.renderflags = 0; + else + self.renderflags = RF_EXTERNALMODEL; + + if (self.sveffects & SVE_INVIS) + self.forceshader = shaderforname("powerups/invisibility"); + else + self.forceshader = 0; + self.fatness = 0; + + if (self.sveffects & SVE_QUAD) + { + addentity(self); + + self.fatness = -2; + self.forceshader = shaderforname("powerups/quad"); + } + if (self.sveffects & SVE_GOD) + { + addentity(self); + + self.fatness = -2.8; + self.forceshader = shaderforname("powerups/regen"); + } + } +}; + +void() BounceProject; +.float removetime; +.float starttime; +.float oldframe; +void() bodythink = +{ + local float final; + if (self.frame >= $axdeth1 && self.frame <= $axdeth9) + final = $axdeth9; + else if (self.frame >= $deatha1 && self.frame <= $deatha11) + final = $deatha11; + else if (self.frame >= $deathb1 && self.frame <= $deathb9) + final = $deathb9; + else if (self.frame >= $deathc1 && self.frame <= $deathc15) + final = $deathc15; + else if (self.frame >= $deathd1 && self.frame <= $deathd9) + final = $deathd9; + else if (self.frame >= $deathe1 && self.frame <= $deathe9) + final = $deathe9; + + self.frame = self.frame+1; + + if (self.frame > final) + self.frame = final; + + self.nextthink = time + 0.1; +}; +void() DeadBodyPredraw = +{ + float ftime; + ftime = time - self.starttime; + + if (self.removetime < time) + { + Anim_UnsetModel(); + remove(self); + return; + } + + BounceProject(); + + Player_Interpolate(); + self.origin_z -= ftime*0.5; +}; + +void() JustRessed = +{ + local entity e; + + e = Anim_DupModel(); + e.frame = self.oldframe; //and stay dead! + e.frame2 = self.oldframe; //and stay dead! + setmodel(e, "progs/player.mdl"); + e.origin = self.lastorg; + e.velocity = self.lastvel; + e.predraw = DeadBodyPredraw; + e.removetime = time + 30; + + e.gibbable = GIB_PLAYER; + e.solid = SOLID_TRIGGER; + + e.classname = "deadbody"; + e.movetype = MOVETYPE_TOSS; + + e.starttime = time; + e.nextthink = time + 0.1; + e.think = bodythink; + e.drawmask = self.drawmask; +}; + +void() PlayerUpdated = +{ + local float noerror; + local vector o; + + noerror = cvar("cg_noerror"); + + //reset the prediction to last-known-good state + ResetPlayerPrediction(); + RunMovement(servercommandframe+1); + player_jump_held = pmove_jump_held; + player_step = pmove_step; + player_steptime = pmove_steptime; + + player_org = self.origin; + player_vel = self.velocity; + pmove_mins = self.mins; + pmove_maxs = self.maxs; + player_sequence = servercommandframe; + + if (noerror) + { + pmove_error = '0 0 0'; + pmove_errortime = time; + + ResetPlayerPrediction(); + } + else + { + RunMovement(clientcommandframe); //make sure we're up to date + o = pmove_org; //save off the old for the teleport check below. + + //reset it, then update to now to guage how much our previous prediction was incorrect by + ResetPlayerPrediction(); + RunMovement(clientcommandframe); + + if (vlen(o - pmove_org) > 64) + {//teleport + pmove_error = '0 0 0'; + pmove_errortime = time; + } + else + { //figure out the error ammount, and lerp back to it, without forgetting about any current inaccuracies. + pmove_error = (pmove_errortime - time)*ERRORTIME * pmove_error + (o - pmove_org); + if (vlen(pmove_error) < 1) + pmove_error = '0 0 0'; + pmove_errortime = time + 1/ERRORTIME; + } + } +}; + +void() RemovePlayer = +{ + if (self.haddied) + { + print("removeressed\n"); + JustRessed(); + self.haddied = false; + } + + strunzone(self.oldskin); + self.oldskin = ""; + Anim_UnsetModel(); + + self.predraw = __NULL__; +}; + +void(float isnew) RefreshPlayer = +{ + local string newskin; + + self.predraw = Player_Interpolate; + + if (isnew) + self.haddied = false; + + //if its not new and they're not dead, but they were before.. + if (self.frame < $axdeth1 || self.frame > $deathe9) + { + if (self.haddied) + { + JustRessed(); + self.haddied = false; + } + } + else + { + self.haddied = true; + } + + self.lastorg = self.origin; + self.lastvel = self.velocity; + + if (isnew) + { +print("new player!\n"); + if (self.entnum == player_localentnum) + { + player_local = self; + } + + self.model = "progs/player.mdl"; + self.oldskin = strzone(""); + Anim_UnsetModel(); + self.drawmask = MASK_NORMAL; + + self.removefunc = RemovePlayer; + } + + newskin = cvar_string("cg_forceskin"); + if (newskin == "") + newskin = getplayerkeyvalue(self.entnum-1, "skin"); +/* if (newskin == "") + { + if (self.oldskin != "") + newskin = strcat(self.oldskin); + else if (random() < 0.33) + newskin = "angelyss/neko"; + else if (random() < 0.5) + newskin = "arachna/red"; + else + newskin = "ayumi/jenna"; + } +*/ + if (newskin != self.oldskin) + { +print("changing to new model\n"); + strunzone(self.oldskin); + self.oldskin = strzone(newskin); + if (!Anim_SetModel(self.oldskin)) + { + if (self.oldskin!="") + print("couldn't set skin\n"); + Anim_UnsetModel(); + } +/* + switch(Anim_GetGender()) + { + case GENDER_FEMALE: + localcmd("setinfo sex f\n"); + break; + case GENDER_MALE: + localcmd("setinfo sex m\n"); + break; + case GENDER_NEUTER: + localcmd("setinfo sex n\n"); + break; + } +*/ + } + + setsize(self, VEC_HULL_MIN, VEC_HULL_MAX); + + self.oldframe = self.frame; + + if (player_local != self) + return; + + PlayerUpdated(); +}; + +//this is sent after the server has run our movement command. +void(float isnew) ParsePlayer = +{ + local float f; + + f = readbyte(); + + if (f != self.frame || isnew) + { + self.frame2 = self.frame; + self.lerptime = time; + self.frame = f; + } + + self.angles_x = readbyte()*(360/256); + self.angles_y = readbyte()*(360/256); + self.origin_x = readcoord(); + self.origin_y = readcoord(); + self.origin_z = readcoord(); + self.velocity_x = readshort()/64; + self.velocity_y = readshort()/64; + self.velocity_z = readshort()/64; + self.colormap = self.entnum; + + self.sveffects = readbyte(); + + RefreshPlayer(isnew); +}; + diff --git a/quakec/csqctest/src/cs/system.qc b/quakec/csqctest/src/cs/system.qc new file mode 100644 index 000000000..520d20644 --- /dev/null +++ b/quakec/csqctest/src/cs/system.qc @@ -0,0 +1,188 @@ + +//NOTE: THIS IS AN INTERFACE FILE. DO NOT EDIT. +//MODIFYING THIS FILE CAN RESULT IN CRC ERRORS. +//YOU HAVE BEEN WARNED. + +//It is safe to edit below the end_sys_fields define, +//but please don't report the engine rejecting due to +//crc mismatches when you've modified above that line. + +//feel free to look though. :) + + + +#ifndef CSQC +#define CSQC 1 +#endif + +/* +============================================================================== + + SOURCE FOR GLOBALVARS_T C STRUCTURE + +============================================================================== +*/ + +// +// system globals +// +entity self; +entity other; +entity world; +float time; +float frametime; + +float player_localentnum; //the entnum +float player_localnum; //the playernum +float maxclients; //a constant filled in by the engine. gah, portability eh? + +float clientcommandframe; //player movement +float servercommandframe; //clientframe echoed off the server + +string mapname; //current brief map name + +#ifndef WORKINDP +float intermission; //non-zero if the server sent an svc_intermission. +#endif + +// +// global variables set by built in functions +// +vector v_forward, v_up, v_right; // set by makevectors() + +// set by traceline / tracebox +float trace_allsolid; +float trace_startsolid; +float trace_fraction; +vector trace_endpos; +vector trace_plane_normal; +float trace_plane_dist; +entity trace_ent; +float trace_inopen; +float trace_inwater; + +#ifdef WORKINDP +void() CSQC_Init; +void() CSQC_Shutdown; +float(float f, float t, float n) CSQC_InputEvent; +void(float width, float height, float do2d) CSQC_UpdateView; +float(string s) CSQC_ConsoleCommand; +#endif + +//these fields are read and set by the default player physics +vector pmove_org; +vector pmove_vel; +vector pmove_mins; +vector pmove_maxs; +//retrieved from the current movement commands (read by player physics) +float input_timelength; +vector input_angles; +vector input_movevalues; //forwards, right, up. +float input_buttons; //attack, use, jump (default physics only uses jump) + +float movevar_gravity; +float movevar_stopspeed; +float movevar_maxspeed; +float movevar_spectatormaxspeed; //used by NOCLIP movetypes. +float movevar_accelerate; +float movevar_airaccelerate; +float movevar_wateraccelerate; +float movevar_friction; +float movevar_waterfriction; +float movevar_entgravity; //the local player's gravity field. Is a multiple (1 is the normal value) + +//================================================ +void end_sys_globals; // flag for structure dumping +//================================================ + +/* +============================================================================== + + SOURCE FOR ENTVARS_T C STRUCTURE + +============================================================================== +*/ + +// +// system fields (*** = do not set in prog code, maintained by C code) +// +.float modelindex; // *** model index in the precached list +.vector absmin, absmax; // *** origin + mins / maxs + +.float entnum; // *** the ent number as on the server +.float drawmask; +.void() predraw; + +.float movetype; +.float solid; + +.vector origin; // *** +.vector oldorigin; // *** +.vector velocity; +.vector angles; +.vector avelocity; + +.string classname; // spawn function + +#ifndef WORKINDP +.float renderflags; +#endif +.string model; +.float frame; +#ifndef WORKINDP +.float frame2; +.float lerpfrac; //the ammount of frame2 to use. +#endif +.float skin; + +#ifdef WORKINDP +.float effects; +#endif + +.vector mins, maxs; // bounding box extents reletive to origin +.vector size; // maxs - mins + +.void() touch; +.void() use; +.void() think; +.void() blocked; // for doors or plats, called when can't push other + +.float nextthink; + +.entity chain; + +#ifdef WORKINDP +.string netname; +#endif + +.entity enemy; + +.float flags; + +.float colormap; + +.entity owner; // who launched a missile + +//================================================ +void end_sys_fields; // flag for structure dumping +//================================================ + +#ifdef WORKINDP +.float frame2; +.float renderflags; +.float lerpfrac; +#endif + +vector view_angles; + +//optional extras +.float alpha; +.float scale; +.float forceshader; //an fte extension, to force a q3 shader upon a model +.float fatness; //an fte feature, to expand alias models along thier normals. + +float pmove_jump_held; +float pmove_waterjumptime; + +.float frame1time; //for automatic framegroups. +.float frame2time; \ No newline at end of file diff --git a/quakec/csqctest/src/cs/test.qc b/quakec/csqctest/src/cs/test.qc new file mode 100644 index 000000000..6aeaf6c85 --- /dev/null +++ b/quakec/csqctest/src/cs/test.qc @@ -0,0 +1,16 @@ + +void() runtest = +{ + self.frame1time = time; +}; + +void() test = +{ + precache_model("test/test.txt"); + self = spawn(); + setmodel(self, "test/test.txt"); + setorigin(self, player_local.origin); + self.drawmask = 1; + self.frame = floor(random()*2); + self.predraw = runtest; +}; \ No newline at end of file diff --git a/quakec/csqctest/src/cs/weapons.qc b/quakec/csqctest/src/cs/weapons.qc new file mode 100644 index 000000000..0598e3055 --- /dev/null +++ b/quakec/csqctest/src/cs/weapons.qc @@ -0,0 +1,330 @@ + +#define crandom() (random()*2 - 1) +.float starttime; +.vector source; +.vector angles; +.float alpha; + +//Moves the entity to where it should be +void() RocketProject = +{ + local vector oldorg; + oldorg = self.origin; + self.origin = self.source + self.velocity * (time - self.starttime); + + //Do the trail thing, if possible. +#ifdef WORKINDP + trailparticles(self, particleeffectforname("tr_rocket"), self.origin, oldorg); +#else + trailparticles(particleeffectforname("tr_rocket"), self, self.origin, oldorg); +#endif + + adddynamiclight(self.origin, 400, '0 1 0'); +}; + +void(float isnew) ParseRocketClass = +{ + self.starttime = time; + self.source_x = readcoord(); + self.source_y = readcoord(); + self.source_z = readcoord(); + self.angles_x = (readshort()*360)/65535; + self.angles_y = (readshort()*360)/65535; + self.angles_z = random()*360; + + self.angles_x*=-1; + makevectors(self.angles); + self.angles_x*=-1; + self.velocity = v_forward*1000; + self.origin = self.source; + + setmodel(self, "progs/missile.mdl"); + self.drawmask = MASK_NORMAL; //general view. + self.predraw = RocketProject; +}; + +void() NailProject = +{ + local vector oldorg; + oldorg = self.origin; + self.origin = self.source + self.velocity * (time - self.starttime); + + //Do the trail thing, if possible. +#ifdef WORKINDP + trailparticles(self, particleeffectforname("tr_nail"), self.origin, oldorg); +#else + trailparticles(particleeffectforname("tr_nail"), self, self.origin, oldorg); +#endif + +// adddynamiclight(self.origin, 100, '1 0 0'); +}; + +void(float isnew) ParseNailClass = +{ + local float speed; + self.starttime = time; + self.source_x = readcoord(); + self.source_y = readcoord(); + self.source_z = readcoord(); + self.modelindex = readbyte(); + speed = readshort(); + self.angles_x = (readshort()*360)/65535; + self.angles_y = (readshort()*360)/65535; + self.angles_z = 0; //don't rotate nails. + + self.angles_x*=-1; + makevectors(self.angles); + self.angles_x*=-1; + self.velocity = v_forward*speed; + self.origin = self.source; + + setmodelindex(self, self.modelindex); + self.drawmask = MASK_NORMAL; //general view. + self.predraw = NailProject; +}; + +vector(float dm) VelocityForDamage = +{ + local vector v; + + v_x = 100 * crandom(); + v_y = 100 * crandom(); + v_z = 200 + 100 * random(); + + dm*=-1; + + if (dm > -50) + { +// print ("level 1\n"); + v = v * 0.7; + } + else if (dm > -200) + { +// print ("level 2\n"); + v = v * 2; + } + else + { +// print ("level 3\n"); + v = v * 10; + } + + return v; +}; + +void() GibProject = +{ + local float td; + local vector oldorg; + oldorg = self.origin; + + td = time - self.starttime; + if (self.nextthink < time) + { + if (self.alpha <= td) + { + remove(self); + return; + } + self.alpha -= td; + } + + BounceProject(); +#ifdef WORKINDP + trailparticles(self, particleeffectforname("tr_blood"), self.origin, oldorg); +#else + trailparticles(particleeffectforname("tr_blood"), self, self.origin, oldorg); +#endif +}; + +void(string gibname, float dm, vector org) ThrowGib = +{ + local entity new; + + new = spawn(); + new.origin = org; + setmodel (new, gibname); + setsize (new, '0 0 0', '0 0 0'); + new.velocity = VelocityForDamage (dm); + new.movetype = MOVETYPE_BOUNCE; + new.solid = SOLID_NOT; + new.avelocity_x = random()*600; + new.avelocity_y = random()*600; + new.avelocity_z = random()*600; + new.think = remove; + new.nextthink = time + 10 + random()*10; + new.frame = 0; + new.flags = 0; + + new.alpha = 1; + new.drawmask = MASK_NORMAL; + + new.predraw = GibProject; + new.starttime = time; +}; + +void TossGibs(vector org, float type, float dm) +{ + local float giblevel; + + switch(type) + { + case GIB_ZOMBIE: + sound (self, CHAN_VOICE, "zombie/z_gib.wav", 1, ATTN_NORM); + break; + default: + sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NORM); + break; + } + + giblevel = cvar("cg_giblevel"); + if (giblevel > 20) + giblevel = 20; + + while(giblevel > 0) + { + giblevel--; + switch(type) + { + case GIB_PLAYER: + ThrowGib("progs/h_player.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_SOLDIER: //CHUNKY KIBBLES!!! + ThrowGib("progs/h_guard.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_DOG: + ThrowGib("progs/h_guard.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_DEMON: + ThrowGib("progs/h_demon.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_OGRE: + ThrowGib("progs/h_ogre.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_WIZARD: + ThrowGib("progs/h_wizard.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + break; + case GIB_SHAMBLER: + ThrowGib("progs/h_shams.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_ZOMBIE: + ThrowGib("progs/h_zombie.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_KNIGHT: + ThrowGib("progs/h_knight.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + + case GIB_HELLKNIGHT: + ThrowGib("progs/h_hellkn.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_FISH: + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_ENFORCER: + ThrowGib("progs/h_mega.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + case GIB_SHALRATH: + ThrowGib("progs/h_shal.mdl", dm, org); + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + default: + ThrowGib("progs/gib1.mdl", dm, org); + ThrowGib("progs/gib2.mdl", dm, org); + ThrowGib("progs/gib3.mdl", dm, org); + break; + } + } +}; + +void(float isnew) ParseGibbing = +{ + float type; + vector org; + float dm; + float i; + + float giblevel; + + type = readbyte(); + dm = readbyte(); + org_x = readcoord(); + org_y = readcoord(); + org_z = readcoord(); + + if (!isnew) //doesn't count if it's not new. + return; + + self.origin = org; + TossGibs(org, type, dm); +} + +void(float isnew) ParseExplosion = +{ + local vector org; + local entity e; + org_x = readcoord(); + org_y = readcoord(); + org_z = readcoord(); + self.origin = org; + if (isnew) + { + sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM); +#ifdef WORKINDP + pointparticles(particleeffectforname("te_explosion"), org, '0 0 0', 1); +#else + pointparticles(particleeffectforname("te_explosion"), org); +#endif + + e = world;//findradius(org, 120); + while (e) + { + //a bit of fun - allow the local client to gib csqc bodies + if (e.gibbable) + { + TossGibs(e.origin+'0 0 16', e.gibbable, 20); + e.gibbable = GIB_BAD; + e.removetime = 0; + } + e = e.chain; + } + } + + self.drawmask = 0; //don't draw it any more. +}; \ No newline at end of file diff --git a/quakec/csqctest/src/csprogs.src b/quakec/csqctest/src/csprogs.src new file mode 100644 index 000000000..bb7c68c3f --- /dev/null +++ b/quakec/csqctest/src/csprogs.src @@ -0,0 +1,40 @@ +../csprogs.dat + +optscsqc.qc +optsall.qc + +cs/system.qc +cs/defs.qc + +common/classes.qc + +common/combuiltins.qc +cs/csbuiltins.qc + +common/extensions.qc + +common/econstants.qc +cs/constants.qc + +common/pmove.qc + +cs/animation.qc +cs/player.qc +cs/hud.qc + +cs/movetypes.qc + +cs/map.qc +cs/keys.qc +cs/menu.qc +cs/fun/tetris.qc +cs/fun/osgk.qc + +cs/weapons.qc + +common/classes.qc + +cs/test.qc + +cs/fun/skinchooser.qc +cs/entrypoints.qc diff --git a/quakec/csqctest/src/fteext.qc b/quakec/csqctest/src/fteext.qc new file mode 100644 index 000000000..1274502b1 --- /dev/null +++ b/quakec/csqctest/src/fteext.qc @@ -0,0 +1,104 @@ + +//FTE_CALLTIMEOFDAY +//IDEA: mvdsv team +void() calltimeofday = #231; +//void(float secs, float min, float hour, float day, float month, float year, string datestring) timeofday = {}; +//A new builtin which immediatly calls a "timeofday" QC function. The key functionality here is that the parameters to the timeofday qc function are infact, the time of day. +//Note that expected use is to copy the parameters into globals, and then use the globals where the builtin was called from. +//History: This extension is identical to the calltimeofday builtin found in mvdsv. However, it uses a different builtin number in an effort to reduce builtin conflicts with other extensions (which mvdsv is not good for). Using cunning coding, you can achieve support for either. + +//FTE_FORCEINFOKEY +//FIXME:forceinfokey + +//FTE_ISBACKBUFFERED +//FIXME:isbackbuffered + +//FTE_MEDIA_AVI +//The console command 'playfilm' supports avi files. Uncompressed audio only, however. + +//FTE_MEDIA_CIN +//The console command 'playfilm' supports quake2 .cin files. + +//FTE_MEDIA_ROQ +//The console command 'playfilm' supports quake3 .RoQ files. + +//FTE_MULTIPROGS +//FIXME +//all sorts of fun multiple progs stuff all running in the same virtual machine. +//it's great fun. + +//FTE_MULTITHREADED +void(float duration) sleep = #; +float() fork = #; +void(...) abort = #; +//sleep stops execution and magically restarts duration seconds later +//fork magically splits execution and somehow returns twice each individual time it's called. +//abort returns from the current function as well as all calling qc functions. Pass a parameter if the root qc function is meant to return something. +//note that sleep and fork preserve only locals and not globals or entity fields. + +//FTE_MVD_PLAYBACK +//there is a playmvd console command, which can play a multiview demo to all connected clients, returning to the current gamestate when finished. + +//FTE_NPCCHAT +//FIXME:chat +//a scripting language supporting qc callbacks, specially designed for one-on-one conversations with non-player charactures. + +//FTE_SOLID_LADDER +float SOLID_LADDER = 20; +//players entering a solid type of this type using qw physics will treat it as a ladder. + +//FTE_STRINGS +//FIXME:stof +//FIXME:strlen +//FIXME:strcat +//FIXME:substring +//FIXME:stov +//FIXME:strzone +//FIXME:strunzone +//FIXME:strstrofs +//FIXME:str2chr +//FIXME:chr2str +//FIXME:strconv +//FIXME:infoadd +//FIXME:infoget +//FIXME:strncmp +//FIXME:strcasecmp +//FIXME:strncasecmp + + + +//FTE_PEXT_SETVIEW"}, //nq setview works. + +//FTE_PEXT_LIGHTSTYLECOL +void(float style, string value, float colourmask) lightstylecol = #35; +float LS_RED = 1; +float LS_GREEN = 2; +float LS_BLUE = 4; +//colours light effects according to bits. Doesn't even need lits. Useful for making an entire map red, and stuff. + +//FTE_PEXT_VIEW2 +.entity view2; +//when set, the player will gain an extra little window showing the world from a different viewpoint. +//Move and angle the view2 entity to position it. Great for rocket cams and alerts (ctf?..) + +//FTE_PEXT_BULLETENS +//Certain texture names can be replaced with text. Can show leader/looser/adverts. + +//FTE_PEXT_FATNESS +.float fatness; +//expands an entity along it's vertex normals. +//Makes it fat without scaling it up. +//vacuum chambers... + +//FTE_PEXT_HULLSIZE +.float hull; +//Use this hull number minus one for bsp collisions, and a bbox for entity-entity collisions. + +//FTE_PEXT_CUSTOMTENTS +//FIXME:RegisterTempEnt +//FIXME:CustomTempEnt + +//FTE_PEXT_256PACKETENTITIES +//Removes the 64 entities visible at once that the qw protocol origionally suffered from. + +//EXT_CSQC \ No newline at end of file diff --git a/quakec/csqctest/src/miscext.qc b/quakec/csqctest/src/miscext.qc new file mode 100644 index 000000000..138475a71 --- /dev/null +++ b/quakec/csqctest/src/miscext.qc @@ -0,0 +1,253 @@ +//definitions that id Software left out +//these are passed as the 'nomonsters' parameter to traceline/tracebox (yes really this was supported in all quake engines, nomonsters is misnamed) +float MOVE_NORMAL = 0; // same as FALSE +float MOVE_NOMONSTERS = 1; // same as TRUE +float MOVE_MISSILE = 2; // save as movement with .movetype == MOVETYPE_FLYMISSILE + +//checkextension function +//idea: expected by almost everyone +//darkplaces implementation: LordHavoc +float(string s) checkextension = #99; +//description: +//check if (cvar("pr_checkextension")) before calling this, this is the only +//guarenteed extension to be present in the extension system, it allows you +//to check if an extension is available, by name, to check for an extension +//use code like this: +//// (it is recommended this code be placed in worldspawn or a worldspawn called function somewhere) +//if (cvar("pr_checkextension")) +//if (checkextension("DP_SV_SETCOLOR")) +// ext_setcolor = TRUE; +//from then on you can check ext_setcolor to know if that extension is available + + + + + + + +//EXT_BITSHIFT +//IDEA: Spike +float(float number, float quantity) bitshift = #218; +//Shifts 'number' 'quantity' bits to the left. So a shift of 1 bit essentually doubles the value while a shift of -1 bit halves. 2 quadrouples and so on. +//The function acts on floats, but casts as integers. The maximum reliable bit stored in a float is 1e23. Adding a twenty fourth bit is possible, but can result in some of the lower bits becoming corrupted. + +//EXT_DIMENSION_GHOST +//IDEA: ?????FIXME????? +.float dimension_ghost; +.float dimension_ghost_alpha; +//depends on EXT_DIMENSION_VISIBLE +//provides an alternate mask for entities to see this one. +//entities seen with this mask and not the dimension_seen mask will have thier alpha value multiplied by thier dimension_ghost_alpha. +//they default to 255 upon entity creation. + +//EXT_DIMENSION_PHYSICS +//IDEA: ?????FIXME?????, Spike +.float dimension_hit; +.float dimension_solid; +//Controls which entities are allowed to collide with other entities. +//dimension_solid is the mask of dimensions in which an entity is solid. +//dimension_hit is the mask of dimensions which will not pass through dimension_solid. +//most of the time they will be the same. +//if one entity walks into annother, they must be able to ignore the other even if thier masks say not. +//they default to 255 upon entity creation. + +//EXT_DIMENSION_VISIBLE +//IDEA: ?????FIXME?????, Spike +.float dimension_see; +.float dimension_seen; +float dimension_send; +//Controls which players see which entities/players. +//You always see yourself. +//the dimension_seen mask is the mask of dimensions which an entity can be seen, while dimension_see is which dimensions an entity can see into. +//dimension_send is set around the sound and various particle effect builtins, and will be sent only to players who's dimension_see matches. +//note that this can be used for sound directed at a single player, per-class pickups, and other cool stuff. +//they default to 255 upon entity creation - note that saved games will need to be fixed-up if there are no values set on any entity after load. + +//FRIK_FILE +//idea: FrikaC +//darkplaces implementation: LordHavoc +//builtin definitions: +float(string s) stof = #81; // get numerical value from a string +float(string filename, float mode) fopen = #110; // opens a file inside quake/gamedir/data/ (mode is FILE_READ, FILE_APPEND, or FILE_WRITE), returns fhandle >= 0 if successful, or fhandle < 0 if unable to open file for any reason +void(float fhandle) fclose = #111; // closes a file +string(float fhandle) fgets = #112; // reads a line of text from the file and returns as a tempstring +void(float fhandle, string s) fputs = #113; // writes a line of text to the end of the file +float(string s) strlen = #114; // returns how many characters are in a string +string(string s1, string s2) strcat = #115; // concatenates two strings (for example "abc", "def" would return "abcdef") and returns as a tempstring +string(string s, float start, float length) substring = #116; // returns a section of a string as a tempstring +vector(string s) stov = #117; // returns vector value from a string +string(string s) strzone = #118; // makes a copy of a string into the string zone and returns it, this is often used to keep around a tempstring for longer periods of time (tempstrings are replaced often) +void(string s) strunzone = #119; // removes a copy of a string from the string zone (you can not use that string again or it may crash!!!) +//constants: +float FILE_READ = 0; +float FILE_APPEND = 1; +float FILE_WRITE = 2; +//cvars: +//pr_zone_min_strings : default 64 (64k), min 64 (64k), max 8192 (8mb) +//description: +//provides text file access functions and string manipulation functions, note that you may want to set pr_zone_min_strings in the worldspawn function if 64k is not enough string zone space. + +//KRIMZON_SV_PARSECLIENTCOMMAND +//idea: KrimZon +//darkplaces implementation: KrimZon, LordHavoc +//engine-called QC prototypes: +//void(string s) SV_ParseClientCommand; +//builtin definitions: +void(entity e, string s) clientcommand = #440; +float(string s) tokenize = #441; +string(float n) argv = #442; +//description: +//provides QC the ability to completely control server interpretation of client commands ("say" and "color" for example, clientcommand is necessary for this and substring (FRIK_FILE) is useful) as well as adding new commands (tokenize, argv, and stof (FRIK_FILE) are useful for this)), whenever a clc_stringcmd is received the QC function is called, and it is up to the QC to decide what (if anything) to do with it + +//NEH_CMD_PLAY2 +//idea: Nehahra +//darkplaces implementation: LordHavoc +//description: +//shows that the engine supports the "play2" console command (plays a sound without spatialization). + +//NEH_RESTOREGAME +//idea: Nehahra +//darkplaces implementation: LordHavoc +//engine-called QC prototypes: +//void() RestoreGame; +//description: +//when a savegame is loaded, this function is called + +//NEXUIZ_PLAYERMODEL +//idea: Nexuiz +//darkplaces implementation: Black +//console commands: +//playermodel - FIXME: EXAMPLE NEEDED +//playerskin - FIXME: EXAMPLE NEEDED +//field definitions: +.string playermodel; // name of player model sent by client +.string playerskin; // name of player skin sent by client +//description: +//these client properties are used by Nexuiz. + +//NXQ_GFX_LETTERBOX +//idea: nxQuake +//darkplaces implementation: LordHavoc +//description: +//shows that the engine supports the "r_letterbox" console variable, set to values in the range 0-100 this restricts the view vertically (and turns off sbar and crosshair), value is a 0-100 percentage of how much to constrict the view, <=0 = normal view height, 25 = 75% of normal view height, 50 = 50%, 75 = 25%, >=100 = no view + +//PRYDON_CLIENTCURSOR +//idea: FrikaC +//darkplaces implementation: LordHavoc +//effects bit: +float EF_SELECTABLE = 16384; // allows cursor to highlight entity (brighten) +//field definitions: +.float cursor_active; // true if cl_prydoncursor mode is on +.vector cursor_screen; // screen position of cursor as -1 to +1 in _x and _y (_z unused) +.vector cursor_trace_start; // position of camera +.vector cursor_trace_endpos; // position of cursor in world (as traced from camera) +.entity cursor_trace_ent; // entity the cursor is pointing at (server forces this to world if the entity is currently free at time of receipt) +//cvar definitions: +//cl_prydoncursor (0/1+, default 0, 1 and above use cursors named gfx/prydoncursor%03i.lmp - or .tga and such if DP_GFX_EXTERNALTEXTURES is implemented) +//description: +//shows that the engine supports the cl_prydoncursor cvar, this puts a clientside mouse pointer on the screen and feeds input to the server for the QuakeC to use as it sees fit. +//the mouse pointer triggers button4 if cursor is at left edge of screen, button5 if at right edge of screen, button6 if at top edge of screen, button7 if at bottom edge of screen. +//the clientside trace skips transparent entities (except those marked EF_SELECTABLE). +//the selected entity highlights only if EF_SELECTABLE is set, a typical selection method would be doubling the brightness of the entity by some means (such as colormod[] *= 2). +//intended to be used by Prydon Gate. + +//QSG_FILE +//IDEA: ?????FIXME????? +//Same as FRIK_FILE, but definitions numbers aren't the same. + +//TENEBRAE_GFX_DLIGHTS +//idea: Tenebrae +//darkplaces implementation: LordHavoc +//fields: +.float light_lev; // radius (does not affect brightness), typical value 350 +.vector color; // color (does not affect radius), typical value '1 1 1' (bright white), can be up to '255 255 255' (nuclear blast) +.float style; // light style (like normal light entities, flickering torches or switchable, etc) +.float pflags; // flags (see PFLAGS_ constants) +.vector angles; // orientation of the light +.float skin; // cubemap filter number, can be 1-255 (0 is assumed to be none, and tenebrae only allows 16-255), this selects a projective light filter, a value of 1 loads cubemaps/1posx.tga and cubemaps/1negx.tga and posy, negy, posz, and negz, similar to skybox but some sides need to be rotated or flipped +//constants: +float PFLAGS_NOSHADOW = 1; // light does not cast shadows +float PFLAGS_CORONA = 2; // light has a corona flare +float PFLAGS_FULLDYNAMIC = 128; // light enable (without this set no light is produced!) +//description: +//more powerful dynamic light settings +//warning: it is best not to use cubemaps on a light entity that has a model, as using a skin number that a model does not have will cause issues in glquake, and produce warnings in darkplaces (use developer 1 to see them) +//changes compared to tenebrae (because they're too 'leet' for standards): +//EF_FULLDYNAMIC effects flag replaced by PFLAGS_FULLDYNAMIC flag (EF_FULLDYNAMIC conflicts with EF_NODRAW) + +//TEI_MOVRELATIVESTATIC +//IDEA: Tei +//movetype definitions: +float MOVETYPE_RELATIVESTATIC = 12; +//Same as MOVETYPE_FOLLOW but it doesn't take owner's angles into account +//e.g. entity will not rotate around owner. + +//TEI_SHOWLMP2 +//IDEA: Tei +void (string slot, string picfile, float x, float y, float org, entity to) ShowPicEnt = #108; //Show pic to player +void (string slot, entity to) HidePicEnt = #109; //Hide pic from player +//Shows/hides pics to/from the player. +//You can do fantastic huds with it, but don't forget it's better to use it only in singleplayer. +//Cause netplay will suck. + +//TQ_DLIGHTS +//IDEA: Tomaz +//field definition: +.float glow_size; +.float glow_red; +.float glow_green; +.float glow_blue; +//Customizable glowing light effect on the entity, glow_red, glow_green and glow_blue is the color in the range 0-1. +//glow_size is is the size of the glow (duh) in the range 0-1024. + +//TQ_PLASMA +//IDEA: Tomaz +//temp entity definitions: +float TE_PLASMA = 16; +//New weapon effect. + +//TQ_RAILTRAIL +//IDEA: id Software, code by TerribleOne modified by Tomaz +//temp entity definitions: +float TE_RAILTRAIL = 17; +//New weapontrail effect. + +//TQ_SLOWMO +//IDEA: Tomaz +//Same as DP_SV_SLOWMO + +//TW_SV_STEPCONTROL +//idea: Transfusion +//darkplaces implementation: LordHavoc +//cvars: +//sv_jumpstep (0/1, default 1) +//sv_stepheight (default 18) +//description: +//sv_jumpstep allows stepping up onto stairs while airborn, sv_stepheight controls how high a single step can be. + + + + + + +//ZQ_QC_CHECKBUILTIN +//IDEA: Tonik +float(float num, ...) checkbuiltin = #23040; +float(float first, float last) checkbuiltinrange = #23041; +//ZQuake (and Betwix :) provides a way to check for the presence of a QC extension by builtin number rather than by name. E.g. to see if the engine supports DP_QC_TRACEBOX (builtin #90), you can use +// if (checkbuiltin(90)) {...} +//instead of +// if (checkextension("DP_QC_TRACEBOX")) {...} +//Several (up to 8) extension numbers may be checked in one call to checkbuiltin(). TRUE will be returned if all of the extensions are supported, FALSE otherwise. +//E.g. +// if (checkbuiltin(94,95,96)) {...} +//is equivalent to +// if (checkextension("DP_QC_MINMAXBOUND")) {...} +//Another way to check several contiguous builtin numbers in one call: +// if (checkbuiltinrange(94,96)) {...} + + + + + + diff --git a/quakec/csqctest/src/optsall.qc b/quakec/csqctest/src/optsall.qc new file mode 100644 index 000000000..599e045b5 --- /dev/null +++ b/quakec/csqctest/src/optsall.qc @@ -0,0 +1,2 @@ +//#define WORKINDP +#define OWNPLAYERPHYSICS diff --git a/quakec/csqctest/src/optscsqc.qc b/quakec/csqctest/src/optscsqc.qc new file mode 100644 index 000000000..97eda0c2c --- /dev/null +++ b/quakec/csqctest/src/optscsqc.qc @@ -0,0 +1 @@ +#define CSQC \ No newline at end of file diff --git a/quakec/csqctest/src/optsmenu.qc b/quakec/csqctest/src/optsmenu.qc new file mode 100644 index 000000000..571445494 --- /dev/null +++ b/quakec/csqctest/src/optsmenu.qc @@ -0,0 +1 @@ +#define MENU \ No newline at end of file diff --git a/quakec/csqctest/src/optsssqc.qc b/quakec/csqctest/src/optsssqc.qc new file mode 100644 index 000000000..08061b05c --- /dev/null +++ b/quakec/csqctest/src/optsssqc.qc @@ -0,0 +1 @@ +#define SSQC \ No newline at end of file diff --git a/quakec/csqctest/src/ss/ai.qc b/quakec/csqctest/src/ss/ai.qc new file mode 100644 index 000000000..e0b2b8bf5 --- /dev/null +++ b/quakec/csqctest/src/ss/ai.qc @@ -0,0 +1,750 @@ +void() movetarget_f; +void() t_movetarget; +void() knight_walk1; +//void() knight_bow6; +//void() knight_bow1; +void(entity etemp, entity stemp, entity stemp, float dmg) T_Damage; +/* + +.enemy +Will be world if not currently angry at anyone. + +.movetarget +The next path spot to walk toward. If .enemy, ignore .movetarget. +When an enemy is killed, the monster will try to return to it's path. + +.huntt_ime +Set to time + something when the player is in sight, but movement straight for +him is blocked. This causes the monster to use wall following code for +movement direction instead of sighting on the player. + +.ideal_yaw +A yaw angle of the intended direction, which will be turned towards at up +to 45 deg / state. If the enemy is in view and hunt_time is not active, +this will be the exact line towards the enemy. + +.pausetime +A monster will leave it's stand state and head towards it's .movetarget when +time > .pausetime. + +walkmove(angle, speed) primitive is all or nothing +*/ + + +// +// globals +// + +// +// when a monster becomes angry at a player, that monster will be used +// as the sight target the next frame so that monsters near that one +// will wake up even if they wouldn't have noticed the player +// +entity sight_entity; +float sight_entity_time; + +float(float v) anglemod = +{ + while (v >= 360) + v = v - 360; + while (v < 0) + v = v + 360; + return v; +}; + +/* +============================================================================== + +MOVETARGET CODE + +The angle of the movetarget effects standing and bowing direction, but has no effect on movement, which allways heads to the next target. + +targetname +must be present. The name of this movetarget. + +target +the next spot to move to. If not present, stop here for good. + +pausetime +The number of seconds to spend standing or bowing for path_stand or path_bow + +============================================================================== +*/ + + +void() movetarget_f = +{ + if (!self.targetname) + objerror ("monster_movetarget: no targetname"); + + self.solid = SOLID_TRIGGER; + self.touch = t_movetarget; + setsize (self, '-8 -8 -8', '8 8 8'); + +}; + +/*QUAKED path_corner (0.5 0.3 0) (-8 -8 -8) (8 8 8) +Monsters will continue walking towards the next target corner. +*/ +void() path_corner = +{ + movetarget_f (); +}; + + +/* +============= +t_movetarget + +Something has bumped into a movetarget. If it is a monster +moving towards it, change the next destination and continue. +============== +*/ +void() t_movetarget = +{ +local entity temp; + + if (other.movetarget != self) + return; + + if (other.enemy) + return; // fighting, not following a path + + temp = self; + self = other; + other = temp; + + if (self.classname == "monster_ogre") + sound (self, CHAN_VOICE, "ogre/ogdrag.wav", 1, ATTN_IDLE);// play chainsaw drag sound + +//dprint ("t_movetarget\n"); + self.goalentity = self.movetarget = find (world, targetname, other.target); + self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin); + if (!self.movetarget) + { + self.pausetime = time + 999999; + self.th_stand (); + return; + } +}; + + + +//============================================================================ + +/* +============= +range + +returns the range catagorization of an entity reletive to self +0 melee range, will become hostile even if back is turned +1 visibility and infront, or visibility and show hostile +2 infront and show hostile +3 only triggered by damage +============= +*/ +float(entity targ) range = +{ +local vector spot1, spot2; +local float r; + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + + r = vlen (spot1 - spot2); + if (r < 120) + return RANGE_MELEE; + if (r < 500) + return RANGE_NEAR; + if (r < 1000) + return RANGE_MID; + return RANGE_FAR; +}; + +/* +============= +visible + +returns 1 if the entity is visible to self, even if not infront () +============= +*/ +float (entity targ) visible = +{ + local vector spot1, spot2; + + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + traceline (spot1, spot2, TRUE, self); // see through other monsters + + if (trace_inopen && trace_inwater) + return FALSE; // sight line crossed contents + + if (trace_fraction == 1) + return TRUE; + return FALSE; +}; + + +/* +============= +infront + +returns 1 if the entity is in front (in sight) of self +============= +*/ +float(entity targ) infront = +{ + local vector vec; + local float dot; + + makevectors (self.angles); + vec = normalize (targ.origin - self.origin); + dot = vec * v_forward; + + if ( dot > 0.3) + { + return TRUE; + } + return FALSE; +}; + + +//============================================================================ + +/* +=========== +ChangeYaw + +Turns towards self.ideal_yaw at self.yaw_speed +Sets the global variable current_yaw +Called every 0.1 sec by monsters +============ +*/ +/* + +void() ChangeYaw = +{ + local float ideal, move; + +//current_yaw = self.ideal_yaw; +// mod down the current angle + current_yaw = anglemod( self.angles_y ); + ideal = self.ideal_yaw; + + if (current_yaw == ideal) + return; + + move = ideal - current_yaw; + if (ideal > current_yaw) + { + if (move > 180) + move = move - 360; + } + else + { + if (move < -180) + move = move + 360; + } + + if (move > 0) + { + if (move > self.yaw_speed) + move = self.yaw_speed; + } + else + { + if (move < 0-self.yaw_speed ) + move = 0-self.yaw_speed; + } + + current_yaw = anglemod (current_yaw + move); + + self.angles_y = current_yaw; +}; + +*/ + + +//============================================================================ + +void() HuntTarget = +{ + self.goalentity = self.enemy; + self.think = self.th_run; + self.ideal_yaw = vectoyaw(self.enemy.origin - self.origin); + self.nextthink = time + 0.1; + SUB_AttackFinished (1); // wait a while before first attack +}; + +void() SightSound = +{ +local float rsnd; + + if (self.classname == "monster_ogre") + sound (self, CHAN_VOICE, "ogre/ogwake.wav", 1, ATTN_NORM); + else if (self.classname == "monster_knight") + sound (self, CHAN_VOICE, "knight/ksight.wav", 1, ATTN_NORM); + else if (self.classname == "monster_shambler") + sound (self, CHAN_VOICE, "shambler/ssight.wav", 1, ATTN_NORM); + else if (self.classname == "monster_demon1") + sound (self, CHAN_VOICE, "demon/sight2.wav", 1, ATTN_NORM); + else if (self.classname == "monster_wizard") + sound (self, CHAN_VOICE, "wizard/wsight.wav", 1, ATTN_NORM); + else if (self.classname == "monster_zombie") + sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_NORM); + else if (self.classname == "monster_dog") + sound (self, CHAN_VOICE, "dog/dsight.wav", 1, ATTN_NORM); + else if (self.classname == "monster_hell_knight") + sound (self, CHAN_VOICE, "hknight/sight1.wav", 1, ATTN_NORM); + else if (self.classname == "monster_tarbaby") + sound (self, CHAN_VOICE, "blob/sight1.wav", 1, ATTN_NORM); + else if (self.classname == "monster_vomit") + sound (self, CHAN_VOICE, "vomitus/v_sight1.wav", 1, ATTN_NORM); + else if (self.classname == "monster_enforcer") + { + rsnd = rint(random() * 3); + if (rsnd == 1) + sound (self, CHAN_VOICE, "enforcer/sight1.wav", 1, ATTN_NORM); + else if (rsnd == 2) + sound (self, CHAN_VOICE, "enforcer/sight2.wav", 1, ATTN_NORM); + else if (rsnd == 0) + sound (self, CHAN_VOICE, "enforcer/sight3.wav", 1, ATTN_NORM); + else + sound (self, CHAN_VOICE, "enforcer/sight4.wav", 1, ATTN_NORM); + } + else if (self.classname == "monster_army") + sound (self, CHAN_VOICE, "soldier/sight1.wav", 1, ATTN_NORM); + else if (self.classname == "monster_shalrath") + sound (self, CHAN_VOICE, "shalrath/sight.wav", 1, ATTN_NORM); +}; + +void() FoundTarget = +{ + if (self.enemy.classname == "player") + { // let other monsters see this monster for a while + sight_entity = self; + sight_entity_time = time; + } + + self.show_hostile = time + 1; // wake up other monsters + + SightSound (); + HuntTarget (); +}; + +/* +=========== +FindTarget + +Self is currently not attacking anything, so try to find a target + +Returns TRUE if an enemy was sighted + +When a player fires a missile, the point of impact becomes a fakeplayer so +that monsters that see the impact will respond as if they had seen the +player. + +To avoid spending too much time, only a single client (or fakeclient) is +checked each frame. This means multi player games will have slightly +slower noticing monsters. +============ +*/ +float() FindTarget = +{ + local entity client; + local float r; + +// if the first spawnflag bit is set, the monster will only wake up on +// really seeing the player, not another monster getting angry + +// spawnflags & 3 is a big hack, because zombie crucified used the first +// spawn flag prior to the ambush flag, and I forgot about it, so the second +// spawn flag works as well + if (sight_entity_time >= time - 0.1 && !(self.spawnflags & 3) ) + { + client = sight_entity; + if (client.enemy == self.enemy) + return FALSE; + } + else + { + client = checkclient (); + if (!client) + return FALSE; // current check entity isn't in PVS + } + + if (client == self.enemy) + return FALSE; + + if (client.flags & FL_NOTARGET) + return FALSE; + if (client.items & IT_INVISIBILITY) + return FALSE; + + r = range (client); + if (r == RANGE_FAR) + return FALSE; + + if (!visible (client)) + return FALSE; + + if (r == RANGE_NEAR) + { + if (client.show_hostile < time && !infront (client)) + return FALSE; + } + else if (r == RANGE_MID) + { + if ( /* client.show_hostile < time || */ !infront (client)) + return FALSE; + } + +// +// got one +// + self.enemy = client; + if (self.enemy.classname != "player") + { + self.enemy = self.enemy.enemy; + if (self.enemy.classname != "player") + { + self.enemy = world; + return FALSE; + } + } + + FoundTarget (); + + return TRUE; +}; + + +//============================================================================= + +void(float dist) ai_forward = +{ + walkmove (self.angles_y, dist); +}; + +void(float dist) ai_back = +{ + walkmove ( (self.angles_y+180), dist); +}; + + +/* +============= +ai_pain + +stagger back a bit +============= +*/ +void(float dist) ai_pain = +{ + self.Version++; //if nothing else happened, we animated. + + ai_back (dist); +/* + local float away; + + away = anglemod (vectoyaw (self.origin - self.enemy.origin) + + 180*(random()- 0.5) ); + + walkmove (away, dist); +*/ +}; + +/* +============= +ai_painforward + +stagger back a bit +============= +*/ +void(float dist) ai_painforward = +{ + self.Version++; //if nothing else happened, we animated. + + walkmove (self.ideal_yaw, dist); +}; + +/* +============= +ai_walk + +The monster is walking it's beat +============= +*/ +void(float dist) ai_walk = +{ + self.Version++; //if nothing else happened, we animated. + + movedist = dist; + + if (self.classname == "monster_dragon") + { + movetogoal (dist); + return; + } + // check for noticing a player + if (FindTarget ()) + return; + + movetogoal (dist); +}; + + +/* +============= +ai_stand + +The monster is staying in one place for a while, with slight angle turns +============= +*/ +void() ai_stand = +{ + self.Version++; //if nothing else happened, we animated. + + if (FindTarget ()) + return; + + if (time > self.pausetime) + { + self.th_walk (); + return; + } + +// change angle slightly + +}; + +/* +============= +ai_turn + +don't move, but turn towards ideal_yaw +============= +*/ +void() ai_turn = +{ + if (FindTarget ()) + return; + + ChangeYaw (); +}; + +//============================================================================= + +/* +============= +ChooseTurn +============= +*/ +void(vector dest3) ChooseTurn = +{ + local vector dir, newdir; + + dir = self.origin - dest3; + + newdir_x = trace_plane_normal_y; + newdir_y = 0 - trace_plane_normal_x; + newdir_z = 0; + + if (dir * newdir > 0) + { + dir_x = 0 - trace_plane_normal_y; + dir_y = trace_plane_normal_x; + } + else + { + dir_x = trace_plane_normal_y; + dir_y = 0 - trace_plane_normal_x; + } + + dir_z = 0; + self.ideal_yaw = vectoyaw(dir); +}; + +/* +============ +FacingIdeal + +============ +*/ +float() FacingIdeal = +{ + local float delta; + + delta = anglemod(self.angles_y - self.ideal_yaw); + if (delta > 45 && delta < 315) + return FALSE; + return TRUE; +}; + + +//============================================================================= + +float() WizardCheckAttack; +float() DogCheckAttack; + +float() CheckAnyAttack = +{ + if (!enemy_vis) + return FALSE; + if (self.classname == "monster_army") + return SoldierCheckAttack (); + if (self.classname == "monster_ogre") + return OgreCheckAttack (); + if (self.classname == "monster_shambler") + return ShamCheckAttack (); + if (self.classname == "monster_demon1") + return DemonCheckAttack (); + if (self.classname == "monster_dog") + return DogCheckAttack (); + if (self.classname == "monster_wizard") + return WizardCheckAttack (); + return CheckAttack (); +}; + + +/* +============= +ai_run_melee + +Turn and close until within an angle to launch a melee attack +============= +*/ +void() ai_run_melee = +{ + self.ideal_yaw = enemy_yaw; + ChangeYaw (); + + if (FacingIdeal()) + { + self.th_melee (); + self.attack_state = AS_STRAIGHT; + } +}; + + +/* +============= +ai_run_missile + +Turn in place until within an angle to launch a missile attack +============= +*/ +void() ai_run_missile = +{ + self.ideal_yaw = enemy_yaw; + ChangeYaw (); + if (FacingIdeal()) + { + self.th_missile (); + self.attack_state = AS_STRAIGHT; + } +}; + + +/* +============= +ai_run_slide + +Strafe sideways, but stay at aproximately the same range +============= +*/ +void() ai_run_slide = +{ + local float ofs; + + self.ideal_yaw = enemy_yaw; + ChangeYaw (); + if (self.lefty) + ofs = 90; + else + ofs = -90; + + if (walkmove (self.ideal_yaw + ofs, movedist)) + return; + + self.lefty = 1 - self.lefty; + + walkmove (self.ideal_yaw - ofs, movedist); +}; + + +/* +============= +ai_run + +The monster has an enemy it is trying to kill +============= +*/ +void(float dist) ai_run = +{ + self.Version++; //if nothing else happened, we animated. + + movedist = dist; +// see if the enemy is dead + if (self.enemy.health <= 0) + { + self.enemy = world; + // FIXME: look all around for other targets + if (self.oldenemy.health > 0) + { + self.enemy = self.oldenemy; + HuntTarget (); + } + else + { + if (self.movetarget) + self.th_walk (); + else + self.th_stand (); + return; + } + } + + self.show_hostile = time + 1; // wake up other monsters + +// check knowledge of enemy + enemy_vis = visible(self.enemy); + if (enemy_vis) + self.search_time = time + 5; + +// look for other coop players + if (coop && self.search_time < time) + { + if (FindTarget ()) + return; + } + + enemy_infront = infront(self.enemy); + enemy_range = range(self.enemy); + enemy_yaw = vectoyaw(self.enemy.origin - self.origin); + + if (self.attack_state == AS_MISSILE) + { +//dprint ("ai_run_missile\n"); + ai_run_missile (); + return; + } + if (self.attack_state == AS_MELEE) + { +//dprint ("ai_run_melee\n"); + ai_run_melee (); + return; + } + + if (CheckAnyAttack ()) + return; // beginning an attack + + if (self.attack_state == AS_SLIDING) + { + ai_run_slide (); + return; + } + +// head straight in + movetogoal (dist); // done in C code... +}; + diff --git a/quakec/csqctest/src/ss/boss.qc b/quakec/csqctest/src/ss/boss.qc new file mode 100644 index 000000000..949de52db --- /dev/null +++ b/quakec/csqctest/src/ss/boss.qc @@ -0,0 +1,385 @@ +/* +============================================================================== + +BOSS-ONE + +============================================================================== +*/ +$cd id1/models/boss1 +$origin 0 0 -15 +$base base +$skin skin +$scale 5 + +$frame rise1 rise2 rise3 rise4 rise5 rise6 rise7 rise8 rise9 rise10 +$frame rise11 rise12 rise13 rise14 rise15 rise16 rise17 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 +$frame walk9 walk10 walk11 walk12 walk13 walk14 walk15 +$frame walk16 walk17 walk18 walk19 walk20 walk21 walk22 +$frame walk23 walk24 walk25 walk26 walk27 walk28 walk29 walk30 walk31 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 death9 + +$frame attack1 attack2 attack3 attack4 attack5 attack6 attack7 attack8 +$frame attack9 attack10 attack11 attack12 attack13 attack14 attack15 +$frame attack16 attack17 attack18 attack19 attack20 attack21 attack22 +$frame attack23 + +$frame shocka1 shocka2 shocka3 shocka4 shocka5 shocka6 shocka7 shocka8 +$frame shocka9 shocka10 + +$frame shockb1 shockb2 shockb3 shockb4 shockb5 shockb6 + +$frame shockc1 shockc2 shockc3 shockc4 shockc5 shockc6 shockc7 shockc8 +$frame shockc9 shockc10 + + +void(vector p) boss_missile; + +void() boss_face = +{ + +// go for another player if multi player + if (self.enemy.health <= 0 || random() < 0.02) + { + self.enemy = find(self.enemy, classname, "player"); + if (!self.enemy) + self.enemy = find(self.enemy, classname, "player"); + } + ai_face(); +}; + +void() boss_rise1 =[ $rise1, boss_rise2 ] { +sound (self, CHAN_WEAPON, "boss1/out1.wav", 1, ATTN_NORM); +}; +void() boss_rise2 =[ $rise2, boss_rise3 ] { +sound (self, CHAN_VOICE, "boss1/sight1.wav", 1, ATTN_NORM); +}; +void() boss_rise3 =[ $rise3, boss_rise4 ] {}; +void() boss_rise4 =[ $rise4, boss_rise5 ] {}; +void() boss_rise5 =[ $rise5, boss_rise6 ] {}; +void() boss_rise6 =[ $rise6, boss_rise7 ] {}; +void() boss_rise7 =[ $rise7, boss_rise8 ] {}; +void() boss_rise8 =[ $rise8, boss_rise9 ] {}; +void() boss_rise9 =[ $rise9, boss_rise10 ] {}; +void() boss_rise10 =[ $rise10, boss_rise11 ] {}; +void() boss_rise11 =[ $rise11, boss_rise12 ] {}; +void() boss_rise12 =[ $rise12, boss_rise13 ] {}; +void() boss_rise13 =[ $rise13, boss_rise14 ] {}; +void() boss_rise14 =[ $rise14, boss_rise15 ] {}; +void() boss_rise15 =[ $rise15, boss_rise16 ] {}; +void() boss_rise16 =[ $rise16, boss_rise17 ] {}; +void() boss_rise17 =[ $rise17, boss_missile1 ] {}; + +void() boss_idle1 =[ $walk1, boss_idle2 ] +{ +// look for other players +}; +void() boss_idle2 =[ $walk2, boss_idle3 ] {boss_face();}; +void() boss_idle3 =[ $walk3, boss_idle4 ] {boss_face();}; +void() boss_idle4 =[ $walk4, boss_idle5 ] {boss_face();}; +void() boss_idle5 =[ $walk5, boss_idle6 ] {boss_face();}; +void() boss_idle6 =[ $walk6, boss_idle7 ] {boss_face();}; +void() boss_idle7 =[ $walk7, boss_idle8 ] {boss_face();}; +void() boss_idle8 =[ $walk8, boss_idle9 ] {boss_face();}; +void() boss_idle9 =[ $walk9, boss_idle10 ] {boss_face();}; +void() boss_idle10 =[ $walk10, boss_idle11 ] {boss_face();}; +void() boss_idle11 =[ $walk11, boss_idle12 ] {boss_face();}; +void() boss_idle12 =[ $walk12, boss_idle13 ] {boss_face();}; +void() boss_idle13 =[ $walk13, boss_idle14 ] {boss_face();}; +void() boss_idle14 =[ $walk14, boss_idle15 ] {boss_face();}; +void() boss_idle15 =[ $walk15, boss_idle16 ] {boss_face();}; +void() boss_idle16 =[ $walk16, boss_idle17 ] {boss_face();}; +void() boss_idle17 =[ $walk17, boss_idle18 ] {boss_face();}; +void() boss_idle18 =[ $walk18, boss_idle19 ] {boss_face();}; +void() boss_idle19 =[ $walk19, boss_idle20 ] {boss_face();}; +void() boss_idle20 =[ $walk20, boss_idle21 ] {boss_face();}; +void() boss_idle21 =[ $walk21, boss_idle22 ] {boss_face();}; +void() boss_idle22 =[ $walk22, boss_idle23 ] {boss_face();}; +void() boss_idle23 =[ $walk23, boss_idle24 ] {boss_face();}; +void() boss_idle24 =[ $walk24, boss_idle25 ] {boss_face();}; +void() boss_idle25 =[ $walk25, boss_idle26 ] {boss_face();}; +void() boss_idle26 =[ $walk26, boss_idle27 ] {boss_face();}; +void() boss_idle27 =[ $walk27, boss_idle28 ] {boss_face();}; +void() boss_idle28 =[ $walk28, boss_idle29 ] {boss_face();}; +void() boss_idle29 =[ $walk29, boss_idle30 ] {boss_face();}; +void() boss_idle30 =[ $walk30, boss_idle31 ] {boss_face();}; +void() boss_idle31 =[ $walk31, boss_idle1 ] {boss_face();}; + +void() boss_missile1 =[ $attack1, boss_missile2 ] {boss_face();}; +void() boss_missile2 =[ $attack2, boss_missile3 ] {boss_face();}; +void() boss_missile3 =[ $attack3, boss_missile4 ] {boss_face();}; +void() boss_missile4 =[ $attack4, boss_missile5 ] {boss_face();}; +void() boss_missile5 =[ $attack5, boss_missile6 ] {boss_face();}; +void() boss_missile6 =[ $attack6, boss_missile7 ] {boss_face();}; +void() boss_missile7 =[ $attack7, boss_missile8 ] {boss_face();}; +void() boss_missile8 =[ $attack8, boss_missile9 ] {boss_face();}; +void() boss_missile9 =[ $attack9, boss_missile10 ] {boss_missile('100 100 200');}; +void() boss_missile10 =[ $attack10, boss_missile11 ] {boss_face();}; +void() boss_missile11 =[ $attack11, boss_missile12 ] {boss_face();}; +void() boss_missile12 =[ $attack12, boss_missile13 ] {boss_face();}; +void() boss_missile13 =[ $attack13, boss_missile14 ] {boss_face();}; +void() boss_missile14 =[ $attack14, boss_missile15 ] {boss_face();}; +void() boss_missile15 =[ $attack15, boss_missile16 ] {boss_face();}; +void() boss_missile16 =[ $attack16, boss_missile17 ] {boss_face();}; +void() boss_missile17 =[ $attack17, boss_missile18 ] {boss_face();}; +void() boss_missile18 =[ $attack18, boss_missile19 ] {boss_face();}; +void() boss_missile19 =[ $attack19, boss_missile20 ] {boss_face();}; +void() boss_missile20 =[ $attack20, boss_missile21 ] {boss_missile('100 -100 200');}; +void() boss_missile21 =[ $attack21, boss_missile22 ] {boss_face();}; +void() boss_missile22 =[ $attack22, boss_missile23 ] {boss_face();}; +void() boss_missile23 =[ $attack23, boss_missile1 ] {boss_face();}; + +void() boss_shocka1 =[ $shocka1, boss_shocka2 ] {}; +void() boss_shocka2 =[ $shocka2, boss_shocka3 ] {}; +void() boss_shocka3 =[ $shocka3, boss_shocka4 ] {}; +void() boss_shocka4 =[ $shocka4, boss_shocka5 ] {}; +void() boss_shocka5 =[ $shocka5, boss_shocka6 ] {}; +void() boss_shocka6 =[ $shocka6, boss_shocka7 ] {}; +void() boss_shocka7 =[ $shocka7, boss_shocka8 ] {}; +void() boss_shocka8 =[ $shocka8, boss_shocka9 ] {}; +void() boss_shocka9 =[ $shocka9, boss_shocka10 ] {}; +void() boss_shocka10 =[ $shocka10, boss_missile1 ] {}; + +void() boss_shockb1 =[ $shockb1, boss_shockb2 ] {}; +void() boss_shockb2 =[ $shockb2, boss_shockb3 ] {}; +void() boss_shockb3 =[ $shockb3, boss_shockb4 ] {}; +void() boss_shockb4 =[ $shockb4, boss_shockb5 ] {}; +void() boss_shockb5 =[ $shockb5, boss_shockb6 ] {}; +void() boss_shockb6 =[ $shockb6, boss_shockb7 ] {}; +void() boss_shockb7 =[ $shockb1, boss_shockb8 ] {}; +void() boss_shockb8 =[ $shockb2, boss_shockb9 ] {}; +void() boss_shockb9 =[ $shockb3, boss_shockb10 ] {}; +void() boss_shockb10 =[ $shockb4, boss_missile1 ] {}; + +void() boss_shockc1 =[ $shockc1, boss_shockc2 ] {}; +void() boss_shockc2 =[ $shockc2, boss_shockc3 ] {}; +void() boss_shockc3 =[ $shockc3, boss_shockc4 ] {}; +void() boss_shockc4 =[ $shockc4, boss_shockc5 ] {}; +void() boss_shockc5 =[ $shockc5, boss_shockc6 ] {}; +void() boss_shockc6 =[ $shockc6, boss_shockc7 ] {}; +void() boss_shockc7 =[ $shockc7, boss_shockc8 ] {}; +void() boss_shockc8 =[ $shockc8, boss_shockc9 ] {}; +void() boss_shockc9 =[ $shockc9, boss_shockc10 ] {}; +void() boss_shockc10 =[ $shockc10, boss_death1 ] {}; + +void() boss_death1 = [$death1, boss_death2] { +sound (self, CHAN_VOICE, "boss1/death.wav", 1, ATTN_NORM); +}; +void() boss_death2 = [$death2, boss_death3] {}; +void() boss_death3 = [$death3, boss_death4] {}; +void() boss_death4 = [$death4, boss_death5] {}; +void() boss_death5 = [$death5, boss_death6] {}; +void() boss_death6 = [$death6, boss_death7] {}; +void() boss_death7 = [$death7, boss_death8] {}; +void() boss_death8 = [$death8, boss_death9] {}; +void() boss_death9 = [$death9, boss_death10] +{ + sound (self, CHAN_BODY, "boss1/out1.wav", 1, ATTN_NORM); + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_LAVASPLASH); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); +}; + +void() boss_death10 = [$death9, boss_death10] +{ + killed_monsters = killed_monsters + 1; + WriteByte (MSG_ALL, SVC_KILLEDMONSTER); // FIXME: reliable broadcast + SUB_UseTargets (); + remove (self); +}; + +void(vector p) boss_missile = +{ + local vector offang; + local vector org, vec, d; + local float t; + + offang = vectoangles (self.enemy.origin - self.origin); + makevectors (offang); + + org = self.origin + p_x*v_forward + p_y*v_right + p_z*'0 0 1'; + +// lead the player on hard mode + if (skill > 1) + { + t = vlen(self.enemy.origin - org) / 300; + vec = self.enemy.velocity; + vec_z = 0; + d = self.enemy.origin + t * vec; + } + else + { + d = self.enemy.origin; + } + + vec = normalize (d - org); + + launch_spike (org, vec); + setmodel (newmis, "progs/lavaball.mdl"); + newmis.avelocity = '200 100 300'; + setsize (newmis, VEC_ORIGIN, VEC_ORIGIN); + newmis.velocity = vec*300; + newmis.touch = T_MissileTouch; // rocket explosion + sound (self, CHAN_WEAPON, "boss1/throw.wav", 1, ATTN_NORM); + +// check for dead enemy + if (self.enemy.health <= 0) + boss_idle1 (); +}; + + +void() boss_awake = +{ + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + self.takedamage = DAMAGE_NO; + + setmodel (self, "progs/boss.mdl"); + setsize (self, '-128 -128 -24', '128 128 256'); + + if (skill == 0) + self.health = 1; + else + self.health = 3; + + self.enemy = activator; + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_LAVASPLASH); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + + self.yaw_speed = 20; + boss_rise1 (); +}; + + +/*QUAKED monster_boss (1 0 0) (-128 -128 -24) (128 128 256) +*/ +void() monster_boss = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/boss.mdl"); + precache_model ("progs/lavaball.mdl"); + + precache_sound ("weapons/rocket1i.wav"); + precache_sound ("boss1/out1.wav"); + precache_sound ("boss1/sight1.wav"); + precache_sound ("misc/power.wav"); + precache_sound ("boss1/throw.wav"); + precache_sound ("boss1/pain.wav"); + precache_sound ("boss1/death.wav"); + + total_monsters = total_monsters + 1; + + self.use = boss_awake; +}; + +//=========================================================================== + +entity le1, le2; +float lightning_end; + +void() lightning_fire = +{ + local vector p1, p2; + + if (time >= lightning_end) + { // done here, put the terminals back up + self = le1; + door_go_down (); + self = le2; + door_go_down (); + return; + } + + p1 = (le1.mins + le1.maxs) * 0.5; + p1_z = le1.absmin_z - 16; + + p2 = (le2.mins + le2.maxs) * 0.5; + p2_z = le2.absmin_z - 16; + + // compensate for length of bolt + p2 = p2 - normalize(p2-p1)*100; + + self.nextthink = time + 0.1; + self.think = lightning_fire; + + WriteByte (MSG_ALL, SVC_TEMPENTITY); + WriteByte (MSG_ALL, TE_LIGHTNING3); + WriteEntity (MSG_ALL, world); + WriteCoord (MSG_ALL, p1_x); + WriteCoord (MSG_ALL, p1_y); + WriteCoord (MSG_ALL, p1_z); + WriteCoord (MSG_ALL, p2_x); + WriteCoord (MSG_ALL, p2_y); + WriteCoord (MSG_ALL, p2_z); +}; + +void() lightning_use = +{ + if (lightning_end >= time + 1) + return; + + le1 = find( world, target, "lightning"); + le2 = find( le1, target, "lightning"); + if (!le1 || !le2) + { + dprint ("missing lightning targets\n"); + return; + } + + if ( + (le1.state != STATE_TOP && le1.state != STATE_BOTTOM) + || (le2.state != STATE_TOP && le2.state != STATE_BOTTOM) + || (le1.state != le2.state) ) + { +// dprint ("not aligned\n"); + return; + } + +// don't let the electrodes go back up until the bolt is done + le1.nextthink = -1; + le2.nextthink = -1; + lightning_end = time + 1; + + sound (self, CHAN_VOICE, "misc/power.wav", 1, ATTN_NORM); + lightning_fire (); + +// advance the boss pain if down + self = find (world, classname, "monster_boss"); + if (!self) + return; + self.enemy = activator; + if (le1.state == STATE_TOP && self.health > 0) + { + sound (self, CHAN_VOICE, "boss1/pain.wav", 1, ATTN_NORM); + self.health = self.health - 1; + if (self.health >= 2) + boss_shocka1(); + else if (self.health == 1) + boss_shockb1(); + else if (self.health == 0) + boss_shockc1(); + } +}; + + +/*QUAKED event_lightning (0 1 1) (-16 -16 -16) (16 16 16) +Just for boss level. +*/ +void() event_lightning = +{ + self.use = lightning_use; +}; + + diff --git a/quakec/csqctest/src/ss/builtins.qc b/quakec/csqctest/src/ss/builtins.qc new file mode 100644 index 000000000..7cb812b03 --- /dev/null +++ b/quakec/csqctest/src/ss/builtins.qc @@ -0,0 +1,43 @@ +//server only builtins. + +entity() checkclient = #17; // returns a client to look for + +void(string s) bprint = #23; +void(entity client, string s) sprint = #24; + +float(float yaw, float dist) walkmove = #32; // returns TRUE or FALSE +void(float style, string value) lightstyle = #35; +float(entity e) checkbottom = #40; // true if self is on ground + +vector(entity e, float speed) aim = #44; // returns the shooting vector + + +// +// direct client message generation +// +void(float to, float f) WriteByte = #52; +void(float to, float f) WriteChar = #53; +void(float to, float f) WriteShort = #54; +void(float to, float f) WriteLong = #55; +void(float to, float f) WriteCoord = #56; +void(float to, float f) WriteAngle = #57; +void(float to, string s) WriteString = #58; +void(float to, entity s) WriteEntity = #59; + +void(float step) movetogoal = #67; + +void(entity e) makestatic = #69; + + + +void(entity client, string s) centerprint = #73; // sprint, but in middle +void(vector pos, string samp, float vol, float atten) ambientsound = #74; +void(string s) changelevel = #70; + +void(entity e) setspawnparms = #78; // set parm1... to the + // values at level start + // for coop respawn + + + + diff --git a/quakec/csqctest/src/ss/buttons.qc b/quakec/csqctest/src/ss/buttons.qc new file mode 100644 index 000000000..695115b08 --- /dev/null +++ b/quakec/csqctest/src/ss/buttons.qc @@ -0,0 +1,139 @@ +// button and multiple button + +void() button_wait; +void() button_return; + +void() button_wait = +{ + self.state = STATE_TOP; + self.nextthink = self.ltime + self.wait; + self.think = button_return; + activator = self.enemy; + SUB_UseTargets(); + self.frame = 1; // use alternate textures +}; + +void() button_done = +{ + self.state = STATE_BOTTOM; +}; + +void() button_return = +{ + self.state = STATE_DOWN; + SUB_CalcMove (self.pos1, self.speed, button_done); + self.frame = 0; // use normal textures + if (self.health) + self.takedamage = DAMAGE_YES; // can be shot again +}; + + +void() button_blocked = +{ // do nothing, just don't ome all the way back out +}; + + +void() button_fire = +{ + if (self.state == STATE_UP || self.state == STATE_TOP) + return; + + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM); + + self.state = STATE_UP; + SUB_CalcMove (self.pos2, self.speed, button_wait); +}; + + +void() button_use = +{ + self.enemy = activator; + button_fire (); +}; + +void() button_touch = +{ + if (other.classname != "player") + return; + self.enemy = other; + button_fire (); +}; + +void() button_killed = +{ + self.enemy = damage_attacker; + self.health = self.max_health; + self.takedamage = DAMAGE_NO; // wil be reset upon return + button_fire (); +}; + + +/*QUAKED func_button (0 .5 .8) ? +When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again. + +"angle" determines the opening direction +"target" all entities with a matching targetname will be used +"speed" override the default 40 speed +"wait" override the default 1 second wait (-1 = never return) +"lip" override the default 4 pixel lip remaining at end of move +"health" if set, the button must be killed instead of touched +"sounds" +0) steam metal +1) wooden clunk +2) metallic click +3) in-out +*/ +void() func_button = +{ + if (self.sounds == 0) + { + precache_sound ("buttons/airbut1.wav"); + self.noise = "buttons/airbut1.wav"; + } + if (self.sounds == 1) + { + precache_sound ("buttons/switch21.wav"); + self.noise = "buttons/switch21.wav"; + } + if (self.sounds == 2) + { + precache_sound ("buttons/switch02.wav"); + self.noise = "buttons/switch02.wav"; + } + if (self.sounds == 3) + { + precache_sound ("buttons/switch04.wav"); + self.noise = "buttons/switch04.wav"; + } + + SetMovedir (); + + self.movetype = MOVETYPE_PUSH; + self.solid = SOLID_BSP; + setmodel (self, self.model); + + self.blocked = button_blocked; + self.use = button_use; + + if (self.health) + { + self.max_health = self.health; + self.th_die = button_killed; + self.takedamage = DAMAGE_YES; + } + else + self.touch = button_touch; + + if (!self.speed) + self.speed = 40; + if (!self.wait) + self.wait = 1; + if (!self.lip) + self.lip = 4; + + self.state = STATE_BOTTOM; + + self.pos1 = self.origin; + self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip); +}; + diff --git a/quakec/csqctest/src/ss/client.qc b/quakec/csqctest/src/ss/client.qc new file mode 100644 index 000000000..6be66ff65 --- /dev/null +++ b/quakec/csqctest/src/ss/client.qc @@ -0,0 +1,1606 @@ + +// prototypes +void () W_WeaponFrame; +void() W_SetCurrentAmmo; +void() player_pain; +void() player_stand1; +void (vector org) spawn_tfog; +void (vector org, entity death_owner) spawn_tdeath; + +float modelindex_eyes, modelindex_player; + +void() DefaultPlayerPhysics; + +.float usingcsqc; +.float lackofcsqckicktime; + +/* +============================================================================= + + LEVEL CHANGING / INTERMISSION + +============================================================================= +*/ + +float intermission_running; +float intermission_exittime; + +/*QUAKED info_intermission (1 0.5 0.5) (-16 -16 -16) (16 16 16) +This is the camera point for the intermission. +Use mangle instead of angle, so you can set pitch or roll as well as yaw. 'pitch roll yaw' +*/ +void() info_intermission = +{ +}; + + + +void() SetChangeParms = +{ + if (self.health <= 0) + { + SetNewParms (); + return; + } + +// remove items + self.items = self.items - (self.items & + (IT_KEY1 | IT_KEY2 | IT_INVISIBILITY | IT_INVULNERABILITY | IT_SUIT | IT_QUAD) ); + +// cap super health + if (self.health > 100) + self.health = 100; + if (self.health < 50) + self.health = 50; + parm1 = self.items; + parm2 = self.health; + parm3 = self.armorvalue; + if (self.ammo_shells < 25) + parm4 = 25; + else + parm4 = self.ammo_shells; + parm5 = self.ammo_nails; + parm6 = self.ammo_rockets; + parm7 = self.ammo_cells; + parm8 = self.weapon; + parm9 = self.armortype * 100; +}; + +void() SetNewParms = +{ + parm1 = IT_SHOTGUN | IT_AXE; + parm2 = 100; + parm3 = 0; + parm4 = 25; + parm5 = 0; + parm6 = 0; + parm7 = 0; + parm8 = 1; + parm9 = 0; +}; + +void() DecodeLevelParms = +{ + if (serverflags) + { + if (world.model == "maps/start.bsp") + SetNewParms (); // take away all stuff on starting new episode + } + + self.items = parm1; + self.health = parm2; + self.armorvalue = parm3; + self.ammo_shells = parm4; + self.ammo_nails = parm5; + self.ammo_rockets = parm6; + self.ammo_cells = parm7; + self.weapon = parm8; + self.armortype = parm9 * 0.01; +}; + +/* +============ +FindIntermission + +Returns the entity to view from +============ +*/ +entity() FindIntermission = +{ + local entity spot; + local float cyc; + +// look for info_intermission first + spot = find (world, classname, "info_intermission"); + if (spot) + { // pick a random one + cyc = random() * 4; + while (cyc > 1) + { + spot = find (spot, classname, "info_intermission"); + if (!spot) + spot = find (spot, classname, "info_intermission"); + cyc = cyc - 1; + } + return spot; + } + +// then look for the start position + spot = find (world, classname, "info_player_start"); + if (spot) + return spot; + +// testinfo_player_start is only found in regioned levels + spot = find (world, classname, "testplayerstart"); + if (spot) + return spot; + + objerror ("FindIntermission: no spot"); + return world; +}; + + +string nextmap; +void() GotoNextMap = +{ + if (cvar("samelevel")) // if samelevel is set, stay on same level + changelevel (mapname); + else + changelevel (nextmap); +}; + + +void() ExitIntermission = +{ +// skip any text in deathmatch + if (deathmatch) + { + GotoNextMap (); + return; + } + + intermission_exittime = time + 1; + intermission_running = intermission_running + 1; + +// +// run some text if at the end of an episode +// + if (intermission_running == 2) + { + if (world.model == "maps/e1m7.bsp") + { + WriteByte (MSG_ALL, SVC_CDTRACK); + WriteByte (MSG_ALL, 2); + WriteByte (MSG_ALL, 3); + if (!cvar("registered")) + { + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task in the other three\nhaunted lands of Quake. Or are you? If\nyou don't register Quake, you'll never\nknow what awaits you in the Realm of\nBlack Magic, the Netherworld, and the\nElder World!"); + } + else + { + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "As the corpse of the monstrous entity\nChthon sinks back into the lava whence\nit rose, you grip the Rune of Earth\nMagic tightly. Now that you have\nconquered the Dimension of the Doomed,\nrealm of Earth Magic, you are ready to\ncomplete your task. A Rune of magic\npower lies at the end of each haunted\nland of Quake. Go forth, seek the\ntotality of the four Runes!"); + } + return; + } + else if (world.model == "maps/e2m6.bsp") + { + WriteByte (MSG_ALL, SVC_CDTRACK); + WriteByte (MSG_ALL, 2); + WriteByte (MSG_ALL, 3); + + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "The Rune of Black Magic throbs evilly in\nyour hand and whispers dark thoughts\ninto your brain. You learn the inmost\nlore of the Hell-Mother; Shub-Niggurath!\nYou now know that she is behind all the\nterrible plotting which has led to so\nmuch death and horror. But she is not\ninviolate! Armed with this Rune, you\nrealize that once all four Runes are\ncombined, the gate to Shub-Niggurath's\nPit will open, and you can face the\nWitch-Goddess herself in her frightful\notherworld cathedral."); + return; + } + else if (world.model == "maps/e3m6.bsp") + { + WriteByte (MSG_ALL, SVC_CDTRACK); + WriteByte (MSG_ALL, 2); + WriteByte (MSG_ALL, 3); + + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "The charred viscera of diabolic horrors\nbubble viscously as you seize the Rune\nof Hell Magic. Its heat scorches your\nhand, and its terrible secrets blight\nyour mind. Gathering the shreds of your\ncourage, you shake the devil's shackles\nfrom your soul, and become ever more\nhard and determined to destroy the\nhideous creatures whose mere existence\nthreatens the souls and psyches of all\nthe population of Earth."); + return; + } + else if (world.model == "maps/e4m7.bsp") + { + WriteByte (MSG_ALL, SVC_CDTRACK); + WriteByte (MSG_ALL, 2); + WriteByte (MSG_ALL, 3); + + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "Despite the awful might of the Elder\nWorld, you have achieved the Rune of\nElder Magic, capstone of all types of\narcane wisdom. Beyond good and evil,\nbeyond life and death, the Rune\npulsates, heavy with import. Patient and\npotent, the Elder Being Shub-Niggurath\nweaves her dire plans to clear off all\nlife from the Earth, and bring her own\nfoul offspring to our world! For all the\ndwellers in these nightmare dimensions\nare her descendants! Once all Runes of\nmagic power are united, the energy\nbehind them will blast open the Gateway\nto Shub-Niggurath, and you can travel\nthere to foil the Hell-Mother's plots\nin person."); + return; + } + + GotoNextMap(); + } + + if (intermission_running == 3) + { + if (!cvar("registered")) + { // shareware episode has been completed, go to sell screen + WriteByte (MSG_ALL, SVC_SELLSCREEN); + return; + } + + if ( (serverflags&15) == 15) + { + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "Now, you have all four Runes. You sense\ntremendous invisible forces moving to\nunseal ancient barriers. Shub-Niggurath\nhad hoped to use the Runes Herself to\nclear off the Earth, but now instead,\nyou will use them to enter her home and\nconfront her as an avatar of avenging\nEarth-life. If you defeat her, you will\nbe remembered forever as the savior of\nthe planet. If she conquers, it will be\nas if you had never been born."); + return; + } + + } + + GotoNextMap(); +}; + +/* +============ +IntermissionThink + +When the player presses attack or jump, change to the next level +============ +*/ +void() IntermissionThink = +{ + if (time < intermission_exittime) + return; + + if (!self.button0 && !self.button1 && !self.button2) + return; + + ExitIntermission (); +}; + +void() execute_changelevel = +{ + local entity pos; + + intermission_running = 1; + +// enforce a wait time before allowing changelevel + if (deathmatch) + intermission_exittime = time + 5; + else + intermission_exittime = time + 2; + + WriteByte (MSG_ALL, SVC_CDTRACK); + WriteByte (MSG_ALL, 3); + WriteByte (MSG_ALL, 3); + + pos = FindIntermission (); + + other = find (world, classname, "player"); + while (other != world) + { + other.view_ofs = '0 0 0'; + other.angles = other.v_angle = pos.mangle; + other.fixangle = TRUE; // turn this way immediately + other.nextthink = time + 0.5; + other.takedamage = DAMAGE_NO; + other.solid = SOLID_NOT; + other.movetype = MOVETYPE_NONE; + other.modelindex = 0; + setorigin (other, pos.origin); + other = find (other, classname, "player"); + } + + WriteByte (MSG_ALL, SVC_INTERMISSION); +}; + + +void() changelevel_touch = +{ + if (other.classname != "player") + return; + + if ((cvar("noexit") == 1) || ((cvar("noexit") == 2) && (mapname != "start"))) + { + T_Damage (other, self, self, 50000); + return; + } + + if (coop || deathmatch) + { + bprint (other.netname); + bprint (" exited the level\n"); + } + + nextmap = self.map; + + SUB_UseTargets (); + + if ( (self.spawnflags & 1) && (deathmatch == 0) ) + { // NO_INTERMISSION + GotoNextMap(); + return; + } + + self.touch = SUB_Null; + +// we can't move people right now, because touch functions are called +// in the middle of C movement code, so set a think time to do it + self.think = execute_changelevel; + self.nextthink = time + 0.1; +}; + +/*QUAKED trigger_changelevel (0.5 0.5 0.5) ? NO_INTERMISSION +When the player touches this, he gets sent to the map listed in the "map" variable. Unless the NO_INTERMISSION flag is set, the view will go to the info_intermission spot and display stats. +*/ +void() trigger_changelevel = +{ + if (!self.map) + objerror ("chagnelevel trigger doesn't have map"); + + InitTrigger (); + self.touch = changelevel_touch; +}; + + +/* +============================================================================= + + PLAYER GAME EDGE FUNCTIONS + +============================================================================= +*/ + +void() set_suicide_frame; + +// called by ClientKill and DeadThink +void() respawn = +{ + if (coop) + { + // make a copy for apearances sake + CopyToBodyQue(self); + // get the spawn parms as they were at level start + setspawnparms (self); + // respawn + PutClientInServer (); + } + else if (deathmatch) + { + // make a copy for apearances sake + CopyToBodyQue(self); + // set default spawn parms + SetNewParms (); + // respawn + PutClientInServer (); + } + else + { // restart the entire server + localcmd ("restart\n"); + } +}; + + +/* +============ +ClientKill + +Player entered the suicide command +============ +*/ +void() ClientKill = +{ + bprint (self.netname); + bprint (" suicides\n"); + + self.frags = self.frags - 2; // extra penalty + self.modelindex = modelindex_player; + + self.health = 0; + self.takedamage = DAMAGE_NO; + self.touch = SUB_Null; + self.th_die (); +}; + +/*float(vector v) CheckSpawnPoint = +{ + return FALSE; +};*/ + +/* +============ +SelectSpawnPoint + +Returns the entity to spawn at +============ +*/ +entity() SelectSpawnPoint = +{ + local entity spot; + local entity thing; + local float pcount; + +// testinfo_player_start is only found in regioned levels + spot = find (world, classname, "testplayerstart"); + if (spot) + return spot; + +// choose a info_player_deathmatch point + if (coop) + { + lastspawn = find(lastspawn, classname, "info_player_coop"); + if (lastspawn == world) + lastspawn = find (lastspawn, classname, "info_player_start"); + if (lastspawn != world) + return lastspawn; + } + else if (deathmatch) + { + spot = lastspawn; + while (1) + { + spot = find(spot, classname, "info_player_deathmatch"); + if (spot != world) + { + if (spot == lastspawn) + return lastspawn; + pcount = 0; + thing = findradius(spot.origin, 32); + while(thing) + { + if (thing.classname == "player") + pcount = pcount + 1; + thing = thing.chain; + } + if (pcount == 0) + { + lastspawn = spot; + return spot; + } + } + } + } + + if (serverflags) + { // return with a rune to start + spot = find (world, classname, "info_player_start2"); + if (spot) + return spot; + } + + spot = find (world, classname, "info_player_start"); + if (!spot) + error ("PutClientInServer: no info_player_start on level"); + + return spot; +}; + +float(entity to) SendPlayer = +{ + float ef; + float f; + + if (!to.usingcsqc) + { + to.usingcsqc = 1; + self.dimension_see = 1; + } + +//encode the current weapon in the lower 4 bits. + for (f = 1, ef = 0; ef < 16; ef=ef+1,f*=2) + { + if (self.weapon == f) + break; + } +//and put effects in the upper 3 + if (self.items & IT_INVISIBILITY) + ef |= 128; + if (self.items & IT_INVULNERABILITY || self.flags & FL_GODMODE) + ef |= 64; + if (self.items & IT_QUAD) + ef |= 32; +//and the final bit takes an indication to switch of prediction. + if (self.movetype != MOVETYPE_WALK) + ef |= 16; //tells the csqc to stop trying to predict (I can't be bothered to send the real movetype) + + + WriteByte(MSG_ENTITY, CLASS_PLAYER); + WriteByte(MSG_ENTITY, self.frame); //for clientside animation selection, in a way compatable with not having csqc. + WriteByte(MSG_ENTITY, self.angles_x*(256/360)); + WriteByte(MSG_ENTITY, self.angles_y*(256/360)); + WriteCoord(MSG_ENTITY, self.origin_x); + WriteCoord(MSG_ENTITY, self.origin_y); + WriteCoord(MSG_ENTITY, self.origin_z); + WriteShort(MSG_ENTITY, self.velocity_x*64); + WriteShort(MSG_ENTITY, self.velocity_y*64); + WriteShort(MSG_ENTITY, self.velocity_z*64); + WriteByte(MSG_ENTITY, ef); + return TRUE; +}; + + +/* +=========== +PutClientInServer + +called each time a player is spawned +============ +*/ +void() DecodeLevelParms; +void() PlayerDie; + +void() PutClientInServer = +{ + local entity spot; + + spot = SelectSpawnPoint (); + + self.classname = "player"; + self.health = 100; + self.takedamage = DAMAGE_AIM; + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_WALK; + self.show_hostile = 0; + self.max_health = 100; + self.flags = FL_CLIENT; + self.air_finished = time + 12; + self.dmg = 2; // initial water damage + self.super_damage_finished = 0; + self.radsuit_finished = 0; + self.invisible_finished = 0; + self.invincible_finished = 0; + self.effects = 0; + self.invincible_time = 0; + + if (serverusingcsqc) + { + self.SendEntity = SendPlayer; + self.Version = self.Version+1; + } + + DecodeLevelParms (); + + W_SetCurrentAmmo (); + + self.attack_finished = time; + self.th_pain = player_pain; + self.th_die = PlayerDie; + + self.deadflag = DEAD_NO; +// paustime is set by teleporters to keep the player from moving a while + self.pausetime = 0; + +// spot = SelectSpawnPoint (); + + self.origin = spot.origin + '0 0 1'; + self.angles = spot.angles; + self.fixangle = TRUE; // turn this way immediately + +// oh, this is a hack! + setmodel (self, "progs/eyes.mdl"); + modelindex_eyes = self.modelindex; + + setmodel (self, "progs/player.mdl"); + modelindex_player = self.modelindex; + + setsize (self, VEC_HULL_MIN, VEC_HULL_MAX); + + self.view_ofs = '0 0 22'; + + player_stand1 (); + + if (deathmatch || coop) + { + makevectors(self.angles); + spawn_tfog (self.origin + v_forward*20); + } + + spawn_tdeath (self.origin, self); +}; + + +/* +============================================================================= + + QUAKED FUNCTIONS + +============================================================================= +*/ + + +/*QUAKED info_player_start (1 0 0) (-16 -16 -24) (16 16 24) +The normal starting point for a level. +*/ +void() info_player_start = +{ +}; + + +/*QUAKED info_player_start2 (1 0 0) (-16 -16 -24) (16 16 24) +Only used on start map for the return point from an episode. +*/ +void() info_player_start2 = +{ +}; + + +/* +saved out by quaked in region mode +*/ +void() testplayerstart = +{ +}; + +/*QUAKED info_player_deathmatch (1 0 1) (-16 -16 -24) (16 16 24) +potential spawning position for deathmatch games +*/ +void() info_player_deathmatch = +{ +}; + +/*QUAKED info_player_coop (1 0 1) (-16 -16 -24) (16 16 24) +potential spawning position for coop games +*/ +void() info_player_coop = +{ +}; + +/* +=============================================================================== + +RULES + +=============================================================================== +*/ + +/* +go to the next level for deathmatch +only called if a time or frag limit has expired +*/ +void() NextLevel = +{ + local entity o; + + if (mapname == "start") + { + if (!cvar("registered")) + { + mapname = "e1m1"; + } + else if (!(serverflags & 1)) + { + mapname = "e1m1"; + serverflags = serverflags | 1; + } + else if (!(serverflags & 2)) + { + mapname = "e2m1"; + serverflags = serverflags | 2; + } + else if (!(serverflags & 4)) + { + mapname = "e3m1"; + serverflags = serverflags | 4; + } + else if (!(serverflags & 8)) + { + mapname = "e4m1"; + serverflags = serverflags - 7; + } + + o = spawn(); + o.map = mapname; + } + else + { + // find a trigger changelevel + o = find(world, classname, "trigger_changelevel"); + + // go back to start if no trigger_changelevel + if (!o) + { + mapname = "start"; + o = spawn(); + o.map = mapname; + } + } + + nextmap = o.map; + gameover = TRUE; + + if (o.nextthink < time) + { + o.think = execute_changelevel; + o.nextthink = time + 0.1; + } +}; + +/* +============ +CheckRules + +Exit deathmatch games upon conditions +============ +*/ +void() CheckRules = +{ + local float timelimit; + local float fraglimit; + + if (gameover) // someone else quit the game already + return; + + timelimit = cvar("timelimit") * 60; + fraglimit = cvar("fraglimit"); + + if (timelimit && time >= timelimit) + { + NextLevel (); + return; + } + + if (fraglimit && self.frags >= fraglimit) + { + NextLevel (); + return; + } +}; + +//============================================================================ + +void() PlayerDeathThink = +{ + local float forward; + + if ((self.flags & FL_ONGROUND)) + { + forward = vlen (self.velocity); + forward = forward - 20; + if (forward <= 0) + self.velocity = '0 0 0'; + else + self.velocity = forward * normalize(self.velocity); + } + +// wait for all buttons released + if (self.deadflag == DEAD_DEAD) + { + if (self.button2 || self.button1 || self.button0) + return; + self.deadflag = DEAD_RESPAWNABLE; + return; + } + +// wait for any button down + if (!self.button2 && !self.button1 && !self.button0) + return; + + self.button0 = 0; + self.button1 = 0; + self.button2 = 0; + respawn(); +}; + + +void() PlayerJump = +{ + + if (self.flags & FL_WATERJUMP) + return; + + if (self.waterlevel >= 2) + { + if (self.watertype == CONTENT_WATER) + self.velocity_z = 100; + else if (self.watertype == CONTENT_SLIME) + self.velocity_z = 80; + else + self.velocity_z = 50; + +// play swiming sound + if (self.swim_flag < time) + { + self.swim_flag = time + 1; + if (random() < 0.5) + sound (self, CHAN_BODY, "misc/water1.wav", 1, ATTN_NORM); + else + sound (self, CHAN_BODY, "misc/water2.wav", 1, ATTN_NORM); + } + + return; + } + + if (!(self.flags & FL_ONGROUND)) + return; + + if ( !(self.flags & FL_JUMPRELEASED) ) + return; // don't pogo stick + + self.flags = self.flags - (self.flags & FL_JUMPRELEASED); + + self.flags = self.flags - FL_ONGROUND; // don't stairwalk + + self.button2 = 0; +// player jumping sound + sound (self, CHAN_BODY, "player/plyrjmp8.wav", 1, ATTN_NORM); + self.velocity_z = self.velocity_z + 270; +}; + + +/* +=========== +WaterMove + +============ +*/ +.float dmgtime; + +void() WaterMove = +{ +//dprint (ftos(self.waterlevel)); + if (self.movetype == MOVETYPE_NOCLIP) + return; + if (self.health < 0) + return; + + if (self.waterlevel != 3) + { + if (self.air_finished < time) + sound (self, CHAN_VOICE, "player/gasp2.wav", 1, ATTN_NORM); + else if (self.air_finished < time + 9) + sound (self, CHAN_VOICE, "player/gasp1.wav", 1, ATTN_NORM); + self.air_finished = time + 12; + self.dmg = 2; + } + else if (self.air_finished < time) + { // drown! + if (self.pain_finished < time) + { + self.dmg = self.dmg + 2; + if (self.dmg > 15) + self.dmg = 10; + T_Damage (self, world, world, self.dmg); + self.pain_finished = time + 1; + } + } + + if (!self.waterlevel) + { + if (self.flags & FL_INWATER) + { + // play leave water sound + sound (self, CHAN_BODY, "misc/outwater.wav", 1, ATTN_NORM); + self.flags = self.flags - FL_INWATER; + } + return; + } + + if (self.watertype == CONTENT_LAVA) + { // do damage + if (self.dmgtime < time) + { + if (self.radsuit_finished > time) + self.dmgtime = time + 1; + else + self.dmgtime = time + 0.2; + + T_Damage (self, world, world, 10*self.waterlevel); + } + } + else if (self.watertype == CONTENT_SLIME) + { // do damage + if (self.dmgtime < time && self.radsuit_finished < time) + { + self.dmgtime = time + 1; + T_Damage (self, world, world, 4*self.waterlevel); + } + } + + if ( !(self.flags & FL_INWATER) ) + { + +// player enter water sound + + if (self.watertype == CONTENT_LAVA) + sound (self, CHAN_BODY, "player/inlava.wav", 1, ATTN_NORM); + if (self.watertype == CONTENT_WATER) + sound (self, CHAN_BODY, "player/inh2o.wav", 1, ATTN_NORM); + if (self.watertype == CONTENT_SLIME) + sound (self, CHAN_BODY, "player/slimbrn2.wav", 1, ATTN_NORM); + + self.flags = self.flags + FL_INWATER; + self.dmgtime = 0; + } + + if (! (self.flags & FL_WATERJUMP) ) + self.velocity = self.velocity - 0.8*self.waterlevel*frametime*self.velocity; +}; + +void() CheckWaterJump = +{ + local vector start, end; + +// check for a jump-out-of-water + makevectors (self.angles); + start = self.origin; + start_z = start_z + 8; + v_forward_z = 0; + normalize(v_forward); + end = start + v_forward*24; + traceline (start, end, TRUE, self); + if (trace_fraction < 1) + { // solid at waist + start_z = start_z + self.maxs_z - 8; + end = start + v_forward*24; + self.movedir = trace_plane_normal * -50; + traceline (start, end, TRUE, self); + if (trace_fraction == 1) + { // open at eye level + self.flags = self.flags | FL_WATERJUMP; + self.velocity_z = 225; + self.flags = self.flags - (self.flags & FL_JUMPRELEASED); + self.teleport_time = time + 2; // safety net + return; + } + } +}; + + +/* +================ +PlayerPreThink + +Called every frame before physics are run +================ +*/ +void() PlayerPreThink = +{ + if (intermission_running) + { + IntermissionThink (); // otherwise a button could be missed between + return; // the think tics + } + + if (self.view_ofs == '0 0 0') + return; // intermission or finale + + self.Version++; + + makevectors (self.v_angle); // is this still used + + CheckRules (); + WaterMove (); + + if (self.waterlevel == 2) + CheckWaterJump (); + + if (self.deadflag >= DEAD_DEAD) + { + PlayerDeathThink (); + return; + } + + if (self.deadflag == DEAD_DYING) + return; // dying, so do nothing + + if (self.button2) + { + PlayerJump (); + } + else + self.flags = self.flags | FL_JUMPRELEASED; + +// teleporters can force a non-moving pause time + if (time < self.pausetime) + self.velocity = '0 0 0'; + + if(time > self.attack_finished && self.currentammo == 0 && self.weapon != IT_AXE) + { + self.weapon = W_BestWeapon (); + W_SetCurrentAmmo (); + } + + if (self.lackofcsqckicktime) + { + if (!self.usingcsqc && self.lackofcsqckicktime < time) + { //well, you could kick them instead, if you were feeling mean. + bprint(self.netname); + bprint(" is not using csqc!\n"); + centerprint(self, "You are not using csqc.\nThis could be due to version differences or only a partially installed mod.\nIf you are using FTEQW, please type \n\sallow_download_csprogs 1\s\n in the console, and then reconnect.\n\nNote that certain incompatabilities may exist if you do not."); + self.lackofcsqckicktime = 0; + } + } +}; + +/* +================ +CheckPowerups + +Check for turning off powerups +================ +*/ +void() CheckPowerups = +{ + if (self.health <= 0) + return; + +// invisibility + if (self.invisible_finished) + { +// sound and screen flash when items starts to run out + if (self.invisible_sound < time) + { + sound (self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE); + self.invisible_sound = time + ((random() * 3) + 1); + } + + + if (self.invisible_finished < time + 3) + { + if (self.invisible_time == 1) + { + sprint (self, "Ring of Shadows magic is fading\n"); + stuffcmd (self, "bf\n"); + sound (self, CHAN_AUTO, "items/inv2.wav", 1, ATTN_NORM); + self.invisible_time = time + 1; + } + + if (self.invisible_time < time) + { + self.invisible_time = time + 1; + stuffcmd (self, "bf\n"); + } + } + + if (self.invisible_finished < time) + { // just stopped + self.items = self.items - IT_INVISIBILITY; + self.invisible_finished = 0; + self.invisible_time = 0; + } + + // use the eyes + self.modelindex = modelindex_eyes; + } + else + self.modelindex = modelindex_player; // don't use eyes + +// invincibility + if (self.invincible_finished) + { +// sound and screen flash when items starts to run out + if (self.invincible_finished < time + 3) + { + if (self.invincible_time == 1) + { + sprint (self, "Protection is almost burned out\n"); + stuffcmd (self, "bf\n"); + sound (self, CHAN_AUTO, "items/protect2.wav", 1, ATTN_NORM); + self.invincible_time = time + 1; + } + + if (self.invincible_time < time) + { + self.invincible_time = time + 1; + stuffcmd (self, "bf\n"); + } + } + + if (self.invincible_finished < time) + { // just stopped + self.items = self.items - IT_INVULNERABILITY; + self.invincible_time = 0; + self.invincible_finished = 0; + } + if (self.invincible_finished > time) + self.effects = self.effects | EF_DIMLIGHT; + else + self.effects = self.effects - (self.effects & EF_DIMLIGHT); + } + +// super damage + if (self.super_damage_finished) + { + +// sound and screen flash when items starts to run out + + if (self.super_damage_finished < time + 3) + { + if (self.super_time == 1) + { + sprint (self, "Quad Damage is wearing off\n"); + stuffcmd (self, "bf\n"); + sound (self, CHAN_AUTO, "items/damage2.wav", 1, ATTN_NORM); + self.super_time = time + 1; + } + + if (self.super_time < time) + { + self.super_time = time + 1; + stuffcmd (self, "bf\n"); + } + } + + if (self.super_damage_finished < time) + { // just stopped + self.items = self.items - IT_QUAD; + self.super_damage_finished = 0; + self.super_time = 0; + } + if (self.super_damage_finished > time) + self.effects = self.effects | EF_DIMLIGHT; + else + self.effects = self.effects - (self.effects & EF_DIMLIGHT); + } + +// suit + if (self.radsuit_finished) + { + self.air_finished = time + 12; // don't drown + +// sound and screen flash when items starts to run out + if (self.radsuit_finished < time + 3) + { + if (self.rad_time == 1) + { + sprint (self, "Air supply in Biosuit expiring\n"); + stuffcmd (self, "bf\n"); + sound (self, CHAN_AUTO, "items/suit2.wav", 1, ATTN_NORM); + self.rad_time = time + 1; + } + + if (self.rad_time < time) + { + self.rad_time = time + 1; + stuffcmd (self, "bf\n"); + } + } + + if (self.radsuit_finished < time) + { // just stopped + self.items = self.items - IT_SUIT; + self.rad_time = 0; + self.radsuit_finished = 0; + } + } + +}; + + +/* +================ +PlayerPostThink + +Called every frame after physics are run +================ +*/ +void() PlayerPostThink = +{ + if (self.view_ofs == '0 0 0') + return; // intermission or finale + if (self.deadflag) + return; + +// do weapon stuff + + W_WeaponFrame (); + +// check to see if player landed and play landing sound + if ((self.jump_flag < -300) && (self.flags & FL_ONGROUND) && (self.health > 0)) + { + if (self.watertype == CONTENT_WATER) + sound (self, CHAN_BODY, "player/h2ojump.wav", 1, ATTN_NORM); + else if (self.jump_flag < -650) + { + self.deathtype = "falling"; + T_Damage (self, world, world, 5); + sound (self, CHAN_VOICE, "player/land2.wav", 1, ATTN_NORM); + } + else + sound (self, CHAN_VOICE, "player/land.wav", 1, ATTN_NORM); + + self.jump_flag = 0; + } + + if (!(self.flags & FL_ONGROUND)) + self.jump_flag = self.velocity_z; + + CheckPowerups (); +}; + + +/* +=========== +ClientConnect + +called when a player connects to a server +============ +*/ +void() ClientConnect = +{ + bprint (self.netname); + bprint (" entered the game\n"); + +// a client connecting during an intermission can cause problems + if (intermission_running) + ExitIntermission (); + + if (serverusingcsqc) + self.lackofcsqckicktime = time + 10; + self.usingcsqc = false; + self.dimension_see = 3; +}; + + +/* +=========== +ClientDisconnect + +called when a player disconnects from a server +============ +*/ +void() ClientDisconnect = +{ + if (gameover) + return; + // if the level end trigger has been activated, just return + // since they aren't *really* leaving + + // let everyone else know + bprint (self.netname); + bprint (" left the game with "); + bprint (ftos(self.frags)); + bprint (" frags\n"); + sound (self, CHAN_BODY, "player/tornoff2.wav", 1, ATTN_NONE); + set_suicide_frame (); + + self.SendEntity = __NULL__; +}; + +enum { + GENDER_MALE, + GENDER_FEMALE, + GENDER_NEUTER +}; +string infokey(entity ent, string keyname) = #80; +float(entity ent) GetGender = +{ + local string s; + if (infokeyworks) + { + s = infokey(ent, "sex"); + if (s == "" || s == "m" || s == "male" || s == "yesplease") + return GENDER_MALE; + if (s == "f" || s == "female" || s == "onthebeach") + return GENDER_FEMALE; + return GENDER_NEUTER; + } + return GENDER_MALE; +}; + +/* +=========== +ClientObituary + +called when a player dies +============ +*/ +void(entity targ, entity attacker) ClientObituary = +{ + local float rnum, g; + local string deathstring, deathstring2; + rnum = random(); + + if (targ.classname == "player") + { + if (attacker.classname == "teledeath") + { + bprint (targ.netname); + bprint (" was telefragged by "); + bprint (attacker.owner.netname); + bprint ("\n"); + + attacker.owner.frags = attacker.owner.frags + 1; + return; + } + + if (attacker.classname == "teledeath2") + { + bprint ("Satan's power deflects "); + bprint (targ.netname); + bprint ("'s telefrag\n"); + + targ.frags = targ.frags - 1; + return; + } + + if (attacker.classname == "player") + { + if (targ == attacker) + { + // killed self + attacker.frags = attacker.frags - 1; + bprint (targ.netname); + + if (targ.weapon == 64 && targ.waterlevel > 1) + { + bprint (" discharges into the water.\n"); + return; + } + if (targ.weapon == IT_GRENADE_LAUNCHER) + bprint (" tries to put the pin back in\n"); + else if (rnum < 0.1) + { + g = GetGender(attacker); + if (g == GENDER_NEUTER) + deathstring = " has a brain the size of a planet\n"; + else if (g == GENDER_FEMALE) + deathstring = " smeared her makeup\n"; + else + deathstring = " smeared the walls\n"; + bprint (deathstring); + } + else + bprint (" becomes bored with life\n"); + return; + } + else if ( (teamplay == 2) && (targ.team > 0)&&(targ.team == attacker.team) ) + { + if (rnum < 0.25) + deathstring = " mows down a teammate\n"; + else if (rnum < 0.50) + { + g = GetGender(attacker); + if (g == GENDER_NEUTER) + deathstring = " checks its glasses\n"; + else if (g == GENDER_FEMALE) + deathstring = " checks her glasses\n"; + else + deathstring = " checks his glasses\n"; + } + else if (rnum < 0.75) + deathstring = " gets a frag for the other team\n"; + else + deathstring = " loses another friend\n"; + bprint (attacker.netname); + bprint (deathstring); + attacker.frags = attacker.frags - 1; + return; + } + else + { + attacker.frags = attacker.frags + 1; + + rnum = attacker.weapon; + if (rnum == IT_AXE) + { + deathstring = " was ax-murdered by "; + deathstring2 = "\n"; + } + if (rnum == IT_SHOTGUN) + { + deathstring = " chewed on "; + deathstring2 = "'s boomstick\n"; + } + if (rnum == IT_SUPER_SHOTGUN) + { + deathstring = " ate 2 loads of "; + deathstring2 = "'s buckshot\n"; + } + if (rnum == IT_NAILGUN) + { + deathstring = " was nailed by "; + deathstring2 = "\n"; + } + if (rnum == IT_SUPER_NAILGUN) + { + deathstring = " was punctured by "; + deathstring2 = "\n"; + } + if (rnum == IT_GRENADE_LAUNCHER) + { + deathstring = " eats "; + deathstring2 = "'s pineapple\n"; + if (targ.health < -40) + { + deathstring = " was gibbed by "; + deathstring2 = "'s grenade\n"; + } + } + if (rnum == IT_ROCKET_LAUNCHER) + { + deathstring = " rides "; + deathstring2 = "'s rocket\n"; + if (targ.health < -40) + { + deathstring = " was gibbed by "; + deathstring2 = "'s rocket\n" ; + } + } + if (rnum == IT_LIGHTNING) + { + deathstring = " accepts "; + if (attacker.waterlevel > 1) + deathstring2 = "'s discharge\n"; + else + deathstring2 = "'s shaft\n"; + } + bprint (targ.netname); + bprint (deathstring); + bprint (attacker.netname); + bprint (deathstring2); + } + return; + } + else + { + targ.frags = targ.frags - 1; + bprint (targ.netname); + + // killed by a montser? + if (attacker.flags & FL_MONSTER) + { + if (attacker.classname == "monster_army") + bprint (" was shot by a Grunt\n"); + if (attacker.classname == "monster_demon1") + bprint (" was eviscerated by a Fiend\n"); + if (attacker.classname == "monster_dog") + bprint (" was mauled by a Rottweiler\n"); + if (attacker.classname == "monster_dragon") + bprint (" was fried by a Dragon\n"); + if (attacker.classname == "monster_enforcer") + bprint (" was blasted by an Enforcer\n"); + if (attacker.classname == "monster_fish") + bprint (" was fed to the Rotfish\n"); + if (attacker.classname == "monster_hell_knight") + bprint (" was slain by a Death Knight\n"); + if (attacker.classname == "monster_knight") + bprint (" was slashed by a Knight\n"); + if (attacker.classname == "monster_ogre") + bprint (" was destroyed by an Ogre\n"); + if (attacker.classname == "monster_oldone") + bprint (" became one with Shub-Niggurath\n"); + if (attacker.classname == "monster_shalrath") + bprint (" was exploded by a Vore\n"); + if (attacker.classname == "monster_shambler") + bprint (" was smashed by a Shambler\n"); + if (attacker.classname == "monster_tarbaby") + bprint (" was slimed by a Spawn\n"); + if (attacker.classname == "monster_vomit") + bprint (" was vomited on by a Vomitus\n"); + if (attacker.classname == "monster_wizard") + bprint (" was scragged by a Scrag\n"); + if (attacker.classname == "monster_zombie") + bprint (" joins the Zombies\n"); + + return; + } + + // tricks and traps + if (attacker.classname == "explo_box") + { + bprint (" blew up\n"); + return; + } + if (attacker.solid == SOLID_BSP && attacker != world) + { + bprint (" was squished\n"); + return; + } + if (attacker.classname == "trap_shooter" || attacker.classname == "trap_spikeshooter") + { + bprint (" was spiked\n"); + return; + } + if (attacker.classname == "fireball") + { + bprint (" ate a lavaball\n"); + return; + } + if (attacker.classname == "trigger_changelevel") + { + bprint (" tried to leave\n"); + return; + } + + // in-water deaths + rnum = targ.watertype; + if (rnum == -3) + { + if (random() < 0.5) + bprint (" sleeps with the fishes\n"); + else + bprint (" sucks it down\n"); + return; + } + else if (rnum == -4) + { + if (random() < 0.5) + bprint (" gulped a load of slime\n"); + else + bprint (" can't exist on slime alone\n"); + return; + } + else if (rnum == -5) + { + if (targ.health < -15) + { + bprint (" burst into flames\n"); + return; + } + if (random() < 0.5) + bprint (" turned into hot slag\n"); + else + bprint (" visits the Volcano God\n"); + return; + } + + // fell to their death? + if (targ.deathtype == "falling") + { + targ.deathtype = ""; + g = GetGender(targ); + if (g == GENDER_NEUTER) + deathstring = " fell to its death\n"; + else if (g == GENDER_FEMALE) + deathstring = " fell to her death\n"; + else + deathstring = " fell to his death\n"; + bprint (deathstring); + return; + } + + // hell if I know; he's just dead!!! + bprint (" died\n"); + } + } +}; + + +/* + +void() SV_ClientMovementCommand = +{ + PlayerPreThink(); + + pmove_org = self.origin; + pmove_vel = self.velocity; + pmove_mins = self.mins; + pmove_maxs = self.maxs; + pmove_jump_held = self.jump_held; + pmove_waterjumptime = self.teleport_time; + + //should match the one used by csqc. +#ifdef OWNPLAYERPHYSICS + PMove(); +#else + DefaultPlayerPhysics(); +#endif + + self.origin = pmove_org; + self.velocity = pmove_vel; + self.jump_held = pmove_jump_held; + self.teleport_time = pmove_waterjumptime; + + self.waterlevel = 0;//FIXME + self.watertype = 0;//FIXME + + self.button0 = (input_buttons & 1); + self.button2 = !!(input_buttons & 2); + + self.button3 = !!(input_buttons & 4); + self.button4 = !!(input_buttons & 8); + self.button5 = !!(input_buttons & 16); + self.button6 = !!(input_buttons & 32); + self.button7 = !!(input_buttons & 64); + self.button8 = !!(input_buttons & 128); + + self.v_angle = input_angles; + self.angles = input_angles; + self.angles_x *= -1/3; + self.movement = input_movevalues; + self.impulse = input_impulse; + + PlayerPostThink(); + self.Version++; +}; + +*/ \ No newline at end of file diff --git a/quakec/csqctest/src/ss/combat.qc b/quakec/csqctest/src/ss/combat.qc new file mode 100644 index 000000000..cc32b16fa --- /dev/null +++ b/quakec/csqctest/src/ss/combat.qc @@ -0,0 +1,285 @@ + +void() T_MissileTouch; +void() info_player_start; +void(entity targ, entity attacker) ClientObituary; + +void() monster_death_use; + +//============================================================================ + +/* +============ +CanDamage + +Returns true if the inflictor can directly damage the target. Used for +explosions and melee attacks. +============ +*/ +float(entity targ, entity inflictor) CanDamage = +{ +// bmodels need special checking because their origin is 0,0,0 + if (targ.movetype == MOVETYPE_PUSH) + { + traceline(inflictor.origin, 0.5 * (targ.absmin + targ.absmax), TRUE, self); + if (trace_fraction == 1) + return TRUE; + if (trace_ent == targ) + return TRUE; + return FALSE; + } + + traceline(inflictor.origin, targ.origin, TRUE, self); + if (trace_fraction == 1) + return TRUE; + traceline(inflictor.origin, targ.origin + '15 15 0', TRUE, self); + if (trace_fraction == 1) + return TRUE; + traceline(inflictor.origin, targ.origin + '-15 -15 0', TRUE, self); + if (trace_fraction == 1) + return TRUE; + traceline(inflictor.origin, targ.origin + '-15 15 0', TRUE, self); + if (trace_fraction == 1) + return TRUE; + traceline(inflictor.origin, targ.origin + '15 -15 0', TRUE, self); + if (trace_fraction == 1) + return TRUE; + + return FALSE; +}; + + +/* +============ +Killed +============ +*/ +void(entity targ, entity attacker) Killed = +{ + local entity oself; + + oself = self; + self = targ; + + if (self.health < -99) + self.health = -99; // don't let sbar look bad if a player + + if (self.movetype == MOVETYPE_PUSH || self.movetype == MOVETYPE_NONE) + { // doors, triggers, etc + self.th_die (); + self = oself; + return; + } + + self.enemy = attacker; + +// bump the monster counter + if (self.flags & FL_MONSTER) + { + killed_monsters = killed_monsters + 1; + WriteByte (MSG_ALL, SVC_KILLEDMONSTER); + } + + ClientObituary(self, attacker); + + self.takedamage = DAMAGE_NO; + self.touch = SUB_Null; + + monster_death_use(); + self.th_die (); + + self = oself; +}; + + +/* +============ +T_Damage + +The damage is coming from inflictor, but get mad at attacker +This should be the only function that ever reduces health. +============ +*/ +void(entity targ, entity inflictor, entity attacker, float damage) T_Damage= +{ + local vector dir; + local entity oldself; + local float save; + local float take; + + if (!targ.takedamage) + return; + +// used by buttons and triggers to set activator for target firing + damage_attacker = attacker; + +// check for quad damage powerup on the attacker + if (attacker.super_damage_finished > time) + damage = damage * 4; + +// save damage based on the target's armor level + + save = ceil(targ.armortype*damage); + if (save >= targ.armorvalue) + { + save = targ.armorvalue; + targ.armortype = 0; // lost all armor + targ.items = targ.items - (targ.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)); + } + + targ.armorvalue = targ.armorvalue - save; + take = ceil(damage-save); + +// add to the damage total for clients, which will be sent as a single +// message at the end of the frame +// FIXME: remove after combining shotgun blasts? + if (targ.flags & FL_CLIENT) + { + targ.dmg_take = targ.dmg_take + take; + targ.dmg_save = targ.dmg_save + save; + targ.dmg_inflictor = inflictor; + } + +// figure momentum add + if ( (inflictor != world) && (targ.movetype == MOVETYPE_WALK) ) + { + dir = targ.origin - (inflictor.absmin + inflictor.absmax) * 0.5; + dir = normalize(dir); + targ.velocity = targ.velocity + dir*damage*8; + } + +// check for godmode or invincibility + if (targ.flags & FL_GODMODE) + return; + if (targ.invincible_finished >= time) + { + if (self.invincible_sound < time) + { + sound (targ, CHAN_ITEM, "items/protect3.wav", 1, ATTN_NORM); + self.invincible_sound = time + 2; + } + return; + } + +// team play damage avoidance + if ( (teamplay == 1) && (targ.team > 0)&&(targ.team == attacker.team) ) + return; + +// do the damage + targ.health = targ.health - take; + + if (targ.health <= 0) + { + Killed (targ, attacker); + return; + } + +// react to the damage + oldself = self; + self = targ; + + if ( (self.flags & FL_MONSTER) && attacker != world) + { + // get mad unless of the same class (except for soldiers) + if (self != attacker && attacker != self.enemy) + { + if ( (self.classname != attacker.classname) + || (self.classname == "monster_army" ) ) + { + if (self.enemy.classname == "player") + self.oldenemy = self.enemy; + self.enemy = attacker; + FoundTarget (); + } + } + } + + if (self.th_pain) + { + self.th_pain (attacker, take); + // nightmare mode monsters don't go into pain frames often + if (skill == 3) + self.pain_finished = time + 5; + } + + self = oldself; +}; + +/* +============ +T_RadiusDamage +============ +*/ +void(entity inflictor, entity attacker, float damage, entity ignore) T_RadiusDamage = +{ + local float points; + local entity head; + local vector org; + + head = findradius(inflictor.origin, damage+40); + + while (head) + { + if (head != ignore) + { + if (head.takedamage) + { + org = head.origin + (head.mins + head.maxs)*0.5; + points = 0.5*vlen (inflictor.origin - org); + if (points < 0) + points = 0; + points = damage - points; + if (head == attacker) + points = points * 0.5; + if (points > 0) + { + if (CanDamage (head, inflictor)) + { // shambler takes half damage from all explosions + if (head.classname == "monster_shambler") + T_Damage (head, inflictor, attacker, points*0.5); + else + T_Damage (head, inflictor, attacker, points); + } + } + } + } + head = head.chain; + } +}; + +/* +============ +T_BeamDamage +============ +*/ +/*void(entity attacker, float damage) T_BeamDamage = +{ + local float points; + local entity head; + + head = findradius(attacker.origin, damage+40); + + while (head) + { + if (head.takedamage) + { + points = 0.5*vlen (attacker.origin - head.origin); + if (points < 0) + points = 0; + points = damage - points; + if (head == attacker) + points = points * 0.5; + if (points > 0) + { + if (CanDamage (head, attacker)) + { + if (head.classname == "monster_shambler") + T_Damage (head, attacker, attacker, points*0.5); + else + T_Damage (head, attacker, attacker, points); + } + } + } + head = head.chain; + } +};*/ + diff --git a/quakec/csqctest/src/ss/defs.qc b/quakec/csqctest/src/ss/defs.qc new file mode 100644 index 000000000..c25dfc72d --- /dev/null +++ b/quakec/csqctest/src/ss/defs.qc @@ -0,0 +1,507 @@ + +/* +============================================================================== + + SOURCE FOR GLOBALVARS_T C STRUCTURE + +============================================================================== +*/ + +// +// system globals +// +entity self; +entity other; +entity world; +float time; +float frametime; + +float force_retouch; // force all entities to touch triggers + // next frame. this is needed because + // non-moving things don't normally scan + // for triggers, and when a trigger is + // created (like a teleport trigger), it + // needs to catch everything. + // decremented each frame, so set to 2 + // to guarantee everything is touched +string mapname; + +float deathmatch; +float coop; +float teamplay; + +float serverflags; // propagated from level to level, used to + // keep track of completed episodes + +float total_secrets; +float total_monsters; + +float found_secrets; // number of secrets found +float killed_monsters; // number of monsters killed + + +// spawnparms are used to encode information about clients across server +// level changes +float parm1, parm2, parm3, parm4, parm5, parm6, parm7, parm8, parm9, parm10, parm11, parm12, parm13, parm14, parm15, parm16; + +// +// global variables set by built in functions +// +vector v_forward, v_up, v_right; // set by makevectors() + +// set by traceline / tracebox +float trace_allsolid; +float trace_startsolid; +float trace_fraction; +vector trace_endpos; +vector trace_plane_normal; +float trace_plane_dist; +entity trace_ent; +float trace_inopen; +float trace_inwater; + +entity msg_entity; // destination of single entity writes + +// +// required prog functions +// +void() main; // only for testing + +void() StartFrame; + +void() PlayerPreThink; +void() PlayerPostThink; + +void() ClientKill; +void() ClientConnect; +void() PutClientInServer; // call after setting the parm1... parms +void() ClientDisconnect; + +void() SetNewParms; // called when a client first connects to + // a server. sets parms so they can be + // saved off for restarts + +void() SetChangeParms; // call to set parms for self so they can + // be saved for a level transition + + +//================================================ +void end_sys_globals; // flag for structure dumping +//================================================ + +/* +============================================================================== + + SOURCE FOR ENTVARS_T C STRUCTURE + +============================================================================== +*/ + +// +// system fields (*** = do not set in prog code, maintained by C code) +// +.float modelindex; // *** model index in the precached list +.vector absmin, absmax; // *** origin + mins / maxs + +.float ltime; // local time for entity +.float movetype; +.float solid; + +.vector origin; // *** +.vector oldorigin; // *** +.vector velocity; +.vector angles; +.vector avelocity; + +.vector punchangle; // temp angle adjust from damage or recoil + +.string classname; // spawn function +.string model; +.float frame; +.float skin; +.float effects; + +.vector mins, maxs; // bounding box extents reletive to origin +.vector size; // maxs - mins + +.void() touch; +.void() use; +.void() think; +.void() blocked; // for doors or plats, called when can't push other + +.float nextthink; +.entity groundentity; + +// stats +.float health; +.float frags; +.float weapon; // one of the IT_SHOTGUN, etc flags +.string weaponmodel; +.float weaponframe; +.float currentammo; +.float ammo_shells, ammo_nails, ammo_rockets, ammo_cells; + +.float items; // bit flags + +.float takedamage; +.entity chain; +.float deadflag; + +.vector view_ofs; // add to origin to get eye point + + +.float button0; // fire +.float button1; // use +.float button2; // jump + +.float impulse; // weapon changes + +.float fixangle; +.vector v_angle; // view / targeting angle for players +.float idealpitch; // calculated pitch angle for lookup up slopes + + +.string netname; + +.entity enemy; + +.float flags; + +.float colormap; +.float team; + +.float max_health; // players maximum health is stored here + +.float teleport_time; // don't back up + +.float armortype; // save this fraction of incoming damage +.float armorvalue; + +.float waterlevel; // 0 = not in, 1 = feet, 2 = wast, 3 = eyes +.float watertype; // a contents value + +.float ideal_yaw; +.float yaw_speed; + +.entity aiment; + +.entity goalentity; // a movetarget or an enemy + +.float spawnflags; + +.string target; +.string targetname; + +// damage is accumulated through a frame. and sent as one single +// message, so the super shotgun doesn't generate huge messages +.float dmg_take; +.float dmg_save; +.entity dmg_inflictor; + +.entity owner; // who launched a missile +.vector movedir; // mostly for doors, but also used for waterjump + +.string message; // trigger messages + +.float sounds; // either a cd track number or sound number + +.string noise, noise1, noise2, noise3; // contains names of wavs to play + +//================================================ +void end_sys_fields; // flag for structure dumping +//================================================ + +/* +============================================================================== + + VARS NOT REFERENCED BY C CODE + +============================================================================== +*/ + + +// +// constants +// + + +// range values +float RANGE_MELEE = 0; +float RANGE_NEAR = 1; +float RANGE_MID = 2; +float RANGE_FAR = 3; + +// deadflag values + +float DEAD_NO = 0; +float DEAD_DYING = 1; +float DEAD_DEAD = 2; +float DEAD_RESPAWNABLE = 3; + +// takedamage values + +float DAMAGE_NO = 0; +float DAMAGE_YES = 1; +float DAMAGE_AIM = 2; + +// point content values + +float CONTENT_EMPTY = -1; +float CONTENT_SOLID = -2; +float CONTENT_WATER = -3; +float CONTENT_SLIME = -4; +float CONTENT_LAVA = -5; +float CONTENT_SKY = -6; + +float STATE_TOP = 0; +float STATE_BOTTOM = 1; +float STATE_UP = 2; +float STATE_DOWN = 3; + +// protocol bytes +float SVC_TEMPENTITY = 23; +float SVC_KILLEDMONSTER = 27; +float SVC_FOUNDSECRET = 28; +float SVC_INTERMISSION = 30; +float SVC_FINALE = 31; +float SVC_CDTRACK = 32; +float SVC_SELLSCREEN = 33; + + +float TE_SPIKE = 0; +float TE_SUPERSPIKE = 1; +float TE_GUNSHOT = 2; +float TE_EXPLOSION = 3; +float TE_TAREXPLOSION = 4; +float TE_LIGHTNING1 = 5; +float TE_LIGHTNING2 = 6; +float TE_WIZSPIKE = 7; +float TE_KNIGHTSPIKE = 8; +float TE_LIGHTNING3 = 9; +float TE_LAVASPLASH = 10; +float TE_TELEPORT = 11; + +// sound channels +// channel 0 never willingly overrides +// other channels (1-7) allways override a playing sound on that channel +float CHAN_AUTO = 0; +float CHAN_WEAPON = 1; +float CHAN_VOICE = 2; +float CHAN_ITEM = 3; +float CHAN_BODY = 4; + +float ATTN_NONE = 0; +float ATTN_NORM = 1; +float ATTN_IDLE = 2; +float ATTN_STATIC = 3; + +// update types + +float UPDATE_GENERAL = 0; +float UPDATE_STATIC = 1; +float UPDATE_BINARY = 2; +float UPDATE_TEMP = 3; + +// entity effects + +float EF_BRIGHTFIELD = 1; +float EF_MUZZLEFLASH = 2; +float EF_BRIGHTLIGHT = 4; +float EF_DIMLIGHT = 8; + + +// messages +float MSG_BROADCAST = 0; // unreliable to all +float MSG_ONE = 1; // reliable to one (msg_entity) +float MSG_ALL = 2; // reliable to all +float MSG_INIT = 3; // write to the init string + +//================================================ + +// +// globals +// +float movedist; +float gameover; // set when a rule exits + +string string_null; // null string, nothing should be held here + +entity newmis; // launch_spike sets this after spawning it + +entity activator; // the entity that activated a trigger or brush + +entity damage_attacker; // set by T_Damage +float framecount; + +float skill; + +//================================================ + +// +// world fields (FIXME: make globals) +// +noref .string wad; +.string map; +.float worldtype; // 0=medieval 1=metal 2=base + +//================================================ + +.string killtarget; + +// +// quakeed fields +// +noref .float light_lev; // not used by game, but parsed by light util +.float style; + + +// +// monster ai +// +.void() th_stand; +.void() th_walk; +.void() th_run; +.void() th_missile; +.void() th_melee; +.void(entity attacker, float damage) th_pain; +.void() th_die; + +.entity oldenemy; // mad at this player before taking damage + +.float speed; + +.float lefty; + +.float search_time; +.float attack_state; + +float AS_STRAIGHT = 1; +float AS_SLIDING = 2; +float AS_MELEE = 3; +float AS_MISSILE = 4; + +// +// player only fields +// +.float walkframe; + +.float attack_finished; +.float pain_finished; + +.float invincible_finished; +.float invisible_finished; +.float super_damage_finished; +.float radsuit_finished; + +.float invincible_time, invincible_sound; +.float invisible_time, invisible_sound; +.float super_time, super_sound; +.float rad_time; +.float fly_sound; + +.float axhitme; + +.float show_hostile; // set to time+0.2 whenever a client fires a + // weapon or takes damage. Used to alert + // monsters that otherwise would let the player go +.float jump_flag; // player jump flag +.float swim_flag; // player swimming sound flag +.float air_finished; // when time > air_finished, start drowning +.float bubble_count; // keeps track of the number of bubbles +.string deathtype; // keeps track of how the player died + +// +// object stuff +// +.string mdl; +.vector mangle; // angle at start + +.vector oldorigin; // only used by secret door + +.float t_length, t_width; + + +// +// doors, etc +// +.vector dest1, dest2; +.float wait; // time from firing to restarting +.float delay; // time from activation to firing +.entity trigger_field; // door's trigger entity +.string noise4; + +// +// monsters +// +.float pausetime; +.entity movetarget; + + +// +// doors +// +.float aflag; +.float dmg; // damage done by door when hit + +// +// misc +// +.float cnt; // misc flag + +// +// subs +// +.void() think1; +.vector finaldest, finalangle; + +// +// triggers +// +.float count; // for counting triggers + + +// +// plats / doors / buttons +// +.float lip; +.float state; +.vector pos1, pos2; // top and bottom positions +.float height; + +// +// sounds +// +.float waitmin; + + + +//============================================================================ + +// +// subs.qc +// +void(vector tdest, float tspeed, void() func) SUB_CalcMove; +void(entity ent, vector tdest, float tspeed, void() func) SUB_CalcMoveEnt; +void(vector destangle, float tspeed, void() func) SUB_CalcAngleMove; +void() SUB_CalcMoveDone; +void() SUB_CalcAngleMoveDone; +void() SUB_Null; +void() SUB_UseTargets; +void() SUB_Remove; + +// +// combat.qc +// +void(entity targ, entity inflictor, entity attacker, float damage) T_Damage; + + +float (entity e, float healamount, float ignore) T_Heal; // health function + +float(entity targ, entity inflictor) CanDamage; + + +float serverusingcsqc; + +.float(entity to) SendEntity; +.float Version; +float MSG_ENTITY = 5; \ No newline at end of file diff --git a/quakec/csqctest/src/ss/demon.qc b/quakec/csqctest/src/ss/demon.qc new file mode 100644 index 000000000..4fe14667e --- /dev/null +++ b/quakec/csqctest/src/ss/demon.qc @@ -0,0 +1,357 @@ +/* +============================================================================== + +DEMON + +============================================================================== +*/ + +$cd id1/models/demon3 +$scale 0.8 +$origin 0 0 24 +$base base +$skin base + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9 +$frame stand10 stand11 stand12 stand13 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 + +$frame run1 run2 run3 run4 run5 run6 + +$frame leap1 leap2 leap3 leap4 leap5 leap6 leap7 leap8 leap9 leap10 +$frame leap11 leap12 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 death9 + +$frame attacka1 attacka2 attacka3 attacka4 attacka5 attacka6 attacka7 attacka8 +$frame attacka9 attacka10 attacka11 attacka12 attacka13 attacka14 attacka15 + +//============================================================================ + +void() Demon_JumpTouch; + +void() demon1_stand1 =[ $stand1, demon1_stand2 ] {ai_stand();}; +void() demon1_stand2 =[ $stand2, demon1_stand3 ] {ai_stand();}; +void() demon1_stand3 =[ $stand3, demon1_stand4 ] {ai_stand();}; +void() demon1_stand4 =[ $stand4, demon1_stand5 ] {ai_stand();}; +void() demon1_stand5 =[ $stand5, demon1_stand6 ] {ai_stand();}; +void() demon1_stand6 =[ $stand6, demon1_stand7 ] {ai_stand();}; +void() demon1_stand7 =[ $stand7, demon1_stand8 ] {ai_stand();}; +void() demon1_stand8 =[ $stand8, demon1_stand9 ] {ai_stand();}; +void() demon1_stand9 =[ $stand9, demon1_stand10 ] {ai_stand();}; +void() demon1_stand10 =[ $stand10, demon1_stand11 ] {ai_stand();}; +void() demon1_stand11 =[ $stand11, demon1_stand12 ] {ai_stand();}; +void() demon1_stand12 =[ $stand12, demon1_stand13 ] {ai_stand();}; +void() demon1_stand13 =[ $stand13, demon1_stand1 ] {ai_stand();}; + +void() demon1_walk1 =[ $walk1, demon1_walk2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "demon/idle1.wav", 1, ATTN_IDLE); +ai_walk(8); +}; +void() demon1_walk2 =[ $walk2, demon1_walk3 ] {ai_walk(6);}; +void() demon1_walk3 =[ $walk3, demon1_walk4 ] {ai_walk(6);}; +void() demon1_walk4 =[ $walk4, demon1_walk5 ] {ai_walk(7);}; +void() demon1_walk5 =[ $walk5, demon1_walk6 ] {ai_walk(4);}; +void() demon1_walk6 =[ $walk6, demon1_walk7 ] {ai_walk(6);}; +void() demon1_walk7 =[ $walk7, demon1_walk8 ] {ai_walk(10);}; +void() demon1_walk8 =[ $walk8, demon1_walk1 ] {ai_walk(10);}; + +void() demon1_run1 =[ $run1, demon1_run2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "demon/idle1.wav", 1, ATTN_IDLE); +ai_run(20);}; +void() demon1_run2 =[ $run2, demon1_run3 ] {ai_run(15);}; +void() demon1_run3 =[ $run3, demon1_run4 ] {ai_run(36);}; +void() demon1_run4 =[ $run4, demon1_run5 ] {ai_run(20);}; +void() demon1_run5 =[ $run5, demon1_run6 ] {ai_run(15);}; +void() demon1_run6 =[ $run6, demon1_run1 ] {ai_run(36);}; + +void() demon1_jump1 =[ $leap1, demon1_jump2 ] {ai_face();}; +void() demon1_jump2 =[ $leap2, demon1_jump3 ] {ai_face();}; +void() demon1_jump3 =[ $leap3, demon1_jump4 ] {ai_face();}; +void() demon1_jump4 =[ $leap4, demon1_jump5 ] +{ + ai_face(); + + self.touch = Demon_JumpTouch; + makevectors (self.angles); + self.origin_z = self.origin_z + 1; + self.velocity = v_forward * 600 + '0 0 250'; + if (self.flags & FL_ONGROUND) + self.flags = self.flags - FL_ONGROUND; +}; +void() demon1_jump5 =[ $leap5, demon1_jump6 ] {}; +void() demon1_jump6 =[ $leap6, demon1_jump7 ] {}; +void() demon1_jump7 =[ $leap7, demon1_jump8 ] {}; +void() demon1_jump8 =[ $leap8, demon1_jump9 ] {}; +void() demon1_jump9 =[ $leap9, demon1_jump10 ] {}; +void() demon1_jump10 =[ $leap10, demon1_jump1 ] { +self.nextthink = time + 3; +// if three seconds pass, assume demon is stuck and jump again +}; + +void() demon1_jump11 =[ $leap11, demon1_jump12 ] {}; +void() demon1_jump12 =[ $leap12, demon1_run1 ] {}; + + +void() demon1_atta1 =[ $attacka1, demon1_atta2 ] {ai_charge(4);}; +void() demon1_atta2 =[ $attacka2, demon1_atta3 ] {ai_charge(0);}; +void() demon1_atta3 =[ $attacka3, demon1_atta4 ] {ai_charge(0);}; +void() demon1_atta4 =[ $attacka4, demon1_atta5 ] {ai_charge(1);}; +void() demon1_atta5 =[ $attacka5, demon1_atta6 ] {ai_charge(2); Demon_Melee(200);}; +void() demon1_atta6 =[ $attacka6, demon1_atta7 ] {ai_charge(1);}; +void() demon1_atta7 =[ $attacka7, demon1_atta8 ] {ai_charge(6);}; +void() demon1_atta8 =[ $attacka8, demon1_atta9 ] {ai_charge(8);}; +void() demon1_atta9 =[ $attacka9, demon1_atta10] {ai_charge(4);}; +void() demon1_atta10 =[ $attacka10, demon1_atta11] {ai_charge(2);}; +void() demon1_atta11 =[ $attacka11, demon1_atta12] {Demon_Melee(-200);}; +void() demon1_atta12 =[ $attacka12, demon1_atta13] {ai_charge(5);}; +void() demon1_atta13 =[ $attacka13, demon1_atta14] {ai_charge(8);}; +void() demon1_atta14 =[ $attacka14, demon1_atta15] {ai_charge(4);}; +void() demon1_atta15 =[ $attacka15, demon1_run1] {ai_charge(4);}; + +void() demon1_pain1 =[ $pain1, demon1_pain2 ] {}; +void() demon1_pain2 =[ $pain2, demon1_pain3 ] {}; +void() demon1_pain3 =[ $pain3, demon1_pain4 ] {}; +void() demon1_pain4 =[ $pain4, demon1_pain5 ] {}; +void() demon1_pain5 =[ $pain5, demon1_pain6 ] {}; +void() demon1_pain6 =[ $pain6, demon1_run1 ] {}; + +void(entity attacker, float damage) demon1_pain = +{ + if (self.touch == Demon_JumpTouch) + return; + + if (self.pain_finished > time) + return; + + self.pain_finished = time + 1; + sound (self, CHAN_VOICE, "demon/dpain1.wav", 1, ATTN_NORM); + + if (random()*200 > damage) + return; // didn't flinch + + demon1_pain1 (); +}; + +void() demon1_die1 =[ $death1, demon1_die2 ] { +sound (self, CHAN_VOICE, "demon/ddeath.wav", 1, ATTN_NORM);}; +void() demon1_die2 =[ $death2, demon1_die3 ] {}; +void() demon1_die3 =[ $death3, demon1_die4 ] {}; +void() demon1_die4 =[ $death4, demon1_die5 ] {}; +void() demon1_die5 =[ $death5, demon1_die6 ] {}; +void() demon1_die6 =[ $death6, demon1_die7 ] +{self.solid = SOLID_NOT;}; +void() demon1_die7 =[ $death7, demon1_die8 ] {}; +void() demon1_die8 =[ $death8, demon1_die9 ] {}; +void() demon1_die9 =[ $death9, demon1_die9 ] {}; + +void() demon_die = +{ +// check for gib + if (self.health < -80) + { + ThrowCSQCGibs(GIB_DEMON); + return; + } + +// regular death + demon1_die1 (); +}; + + +void() Demon_MeleeAttack = +{ + demon1_atta1 (); +}; + + +/*QUAKED monster_demon1 (1 0 0) (-32 -32 -24) (32 32 64) Ambush + +*/ +void() monster_demon1 = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/demon.mdl"); + precache_model ("progs/h_demon.mdl"); + + precache_sound ("demon/ddeath.wav"); + precache_sound ("demon/dhit2.wav"); + precache_sound ("demon/djump.wav"); + precache_sound ("demon/dpain1.wav"); + precache_sound ("demon/idle1.wav"); + precache_sound ("demon/sight2.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/demon.mdl"); + + setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX); + self.health = 300; + + self.th_stand = demon1_stand1; + self.th_walk = demon1_walk1; + self.th_run = demon1_run1; + self.th_die = demon_die; + self.th_melee = Demon_MeleeAttack; // one of two attacks + self.th_missile = demon1_jump1; // jump attack + self.th_pain = demon1_pain; + + walkmonster_start(); +}; + + +/* +============================================================================== + +DEMON + +============================================================================== +*/ + +/* +============== +CheckDemonMelee + +Returns TRUE if a melee attack would hit right now +============== +*/ +float() CheckDemonMelee = +{ + if (enemy_range == RANGE_MELEE) + { // FIXME: check canreach + self.attack_state = AS_MELEE; + return TRUE; + } + return FALSE; +}; + +/* +============== +CheckDemonJump + +============== +*/ +float() CheckDemonJump = +{ + local vector dist; + local float d; + + if (self.origin_z + self.mins_z > self.enemy.origin_z + self.enemy.mins_z + + 0.75 * self.enemy.size_z) + return FALSE; + + if (self.origin_z + self.maxs_z < self.enemy.origin_z + self.enemy.mins_z + + 0.25 * self.enemy.size_z) + return FALSE; + + dist = self.enemy.origin - self.origin; + dist_z = 0; + + d = vlen(dist); + + if (d < 100) + return FALSE; + + if (d > 200) + { + if (random() < 0.9) + return FALSE; + } + + return TRUE; +}; + +float() DemonCheckAttack = +{ +// if close enough for slashing, go for it + if (CheckDemonMelee ()) + { + self.attack_state = AS_MELEE; + return TRUE; + } + + if (CheckDemonJump ()) + { + self.attack_state = AS_MISSILE; + sound (self, CHAN_VOICE, "demon/djump.wav", 1, ATTN_NORM); + return TRUE; + } + + return FALSE; +}; + + +//=========================================================================== + +void(float side) Demon_Melee = +{ + local float ldmg; + local vector delta; + + ai_face (); + walkmove (self.ideal_yaw, 12); // allow a little closing + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 100) + return; + if (!CanDamage (self.enemy, self)) + return; + + sound (self, CHAN_WEAPON, "demon/dhit2.wav", 1, ATTN_NORM); + ldmg = 10 + 5*random(); + T_Damage (self.enemy, self, self, ldmg); + + makevectors (self.angles); + SpawnMeatSpray (self.origin + v_forward*16, side * v_right); +}; + + +void() Demon_JumpTouch = +{ + local float ldmg; + + if (self.health <= 0) + return; + + if (other.takedamage) + { + if ( vlen(self.velocity) > 400 ) + { + ldmg = 40 + 10*random(); + T_Damage (other, self, self, ldmg); + } + } + + if (!checkbottom(self)) + { + if (self.flags & FL_ONGROUND) + { // jump randomly to not get hung up +//dprint ("popjump\n"); + self.touch = SUB_Null; + self.think = demon1_jump1; + self.nextthink = time + 0.1; + +// self.velocity_x = (random() - 0.5) * 600; +// self.velocity_y = (random() - 0.5) * 600; +// self.velocity_z = 200; +// self.flags = self.flags - FL_ONGROUND; + } + return; // not on ground yet + } + + self.touch = SUB_Null; + self.think = demon1_jump11; + self.nextthink = time + 0.1; +}; + diff --git a/quakec/csqctest/src/ss/dog.qc b/quakec/csqctest/src/ss/dog.qc new file mode 100644 index 000000000..942a3bb72 --- /dev/null +++ b/quakec/csqctest/src/ss/dog.qc @@ -0,0 +1,358 @@ +/* +============================================================================== + +DOG + +============================================================================== +*/ +$cd id1/models/dog +$origin 0 0 24 +$base base +$skin skin + +$frame attack1 attack2 attack3 attack4 attack5 attack6 attack7 attack8 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 death9 + +$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8 +$frame deathb9 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + +$frame painb1 painb2 painb3 painb4 painb5 painb6 painb7 painb8 painb9 painb10 +$frame painb11 painb12 painb13 painb14 painb15 painb16 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 run9 run10 run11 run12 + +$frame leap1 leap2 leap3 leap4 leap5 leap6 leap7 leap8 leap9 + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 + + +void() dog_leap1; +void() dog_run1; + +/* +================ +dog_bite + +================ +*/ +void() dog_bite = +{ +local vector delta; +local float ldmg; + + if (!self.enemy) + return; + + ai_charge(10); + + if (!CanDamage (self.enemy, self)) + return; + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 100) + return; + + ldmg = (random()*3) * 8; + T_Damage (self.enemy, self, self, ldmg); +}; + +void() Dog_JumpTouch = +{ + local float ldmg; + + if (self.health <= 0) + return; + + if (other.takedamage) + { + if ( vlen(self.velocity) > 300 ) + { + ldmg = 10 + 10*random(); + T_Damage (other, self, self, ldmg); + } + } + + if (!checkbottom(self)) + { + if (self.flags & FL_ONGROUND) + { // jump randomly to not get hung up +//dprint ("popjump\n"); + self.touch = SUB_Null; + self.think = dog_leap1; + self.nextthink = time + 0.1; + +// self.velocity_x = (random() - 0.5) * 600; +// self.velocity_y = (random() - 0.5) * 600; +// self.velocity_z = 200; +// self.flags = self.flags - FL_ONGROUND; + } + return; // not on ground yet + } + + self.touch = SUB_Null; + self.think = dog_run1; + self.nextthink = time + 0.1; +}; + + +void() dog_stand1 =[ $stand1, dog_stand2 ] {ai_stand();}; +void() dog_stand2 =[ $stand2, dog_stand3 ] {ai_stand();}; +void() dog_stand3 =[ $stand3, dog_stand4 ] {ai_stand();}; +void() dog_stand4 =[ $stand4, dog_stand5 ] {ai_stand();}; +void() dog_stand5 =[ $stand5, dog_stand6 ] {ai_stand();}; +void() dog_stand6 =[ $stand6, dog_stand7 ] {ai_stand();}; +void() dog_stand7 =[ $stand7, dog_stand8 ] {ai_stand();}; +void() dog_stand8 =[ $stand8, dog_stand9 ] {ai_stand();}; +void() dog_stand9 =[ $stand9, dog_stand1 ] {ai_stand();}; + +void() dog_walk1 =[ $walk1 , dog_walk2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "dog/idle.wav", 1, ATTN_IDLE); +ai_walk(8);}; +void() dog_walk2 =[ $walk2 , dog_walk3 ] {ai_walk(8);}; +void() dog_walk3 =[ $walk3 , dog_walk4 ] {ai_walk(8);}; +void() dog_walk4 =[ $walk4 , dog_walk5 ] {ai_walk(8);}; +void() dog_walk5 =[ $walk5 , dog_walk6 ] {ai_walk(8);}; +void() dog_walk6 =[ $walk6 , dog_walk7 ] {ai_walk(8);}; +void() dog_walk7 =[ $walk7 , dog_walk8 ] {ai_walk(8);}; +void() dog_walk8 =[ $walk8 , dog_walk1 ] {ai_walk(8);}; + +void() dog_run1 =[ $run1 , dog_run2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "dog/idle.wav", 1, ATTN_IDLE); +ai_run(16);}; +void() dog_run2 =[ $run2 , dog_run3 ] {ai_run(32);}; +void() dog_run3 =[ $run3 , dog_run4 ] {ai_run(32);}; +void() dog_run4 =[ $run4 , dog_run5 ] {ai_run(20);}; +void() dog_run5 =[ $run5 , dog_run6 ] {ai_run(64);}; +void() dog_run6 =[ $run6 , dog_run7 ] {ai_run(32);}; +void() dog_run7 =[ $run7 , dog_run8 ] {ai_run(16);}; +void() dog_run8 =[ $run8 , dog_run9 ] {ai_run(32);}; +void() dog_run9 =[ $run9 , dog_run10 ] {ai_run(32);}; +void() dog_run10 =[ $run10 , dog_run11 ] {ai_run(20);}; +void() dog_run11 =[ $run11 , dog_run12 ] {ai_run(64);}; +void() dog_run12 =[ $run12 , dog_run1 ] {ai_run(32);}; + +void() dog_atta1 =[ $attack1, dog_atta2 ] {ai_charge(10);}; +void() dog_atta2 =[ $attack2, dog_atta3 ] {ai_charge(10);}; +void() dog_atta3 =[ $attack3, dog_atta4 ] {ai_charge(10);}; +void() dog_atta4 =[ $attack4, dog_atta5 ] { +sound (self, CHAN_VOICE, "dog/dattack1.wav", 1, ATTN_NORM); +dog_bite();}; +void() dog_atta5 =[ $attack5, dog_atta6 ] {ai_charge(10);}; +void() dog_atta6 =[ $attack6, dog_atta7 ] {ai_charge(10);}; +void() dog_atta7 =[ $attack7, dog_atta8 ] {ai_charge(10);}; +void() dog_atta8 =[ $attack8, dog_run1 ] {ai_charge(10);}; + +void() dog_leap1 =[ $leap1, dog_leap2 ] {ai_face();}; +void() dog_leap2 =[ $leap2, dog_leap3 ] +{ + ai_face(); + + self.touch = Dog_JumpTouch; + makevectors (self.angles); + self.origin_z = self.origin_z + 1; + self.velocity = v_forward * 300 + '0 0 200'; + if (self.flags & FL_ONGROUND) + self.flags = self.flags - FL_ONGROUND; +}; + +void() dog_leap3 =[ $leap3, dog_leap4 ] {}; +void() dog_leap4 =[ $leap4, dog_leap5 ] {}; +void() dog_leap5 =[ $leap5, dog_leap6 ] {}; +void() dog_leap6 =[ $leap6, dog_leap7 ] {}; +void() dog_leap7 =[ $leap7, dog_leap8 ] {}; +void() dog_leap8 =[ $leap8, dog_leap9 ] {}; +void() dog_leap9 =[ $leap9, dog_leap9 ] {}; + +void() dog_pain1 =[ $pain1 , dog_pain2 ] {}; +void() dog_pain2 =[ $pain2 , dog_pain3 ] {}; +void() dog_pain3 =[ $pain3 , dog_pain4 ] {}; +void() dog_pain4 =[ $pain4 , dog_pain5 ] {}; +void() dog_pain5 =[ $pain5 , dog_pain6 ] {}; +void() dog_pain6 =[ $pain6 , dog_run1 ] {}; + +void() dog_painb1 =[ $painb1 , dog_painb2 ] {}; +void() dog_painb2 =[ $painb2 , dog_painb3 ] {}; +void() dog_painb3 =[ $painb3 , dog_painb4 ] {ai_pain(4);}; +void() dog_painb4 =[ $painb4 , dog_painb5 ] {ai_pain(12);}; +void() dog_painb5 =[ $painb5 , dog_painb6 ] {ai_pain(12);}; +void() dog_painb6 =[ $painb6 , dog_painb7 ] {ai_pain(2);}; +void() dog_painb7 =[ $painb7 , dog_painb8 ] {}; +void() dog_painb8 =[ $painb8 , dog_painb9 ] {ai_pain(4);}; +void() dog_painb9 =[ $painb9 , dog_painb10 ] {}; +void() dog_painb10 =[ $painb10 , dog_painb11 ] {ai_pain(10);}; +void() dog_painb11 =[ $painb11 , dog_painb12 ] {}; +void() dog_painb12 =[ $painb12 , dog_painb13 ] {}; +void() dog_painb13 =[ $painb13 , dog_painb14 ] {}; +void() dog_painb14 =[ $painb14 , dog_painb15 ] {}; +void() dog_painb15 =[ $painb15 , dog_painb16 ] {}; +void() dog_painb16 =[ $painb16 , dog_run1 ] {}; + +void() dog_pain = +{ + sound (self, CHAN_VOICE, "dog/dpain1.wav", 1, ATTN_NORM); + + if (random() > 0.5) + dog_pain1 (); + else + dog_painb1 (); +}; + +void() dog_die1 =[ $death1, dog_die2 ] {}; +void() dog_die2 =[ $death2, dog_die3 ] {}; +void() dog_die3 =[ $death3, dog_die4 ] {}; +void() dog_die4 =[ $death4, dog_die5 ] {}; +void() dog_die5 =[ $death5, dog_die6 ] {}; +void() dog_die6 =[ $death6, dog_die7 ] {}; +void() dog_die7 =[ $death7, dog_die8 ] {}; +void() dog_die8 =[ $death8, dog_die9 ] {}; +void() dog_die9 =[ $death9, dog_die9 ] {}; + +void() dog_dieb1 =[ $deathb1, dog_dieb2 ] {}; +void() dog_dieb2 =[ $deathb2, dog_dieb3 ] {}; +void() dog_dieb3 =[ $deathb3, dog_dieb4 ] {}; +void() dog_dieb4 =[ $deathb4, dog_dieb5 ] {}; +void() dog_dieb5 =[ $deathb5, dog_dieb6 ] {}; +void() dog_dieb6 =[ $deathb6, dog_dieb7 ] {}; +void() dog_dieb7 =[ $deathb7, dog_dieb8 ] {}; +void() dog_dieb8 =[ $deathb8, dog_dieb9 ] {}; +void() dog_dieb9 =[ $deathb9, dog_dieb9 ] {}; + + +void() dog_die = +{ +// check for gib + if (self.health < -35) + { + ThrowCSQCGibs(GIB_DOG); + return; + } + +// regular death + sound (self, CHAN_VOICE, "dog/ddeath.wav", 1, ATTN_NORM); + self.solid = SOLID_NOT; + + if (random() > 0.5) + dog_die1 (); + else + dog_dieb1 (); +}; + +//============================================================================ + +/* +============== +CheckDogMelee + +Returns TRUE if a melee attack would hit right now +============== +*/ +float() CheckDogMelee = +{ + if (enemy_range == RANGE_MELEE) + { // FIXME: check canreach + self.attack_state = AS_MELEE; + return TRUE; + } + return FALSE; +}; + +/* +============== +CheckDogJump + +============== +*/ +float() CheckDogJump = +{ + local vector dist; + local float d; + + if (self.origin_z + self.mins_z > self.enemy.origin_z + self.enemy.mins_z + + 0.75 * self.enemy.size_z) + return FALSE; + + if (self.origin_z + self.maxs_z < self.enemy.origin_z + self.enemy.mins_z + + 0.25 * self.enemy.size_z) + return FALSE; + + dist = self.enemy.origin - self.origin; + dist_z = 0; + + d = vlen(dist); + + if (d < 80) + return FALSE; + + if (d > 150) + return FALSE; + + return TRUE; +}; + +float() DogCheckAttack = +{ + +// if close enough for slashing, go for it + if (CheckDogMelee ()) + { + self.attack_state = AS_MELEE; + return TRUE; + } + + if (CheckDogJump ()) + { + self.attack_state = AS_MISSILE; + return TRUE; + } + + return FALSE; +}; + + +//=========================================================================== + +/*QUAKED monster_dog (1 0 0) (-32 -32 -24) (32 32 40) Ambush + +*/ +void() monster_dog = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/h_dog.mdl"); + precache_model ("progs/dog.mdl"); + + precache_sound ("dog/dattack1.wav"); + precache_sound ("dog/ddeath.wav"); + precache_sound ("dog/dpain1.wav"); + precache_sound ("dog/dsight.wav"); + precache_sound ("dog/idle.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/dog.mdl"); + + setsize (self, '-32 -32 -24', '32 32 40'); + self.health = 25; + + self.th_stand = dog_stand1; + self.th_walk = dog_walk1; + self.th_run = dog_run1; + self.th_pain = dog_pain; + self.th_die = dog_die; + self.th_melee = dog_atta1; + self.th_missile = dog_leap1; + + walkmonster_start(); +}; diff --git a/quakec/csqctest/src/ss/doors.qc b/quakec/csqctest/src/ss/doors.qc new file mode 100644 index 000000000..5761eb6e2 --- /dev/null +++ b/quakec/csqctest/src/ss/doors.qc @@ -0,0 +1,778 @@ + +float DOOR_START_OPEN = 1; +float DOOR_DONT_LINK = 4; +float DOOR_GOLD_KEY = 8; +float DOOR_SILVER_KEY = 16; +float DOOR_TOGGLE = 32; + +/* + +Doors are similar to buttons, but can spawn a fat trigger field around them +to open without a touch, and they link together to form simultanious +double/quad doors. + +Door.owner is the master door. If there is only one door, it points to itself. +If multiple doors, all will point to a single one. + +Door.enemy chains from the master door through all doors linked in the chain. + +*/ + +/* +============================================================================= + +THINK FUNCTIONS + +============================================================================= +*/ + +void() door_go_down; +void() door_go_up; + +void() door_blocked = +{ + T_Damage (other, self, self, self.dmg); + +// if a door has a negative wait, it would never come back if blocked, +// so let it just squash the object to death real fast + if (self.wait >= 0) + { + if (self.state == STATE_DOWN) + door_go_up (); + else + door_go_down (); + } +}; + + +void() door_hit_top = +{ + sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM); + self.state = STATE_TOP; + if (self.spawnflags & DOOR_TOGGLE) + return; // don't come down automatically + self.think = door_go_down; + self.nextthink = self.ltime + self.wait; +}; + +void() door_hit_bottom = +{ + sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM); + self.state = STATE_BOTTOM; +}; + +void() door_go_down = +{ + sound (self, CHAN_VOICE, self.noise2, 1, ATTN_NORM); + if (self.max_health) + { + self.takedamage = DAMAGE_YES; + self.health = self.max_health; + } + + self.state = STATE_DOWN; + SUB_CalcMove (self.pos1, self.speed, door_hit_bottom); +}; + +void() door_go_up = +{ + if (self.state == STATE_UP) + return; // allready going up + + if (self.state == STATE_TOP) + { // reset top wait time + self.nextthink = self.ltime + self.wait; + return; + } + + sound (self, CHAN_VOICE, self.noise2, 1, ATTN_NORM); + self.state = STATE_UP; + SUB_CalcMove (self.pos2, self.speed, door_hit_top); + + SUB_UseTargets(); +}; + + +/* +============================================================================= + +ACTIVATION FUNCTIONS + +============================================================================= +*/ + +void() door_fire = +{ + local entity oself; + local entity starte; + + if (self.owner != self) + objerror ("door_fire: self.owner != self"); + +// play use key sound + + if (self.items) + sound (self, CHAN_VOICE, self.noise4, 1, ATTN_NORM); + + self.message = string_null; // no more message + oself = self; + + if (self.spawnflags & DOOR_TOGGLE) + { + if (self.state == STATE_UP || self.state == STATE_TOP) + { + starte = self; + do + { + door_go_down (); + self = self.enemy; + } while ( (self != starte) && (self != world) ); + self = oself; + return; + } + } + +// trigger all paired doors + starte = self; + do + { + door_go_up (); + self = self.enemy; + } while ( (self != starte) && (self != world) ); + self = oself; +}; + + +void() door_use = +{ + local entity oself; + + self.message = ""; // door message are for touch only + self.owner.message = ""; + self.enemy.message = ""; + oself = self; + self = self.owner; + door_fire (); + self = oself; +}; + + +void() door_trigger_touch = +{ + if (other.health <= 0) + return; + + if (time < self.attack_finished) + return; + self.attack_finished = time + 1; + + activator = other; + + self = self.owner; + door_use (); +}; + + +void() door_killed = +{ + local entity oself; + + oself = self; + self = self.owner; + self.health = self.max_health; + self.takedamage = DAMAGE_NO; // wil be reset upon return + door_use (); + self = oself; +}; + + +/* +================ +door_touch + +Prints messages and opens key doors +================ +*/ +void() door_touch = +{ + if (other.classname != "player") + return; + if (self.owner.attack_finished > time) + return; + + self.owner.attack_finished = time + 2; + + if (self.owner.message != "") + { + centerprint (other, self.owner.message); + sound (other, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM); + } + +// key door stuff + if (!self.items) + return; + +// FIXME: blink key on player's status bar + if ( (self.items & other.items) != self.items ) + { + if (self.owner.items == IT_KEY1) + { + if (world.worldtype == 2) + { + centerprint (other, "You need the silver keycard"); + sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + } + else if (world.worldtype == 1) + { + centerprint (other, "You need the silver runekey"); + sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + } + else if (world.worldtype == 0) + { + centerprint (other, "You need the silver key"); + sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + } + } + else + { + if (world.worldtype == 2) + { + centerprint (other, "You need the gold keycard"); + sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + } + else if (world.worldtype == 1) + { + centerprint (other, "You need the gold runekey"); + sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + } + else if (world.worldtype == 0) + { + centerprint (other, "You need the gold key"); + sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + } + } + return; + } + + other.items = other.items - self.items; + self.touch = SUB_Null; + if (self.enemy) + self.enemy.touch = SUB_Null; // get paired door + door_use (); +}; + +/* +============================================================================= + +SPAWNING FUNCTIONS + +============================================================================= +*/ + + +entity(vector fmins, vector fmaxs) spawn_field = +{ + local entity trigger; + local vector t1, t2; + + trigger = spawn(); + trigger.movetype = MOVETYPE_NONE; + trigger.solid = SOLID_TRIGGER; + trigger.owner = self; + trigger.touch = door_trigger_touch; + + t1 = fmins; + t2 = fmaxs; + setsize (trigger, t1 - '60 60 8', t2 + '60 60 8'); + return (trigger); +}; + + +float (entity e1, entity e2) EntitiesTouching = +{ + if (e1.mins_x > e2.maxs_x) + return FALSE; + if (e1.mins_y > e2.maxs_y) + return FALSE; + if (e1.mins_z > e2.maxs_z) + return FALSE; + if (e1.maxs_x < e2.mins_x) + return FALSE; + if (e1.maxs_y < e2.mins_y) + return FALSE; + if (e1.maxs_z < e2.mins_z) + return FALSE; + return TRUE; +}; + + +/* +============= +LinkDoors + + +============= +*/ +void() LinkDoors = +{ + local entity t, starte; + local vector cmins, cmaxs; + + if (self.enemy) + return; // already linked by another door + if (self.spawnflags & 4) + { + self.owner = self.enemy = self; + return; // don't want to link this door + } + + cmins = self.mins; + cmaxs = self.maxs; + + starte = self; + t = self; + + do + { + self.owner = starte; // master door + + if (self.health) + starte.health = self.health; + if (self.targetname!="") + starte.targetname = self.targetname; + if (self.message != "") + starte.message = self.message; + + t = find (t, classname, self.classname); + if (!t) + { + self.enemy = starte; // make the chain a loop + + // shootable, fired, or key doors just needed the owner/enemy links, + // they don't spawn a field + + self = self.owner; + + if (self.health) + return; + if (self.targetname!="") + return; + if (self.items) + return; + + self.owner.trigger_field = spawn_field(cmins, cmaxs); + + return; + } + + if (EntitiesTouching(self,t)) + { + if (t.enemy) + objerror ("cross connected doors"); + + self.enemy = t; + self = t; + + if (t.mins_x < cmins_x) + cmins_x = t.mins_x; + if (t.mins_y < cmins_y) + cmins_y = t.mins_y; + if (t.mins_z < cmins_z) + cmins_z = t.mins_z; + if (t.maxs_x > cmaxs_x) + cmaxs_x = t.maxs_x; + if (t.maxs_y > cmaxs_y) + cmaxs_y = t.maxs_y; + if (t.maxs_z > cmaxs_z) + cmaxs_z = t.maxs_z; + } + } while (1 ); + +}; + + +/*QUAKED func_door (0 .5 .8) ? START_OPEN x DOOR_DONT_LINK GOLD_KEY SILVER_KEY TOGGLE +if two doors touch, they are assumed to be connected and operate as a unit. + +TOGGLE causes the door to wait in both the start and end states for a trigger event. + +START_OPEN causes the door to move to its destination when spawned, and operate in reverse. It is used to temporarily or permanently close off an area when triggered (not usefull for touch or takedamage doors). + +Key doors are allways wait -1. + +"message" is printed when the door is touched if it is a trigger door and it hasn't been fired yet +"angle" determines the opening direction +"targetname" if set, no touch field will be spawned and a remote button or trigger field activates the door. +"health" if set, door must be shot open +"speed" movement speed (100 default) +"wait" wait before returning (3 default, -1 = never return) +"lip" lip remaining at end of move (8 default) +"dmg" damage to inflict when blocked (2 default) +"sounds" +0) no sound +1) stone +2) base +3) stone chain +4) screechy metal +*/ + +void() func_door = + +{ + + if (world.worldtype == 0) + { + precache_sound ("doors/medtry.wav"); + precache_sound ("doors/meduse.wav"); + self.noise3 = "doors/medtry.wav"; + self.noise4 = "doors/meduse.wav"; + } + else if (world.worldtype == 1) + { + precache_sound ("doors/runetry.wav"); + precache_sound ("doors/runeuse.wav"); + self.noise3 = "doors/runetry.wav"; + self.noise4 = "doors/runeuse.wav"; + } + else if (world.worldtype == 2) + { + precache_sound ("doors/basetry.wav"); + precache_sound ("doors/baseuse.wav"); + self.noise3 = "doors/basetry.wav"; + self.noise4 = "doors/baseuse.wav"; + } + else + { + dprint ("no worldtype set!\n"); + } + if (self.sounds == 0) + { + precache_sound ("misc/null.wav"); + precache_sound ("misc/null.wav"); + self.noise1 = "misc/null.wav"; + self.noise2 = "misc/null.wav"; + } + if (self.sounds == 1) + { + precache_sound ("doors/drclos4.wav"); + precache_sound ("doors/doormv1.wav"); + self.noise1 = "doors/drclos4.wav"; + self.noise2 = "doors/doormv1.wav"; + } + if (self.sounds == 2) + { + precache_sound ("doors/hydro1.wav"); + precache_sound ("doors/hydro2.wav"); + self.noise2 = "doors/hydro1.wav"; + self.noise1 = "doors/hydro2.wav"; + } + if (self.sounds == 3) + { + precache_sound ("doors/stndr1.wav"); + precache_sound ("doors/stndr2.wav"); + self.noise2 = "doors/stndr1.wav"; + self.noise1 = "doors/stndr2.wav"; + } + if (self.sounds == 4) + { + precache_sound ("doors/ddoor1.wav"); + precache_sound ("doors/ddoor2.wav"); + self.noise1 = "doors/ddoor2.wav"; + self.noise2 = "doors/ddoor1.wav"; + } + + + SetMovedir (); + + self.max_health = self.health; + self.solid = SOLID_BSP; + self.movetype = MOVETYPE_PUSH; + setorigin (self, self.origin); + setmodel (self, self.model); + self.classname = "door"; + + self.blocked = door_blocked; + self.use = door_use; + + if (self.spawnflags & DOOR_SILVER_KEY) + self.items = IT_KEY1; + if (self.spawnflags & DOOR_GOLD_KEY) + self.items = IT_KEY2; + + if (!self.speed) + self.speed = 100; + if (!self.wait) + self.wait = 3; + if (!self.lip) + self.lip = 8; + if (!self.dmg) + self.dmg = 2; + + self.pos1 = self.origin; + self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip); + +// DOOR_START_OPEN is to allow an entity to be lighted in the closed position +// but spawn in the open position + if (self.spawnflags & DOOR_START_OPEN) + { + setorigin (self, self.pos2); + self.pos2 = self.pos1; + self.pos1 = self.origin; + } + + self.state = STATE_BOTTOM; + + if (self.health) + { + self.takedamage = DAMAGE_YES; + self.th_die = door_killed; + } + + if (self.items) + self.wait = -1; + + self.touch = door_touch; + +// LinkDoors can't be done until all of the doors have been spawned, so +// the sizes can be detected properly. + self.think = LinkDoors; + self.nextthink = self.ltime + 0.1; +}; + +/* +============================================================================= + +SECRET DOORS + +============================================================================= +*/ + +void() fd_secret_move1; +void() fd_secret_move2; +void() fd_secret_move3; +void() fd_secret_move4; +void() fd_secret_move5; +void() fd_secret_move6; +void() fd_secret_done; + +float SECRET_OPEN_ONCE = 1; // stays open +float SECRET_1ST_LEFT = 2; // 1st move is left of arrow +float SECRET_1ST_DOWN = 4; // 1st move is down from arrow +float SECRET_NO_SHOOT = 8; // only opened by trigger +float SECRET_YES_SHOOT = 16; // shootable even if targeted + + +void () fd_secret_use = +{ + local float temp; + + self.health = 10000; + + // exit if still moving around... + if (self.origin != self.oldorigin) + return; + + self.message = string_null; // no more message + + SUB_UseTargets(); // fire all targets / killtargets + + if (!(self.spawnflags & SECRET_NO_SHOOT)) + { + self.th_pain = SUB_Null; + self.takedamage = DAMAGE_NO; + } + self.velocity = '0 0 0'; + + // Make a sound, wait a little... + + sound(self, CHAN_VOICE, self.noise1, 1, ATTN_NORM); + self.nextthink = self.ltime + 0.1; + + temp = 1 - (self.spawnflags & SECRET_1ST_LEFT); // 1 or -1 + makevectors(self.mangle); + + if (!self.t_width) + { + if (self.spawnflags & SECRET_1ST_DOWN) + self. t_width = fabs(v_up * self.size); + else + self. t_width = fabs(v_right * self.size); + } + + if (!self.t_length) + self. t_length = fabs(v_forward * self.size); + + if (self.spawnflags & SECRET_1ST_DOWN) + self.dest1 = self.origin - v_up * self.t_width; + else + self.dest1 = self.origin + v_right * (self.t_width * temp); + + self.dest2 = self.dest1 + v_forward * self.t_length; + SUB_CalcMove(self.dest1, self.speed, fd_secret_move1); + sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM); +}; + +// Wait after first movement... +void () fd_secret_move1 = +{ + self.nextthink = self.ltime + 1.0; + self.think = fd_secret_move2; + sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); +}; + +// Start moving sideways w/sound... +void () fd_secret_move2 = +{ + sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM); + SUB_CalcMove(self.dest2, self.speed, fd_secret_move3); +}; + +// Wait here until time to go back... +void () fd_secret_move3 = +{ + sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); + if (!(self.spawnflags & SECRET_OPEN_ONCE)) + { + self.nextthink = self.ltime + self.wait; + self.think = fd_secret_move4; + } +}; + +// Move backward... +void () fd_secret_move4 = +{ + sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM); + SUB_CalcMove(self.dest1, self.speed, fd_secret_move5); +}; + +// Wait 1 second... +void () fd_secret_move5 = +{ + self.nextthink = self.ltime + 1.0; + self.think = fd_secret_move6; + sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); +}; + +void () fd_secret_move6 = +{ + sound(self, CHAN_VOICE, self.noise2, 1, ATTN_NORM); + SUB_CalcMove(self.oldorigin, self.speed, fd_secret_done); +}; + +void () fd_secret_done = +{ + if (!self.targetname || self.spawnflags&SECRET_YES_SHOOT) + { + self.health = 10000; + self.takedamage = DAMAGE_YES; + self.th_pain = fd_secret_use; + } + sound(self, CHAN_VOICE, self.noise3, 1, ATTN_NORM); +}; + +void () secret_blocked = +{ + if (time < self.attack_finished) + return; + self.attack_finished = time + 0.5; + T_Damage (other, self, self, self.dmg); +}; + +/* +================ +secret_touch + +Prints messages +================ +*/ +void() secret_touch = +{ + if (other.classname != "player") + return; + if (self.attack_finished > time) + return; + + self.attack_finished = time + 2; + + if (self.message!="") + { + centerprint (other, self.message); + sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM); + } +}; + + +/*QUAKED func_door_secret (0 .5 .8) ? open_once 1st_left 1st_down no_shoot always_shoot +Basic secret door. Slides back, then to the side. Angle determines direction. +wait = # of seconds before coming back +1st_left = 1st move is left of arrow +1st_down = 1st move is down from arrow +always_shoot = even if targeted, keep shootable +t_width = override WIDTH to move back (or height if going down) +t_length = override LENGTH to move sideways +"dmg" damage to inflict when blocked (2 default) + +If a secret door has a targetname, it will only be opened by it's botton or trigger, not by damage. +"sounds" +1) medieval +2) metal +3) base +*/ + +void () func_door_secret = +{ + if (self.sounds == 0) + self.sounds = 3; + if (self.sounds == 1) + { + precache_sound ("doors/latch2.wav"); + precache_sound ("doors/winch2.wav"); + precache_sound ("doors/drclos4.wav"); + self.noise1 = "doors/latch2.wav"; + self.noise2 = "doors/winch2.wav"; + self.noise3 = "doors/drclos4.wav"; + } + if (self.sounds == 2) + { + precache_sound ("doors/airdoor1.wav"); + precache_sound ("doors/airdoor2.wav"); + self.noise2 = "doors/airdoor1.wav"; + self.noise1 = "doors/airdoor2.wav"; + self.noise3 = "doors/airdoor2.wav"; + } + if (self.sounds == 3) + { + precache_sound ("doors/basesec1.wav"); + precache_sound ("doors/basesec2.wav"); + self.noise2 = "doors/basesec1.wav"; + self.noise1 = "doors/basesec2.wav"; + self.noise3 = "doors/basesec2.wav"; + } + + if (!self.dmg) + self.dmg = 2; + + // Magic formula... + self.mangle = self.angles; + self.angles = '0 0 0'; + self.solid = SOLID_BSP; + self.movetype = MOVETYPE_PUSH; + self.classname = "door"; + setmodel (self, self.model); + setorigin (self, self.origin); + + self.touch = secret_touch; + self.blocked = secret_blocked; + self.speed = 50; + self.use = fd_secret_use; + if ( !self.targetname || self.spawnflags&SECRET_YES_SHOOT) + { + self.health = 10000; + self.takedamage = DAMAGE_YES; + self.th_pain = fd_secret_use; + self.th_die = fd_secret_use; + } + self.oldorigin = self.origin; + if (!self.wait) + self.wait = 5; // 5 seconds before closing +}; diff --git a/quakec/csqctest/src/ss/enforcer.qc b/quakec/csqctest/src/ss/enforcer.qc new file mode 100644 index 000000000..3ac1d6385 --- /dev/null +++ b/quakec/csqctest/src/ss/enforcer.qc @@ -0,0 +1,345 @@ +/* +============================================================================== + +SOLDIER / PLAYER + +============================================================================== +*/ + +$cd id1/models/enforcer +$origin 0 -6 24 +$base base +$skin skin + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 walk10 +$frame walk11 walk12 walk13 walk14 walk15 walk16 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 + +$frame attack1 attack2 attack3 attack4 attack5 attack6 +$frame attack7 attack8 attack9 attack10 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 +$frame death9 death10 death11 death12 death13 death14 + +$frame fdeath1 fdeath2 fdeath3 fdeath4 fdeath5 fdeath6 fdeath7 fdeath8 +$frame fdeath9 fdeath10 fdeath11 + +$frame paina1 paina2 paina3 paina4 + +$frame painb1 painb2 painb3 painb4 painb5 + +$frame painc1 painc2 painc3 painc4 painc5 painc6 painc7 painc8 + +$frame paind1 paind2 paind3 paind4 paind5 paind6 paind7 paind8 +$frame paind9 paind10 paind11 paind12 paind13 paind14 paind15 paind16 +$frame paind17 paind18 paind19 + + +void() Laser_Touch = +{ + local vector org; + + if (other == self.owner) + return; // don't explode on owner + + if (pointcontents(self.origin) == CONTENT_SKY) + { + remove(self); + return; + } + + sound (self, CHAN_WEAPON, "enforcer/enfstop.wav", 1, ATTN_STATIC); + org = self.origin - 8*normalize(self.velocity); + + if (other.health) + { + SpawnBlood (org, self.velocity*0.2, 15); + T_Damage (other, self, self.owner, 15); + } + else + { + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_GUNSHOT); + WriteCoord (MSG_BROADCAST, org_x); + WriteCoord (MSG_BROADCAST, org_y); + WriteCoord (MSG_BROADCAST, org_z); + } + + remove(self); +}; + +void(vector org, vector vec) LaunchLaser = +{ + if (self.classname == "monster_enforcer") + sound (self, CHAN_WEAPON, "enforcer/enfire.wav", 1, ATTN_NORM); + + vec = normalize(vec); + + newmis = spawn(); + newmis.owner = self; + newmis.movetype = MOVETYPE_FLY; + newmis.solid = SOLID_BBOX; + newmis.effects = EF_DIMLIGHT; + + setmodel (newmis, "progs/laser.mdl"); + setsize (newmis, '0 0 0', '0 0 0'); + + setorigin (newmis, org); + + newmis.velocity = vec * 600; + newmis.angles = vectoangles(newmis.velocity); + + newmis.nextthink = time + 5; + newmis.think = SUB_Remove; + newmis.touch = Laser_Touch; +}; + + + +void() enforcer_fire = +{ + local vector org; + + self.effects = self.effects | EF_MUZZLEFLASH; + makevectors (self.angles); + + org = self.origin + v_forward * 30 + v_right * 8.5 + '0 0 16'; + + LaunchLaser(org, self.enemy.origin - self.origin); +}; + +//============================================================================ + +void() enf_stand1 =[ $stand1, enf_stand2 ] {ai_stand();}; +void() enf_stand2 =[ $stand2, enf_stand3 ] {ai_stand();}; +void() enf_stand3 =[ $stand3, enf_stand4 ] {ai_stand();}; +void() enf_stand4 =[ $stand4, enf_stand5 ] {ai_stand();}; +void() enf_stand5 =[ $stand5, enf_stand6 ] {ai_stand();}; +void() enf_stand6 =[ $stand6, enf_stand7 ] {ai_stand();}; +void() enf_stand7 =[ $stand7, enf_stand1 ] {ai_stand();}; + +void() enf_walk1 =[ $walk1 , enf_walk2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "enforcer/idle1.wav", 1, ATTN_IDLE); +ai_walk(2);}; +void() enf_walk2 =[ $walk2 , enf_walk3 ] {ai_walk(4);}; +void() enf_walk3 =[ $walk3 , enf_walk4 ] {ai_walk(4);}; +void() enf_walk4 =[ $walk4 , enf_walk5 ] {ai_walk(3);}; +void() enf_walk5 =[ $walk5 , enf_walk6 ] {ai_walk(1);}; +void() enf_walk6 =[ $walk6 , enf_walk7 ] {ai_walk(2);}; +void() enf_walk7 =[ $walk7 , enf_walk8 ] {ai_walk(2);}; +void() enf_walk8 =[ $walk8 , enf_walk9 ] {ai_walk(1);}; +void() enf_walk9 =[ $walk9 , enf_walk10 ] {ai_walk(2);}; +void() enf_walk10 =[ $walk10, enf_walk11 ] {ai_walk(4);}; +void() enf_walk11 =[ $walk11, enf_walk12 ] {ai_walk(4);}; +void() enf_walk12 =[ $walk12, enf_walk13 ] {ai_walk(1);}; +void() enf_walk13 =[ $walk13, enf_walk14 ] {ai_walk(2);}; +void() enf_walk14 =[ $walk14, enf_walk15 ] {ai_walk(3);}; +void() enf_walk15 =[ $walk15, enf_walk16 ] {ai_walk(4);}; +void() enf_walk16 =[ $walk16, enf_walk1 ] {ai_walk(2);}; + +void() enf_run1 =[ $run1 , enf_run2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "enforcer/idle1.wav", 1, ATTN_IDLE); +ai_run(18);}; +void() enf_run2 =[ $run2 , enf_run3 ] {ai_run(14);}; +void() enf_run3 =[ $run3 , enf_run4 ] {ai_run(7);}; +void() enf_run4 =[ $run4 , enf_run5 ] {ai_run(12);}; +void() enf_run5 =[ $run5 , enf_run6 ] {ai_run(14);}; +void() enf_run6 =[ $run6 , enf_run7 ] {ai_run(14);}; +void() enf_run7 =[ $run7 , enf_run8 ] {ai_run(7);}; +void() enf_run8 =[ $run8 , enf_run1 ] {ai_run(11);}; + +void() enf_atk1 =[ $attack1, enf_atk2 ] {ai_face();}; +void() enf_atk2 =[ $attack2, enf_atk3 ] {ai_face();}; +void() enf_atk3 =[ $attack3, enf_atk4 ] {ai_face();}; +void() enf_atk4 =[ $attack4, enf_atk5 ] {ai_face();}; +void() enf_atk5 =[ $attack5, enf_atk6 ] {ai_face();}; +void() enf_atk6 =[ $attack6, enf_atk7 ] {enforcer_fire();}; +void() enf_atk7 =[ $attack7, enf_atk8 ] {ai_face();}; +void() enf_atk8 =[ $attack8, enf_atk9 ] {ai_face();}; +void() enf_atk9 =[ $attack5, enf_atk10 ] {ai_face();}; +void() enf_atk10 =[ $attack6, enf_atk11 ] {enforcer_fire();}; +void() enf_atk11 =[ $attack7, enf_atk12 ] {ai_face();}; +void() enf_atk12 =[ $attack8, enf_atk13 ] {ai_face();}; +void() enf_atk13 =[ $attack9, enf_atk14 ] {ai_face();}; +void() enf_atk14 =[ $attack10, enf_run1 ] {ai_face(); +SUB_CheckRefire (enf_atk1); +}; + +void() enf_paina1 =[ $paina1, enf_paina2 ] {}; +void() enf_paina2 =[ $paina2, enf_paina3 ] {}; +void() enf_paina3 =[ $paina3, enf_paina4 ] {}; +void() enf_paina4 =[ $paina4, enf_run1 ] {}; + +void() enf_painb1 =[ $painb1, enf_painb2 ] {}; +void() enf_painb2 =[ $painb2, enf_painb3 ] {}; +void() enf_painb3 =[ $painb3, enf_painb4 ] {}; +void() enf_painb4 =[ $painb4, enf_painb5 ] {}; +void() enf_painb5 =[ $painb5, enf_run1 ] {}; + +void() enf_painc1 =[ $painc1, enf_painc2 ] {}; +void() enf_painc2 =[ $painc2, enf_painc3 ] {}; +void() enf_painc3 =[ $painc3, enf_painc4 ] {}; +void() enf_painc4 =[ $painc4, enf_painc5 ] {}; +void() enf_painc5 =[ $painc5, enf_painc6 ] {}; +void() enf_painc6 =[ $painc6, enf_painc7 ] {}; +void() enf_painc7 =[ $painc7, enf_painc8 ] {}; +void() enf_painc8 =[ $painc8, enf_run1 ] {}; + +void() enf_paind1 =[ $paind1, enf_paind2 ] {}; +void() enf_paind2 =[ $paind2, enf_paind3 ] {}; +void() enf_paind3 =[ $paind3, enf_paind4 ] {}; +void() enf_paind4 =[ $paind4, enf_paind5 ] {ai_painforward(2);}; +void() enf_paind5 =[ $paind5, enf_paind6 ] {ai_painforward(1);}; +void() enf_paind6 =[ $paind6, enf_paind7 ] {}; +void() enf_paind7 =[ $paind7, enf_paind8 ] {}; +void() enf_paind8 =[ $paind8, enf_paind9 ] {}; +void() enf_paind9 =[ $paind9, enf_paind10 ] {}; +void() enf_paind10 =[ $paind10, enf_paind11 ] {}; +void() enf_paind11 =[ $paind11, enf_paind12 ] {ai_painforward(1);}; +void() enf_paind12 =[ $paind12, enf_paind13 ] {ai_painforward(1);}; +void() enf_paind13 =[ $paind13, enf_paind14 ] {ai_painforward(1);}; +void() enf_paind14 =[ $paind14, enf_paind15 ] {}; +void() enf_paind15 =[ $paind15, enf_paind16 ] {}; +void() enf_paind16 =[ $paind16, enf_paind17 ] {ai_pain(1);}; +void() enf_paind17 =[ $paind17, enf_paind18 ] {ai_pain(1);}; +void() enf_paind18 =[ $paind18, enf_paind19 ] {}; +void() enf_paind19 =[ $paind19, enf_run1 ] {}; + +void(entity attacker, float damage) enf_pain = +{ + local float r; + + r = random (); + if (self.pain_finished > time) + return; + + + if (r < 0.5) + sound (self, CHAN_VOICE, "enforcer/pain1.wav", 1, ATTN_NORM); + else + sound (self, CHAN_VOICE, "enforcer/pain2.wav", 1, ATTN_NORM); + + if (r < 0.2) + { + self.pain_finished = time + 1; + enf_paina1 (); + } + else if (r < 0.4) + { + self.pain_finished = time + 1; + enf_painb1 (); + } + else if (r < 0.7) + { + self.pain_finished = time + 1; + enf_painc1 (); + } + else + { + self.pain_finished = time + 2; + enf_paind1 (); + } +}; + +//============================================================================ + + + + +void() enf_die1 =[ $death1, enf_die2 ] {}; +void() enf_die2 =[ $death2, enf_die3 ] {}; +void() enf_die3 =[ $death3, enf_die4 ] +{self.solid = SOLID_NOT;self.ammo_cells = 5;DropBackpack();}; +void() enf_die4 =[ $death4, enf_die5 ] {ai_forward(14);}; +void() enf_die5 =[ $death5, enf_die6 ] {ai_forward(2);}; +void() enf_die6 =[ $death6, enf_die7 ] {}; +void() enf_die7 =[ $death7, enf_die8 ] {}; +void() enf_die8 =[ $death8, enf_die9 ] {}; +void() enf_die9 =[ $death9, enf_die10 ] {ai_forward(3);}; +void() enf_die10 =[ $death10, enf_die11 ] {ai_forward(5);}; +void() enf_die11 =[ $death11, enf_die12 ] {ai_forward(5);}; +void() enf_die12 =[ $death12, enf_die13 ] {ai_forward(5);}; +void() enf_die13 =[ $death13, enf_die14 ] {}; +void() enf_die14 =[ $death14, enf_die14 ] {}; + +void() enf_fdie1 =[ $fdeath1, enf_fdie2 ] { + +}; +void() enf_fdie2 =[ $fdeath2, enf_fdie3 ] {}; +void() enf_fdie3 =[ $fdeath3, enf_fdie4 ] +{self.solid = SOLID_NOT;self.ammo_cells = 5;DropBackpack();}; +void() enf_fdie4 =[ $fdeath4, enf_fdie5 ] {}; +void() enf_fdie5 =[ $fdeath5, enf_fdie6 ] {}; +void() enf_fdie6 =[ $fdeath6, enf_fdie7 ] {}; +void() enf_fdie7 =[ $fdeath7, enf_fdie8 ] {}; +void() enf_fdie8 =[ $fdeath8, enf_fdie9 ] {}; +void() enf_fdie9 =[ $fdeath9, enf_fdie10 ] {}; +void() enf_fdie10 =[ $fdeath10, enf_fdie11 ] {}; +void() enf_fdie11 =[ $fdeath11, enf_fdie11 ] {}; + + +void() enf_die = +{ +// check for gib + if (self.health < -35) + { + ThrowCSQCGibs(GIB_ENFORCER); + return; + } + +// regular death + sound (self, CHAN_VOICE, "enforcer/death1.wav", 1, ATTN_NORM); + if (random() > 0.5) + enf_die1 (); + else + enf_fdie1 (); +}; + + +/*QUAKED monster_enforcer (1 0 0) (-16 -16 -24) (16 16 40) Ambush + +*/ +void() monster_enforcer = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model2 ("progs/enforcer.mdl"); + precache_model2 ("progs/h_mega.mdl"); + precache_model2 ("progs/laser.mdl"); + + precache_sound2 ("enforcer/death1.wav"); + precache_sound2 ("enforcer/enfire.wav"); + precache_sound2 ("enforcer/enfstop.wav"); + precache_sound2 ("enforcer/idle1.wav"); + precache_sound2 ("enforcer/pain1.wav"); + precache_sound2 ("enforcer/pain2.wav"); + precache_sound2 ("enforcer/sight1.wav"); + precache_sound2 ("enforcer/sight2.wav"); + precache_sound2 ("enforcer/sight3.wav"); + precache_sound2 ("enforcer/sight4.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/enforcer.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 80; + + self.th_stand = enf_stand1; + self.th_walk = enf_walk1; + self.th_run = enf_run1; + self.th_pain = enf_pain; + self.th_die = enf_die; + self.th_missile = enf_atk1; + + walkmonster_start(); +}; diff --git a/quakec/csqctest/src/ss/fight.qc b/quakec/csqctest/src/ss/fight.qc new file mode 100644 index 000000000..1d0f02927 --- /dev/null +++ b/quakec/csqctest/src/ss/fight.qc @@ -0,0 +1,407 @@ + +/* + +A monster is in fight mode if it thinks it can effectively attack its +enemy. + +When it decides it can't attack, it goes into hunt mode. + +*/ + +float(float v) anglemod; + +void() knight_atk1; +void() knight_runatk1; +void() ogre_smash1; +void() ogre_swing1; + +void() sham_smash1; +void() sham_swingr1; +void() sham_swingl1; + +float() DemonCheckAttack; +void(float side) Demon_Melee; + +//void(vector dest) ChooseTurn; + +void() ai_face; + + +float enemy_vis, enemy_infront, enemy_range; +float enemy_yaw; + + +void() knight_attack = +{ + local float len; + +// decide if now is a good swing time + len = vlen(self.enemy.origin+self.enemy.view_ofs - (self.origin+self.view_ofs)); + + if (len<80) + knight_atk1 (); + else + knight_runatk1 (); +}; + +//============================================================================= + +/* +=========== +CheckAttack + +The player is in view, so decide to move or launch an attack +Returns FALSE if movement should continue +============ +*/ +float() CheckAttack = +{ + local vector spot1, spot2; + local entity targ; + local float chance; + + targ = self.enemy; + +// see if any entities are in the way of the shot + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + + traceline (spot1, spot2, FALSE, self); + + if (trace_ent != targ) + return FALSE; // don't have a clear shot + + if (trace_inopen && trace_inwater) + return FALSE; // sight line crossed contents + + if (enemy_range == RANGE_MELEE) + { // melee attack + if (self.th_melee) + { + if (self.classname == "monster_knight") + knight_attack (); + else + self.th_melee (); + return TRUE; + } + } + +// missile attack + if (!self.th_missile) + return FALSE; + + if (time < self.attack_finished) + return FALSE; + + if (enemy_range == RANGE_FAR) + return FALSE; + + if (enemy_range == RANGE_MELEE) + { + chance = 0.9; + self.attack_finished = 0; + } + else if (enemy_range == RANGE_NEAR) + { + if (self.th_melee) + chance = 0.2; + else + chance = 0.4; + } + else if (enemy_range == RANGE_MID) + { + if (self.th_melee) + chance = 0.05; + else + chance = 0.1; + } + else + chance = 0; + + if (random () < chance) + { + self.th_missile (); + SUB_AttackFinished (2*random()); + return TRUE; + } + + return FALSE; +}; + + +/* +============= +ai_face + +Stay facing the enemy +============= +*/ +void() ai_face = +{ + self.ideal_yaw = vectoyaw(self.enemy.origin - self.origin); + ChangeYaw (); +}; + +/* +============= +ai_charge + +The monster is in a melee attack, so get as close as possible to .enemy +============= +*/ +float (entity targ) visible; +float(entity targ) infront; +float(entity targ) range; + +void(float d) ai_charge = +{ + ai_face (); + movetogoal (d); // done in C code... +}; + +void() ai_charge_side = +{ + local vector dtemp; + local float heading; + +// aim to the left of the enemy for a flyby + + self.ideal_yaw = vectoyaw(self.enemy.origin - self.origin); + ChangeYaw (); + + makevectors (self.angles); + dtemp = self.enemy.origin - 30*v_right; + heading = vectoyaw(dtemp - self.origin); + + walkmove(heading, 20); +}; + + +/* +============= +ai_melee + +============= +*/ +void() ai_melee = +{ + local vector delta; + local float ldmg; + + if (!self.enemy) + return; // removed before stroke + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 60) + return; + + ldmg = (random() *3) * 3; + T_Damage (self.enemy, self, self, ldmg); +}; + + +void() ai_melee_side = +{ + local vector delta; + local float ldmg; + + if (!self.enemy) + return; // removed before stroke + + ai_charge_side(); + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 60) + return; + if (!CanDamage (self.enemy, self)) + return; + ldmg = (random()*3) * 3; + T_Damage (self.enemy, self, self, ldmg); +}; + + +//============================================================================= + +/* +=========== +SoldierCheckAttack + +The player is in view, so decide to move or launch an attack +Returns FALSE if movement should continue +============ +*/ +float() SoldierCheckAttack = +{ + local vector spot1, spot2; + local entity targ; + local float chance; + + targ = self.enemy; + +// see if any entities are in the way of the shot + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + + traceline (spot1, spot2, FALSE, self); + + if (trace_inopen && trace_inwater) + return FALSE; // sight line crossed contents + + if (trace_ent != targ) + return FALSE; // don't have a clear shot + + +// missile attack + if (time < self.attack_finished) + return FALSE; + + if (enemy_range == RANGE_FAR) + return FALSE; + + if (enemy_range == RANGE_MELEE) + chance = 0.9; + else if (enemy_range == RANGE_NEAR) + chance = 0.4; + else if (enemy_range == RANGE_MID) + chance = 0.05; + else + chance = 0; + + if (random () < chance) + { + self.th_missile (); + SUB_AttackFinished (1 + random()); + if (random() < 0.3) + self.lefty = !self.lefty; + + return TRUE; + } + + return FALSE; +}; +//============================================================================= + +/* +=========== +ShamCheckAttack + +The player is in view, so decide to move or launch an attack +Returns FALSE if movement should continue +============ +*/ +float() ShamCheckAttack = +{ + local vector spot1, spot2; + local entity targ; + + if (enemy_range == RANGE_MELEE) + { + if (CanDamage (self.enemy, self)) + { + self.attack_state = AS_MELEE; + return TRUE; + } + } + + if (time < self.attack_finished) + return FALSE; + + if (!enemy_vis) + return FALSE; + + targ = self.enemy; + +// see if any entities are in the way of the shot + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + + if (vlen(spot1 - spot2) > 600) + return FALSE; + + traceline (spot1, spot2, FALSE, self); + + if (trace_inopen && trace_inwater) + return FALSE; // sight line crossed contents + + if (trace_ent != targ) + { + return FALSE; // don't have a clear shot + } + +// missile attack + if (enemy_range == RANGE_FAR) + return FALSE; + + self.attack_state = AS_MISSILE; + SUB_AttackFinished (2 + 2*random()); + return TRUE; +}; + +//============================================================================ + +/* +=========== +OgreCheckAttack + +The player is in view, so decide to move or launch an attack +Returns FALSE if movement should continue +============ +*/ +float() OgreCheckAttack = +{ + local vector spot1, spot2; + local entity targ; + local float chance; + + if (enemy_range == RANGE_MELEE) + { + if (CanDamage (self.enemy, self)) + { + self.attack_state = AS_MELEE; + return TRUE; + } + } + + if (time < self.attack_finished) + return FALSE; + + if (!enemy_vis) + return FALSE; + + targ = self.enemy; + +// see if any entities are in the way of the shot + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + + traceline (spot1, spot2, FALSE, self); + + if (trace_inopen && trace_inwater) + return FALSE; // sight line crossed contents + + if (trace_ent != targ) + { + return FALSE; // don't have a clear shot + } + +// missile attack + if (time < self.attack_finished) + return FALSE; + + if (enemy_range == RANGE_FAR) + return FALSE; + + else if (enemy_range == RANGE_NEAR) + chance = 0.10; + else if (enemy_range == RANGE_MID) + chance = 0.05; + else + chance = 0; + + self.attack_state = AS_MISSILE; + SUB_AttackFinished (1 + 2*random()); + return TRUE; +}; + diff --git a/quakec/csqctest/src/ss/fish.qc b/quakec/csqctest/src/ss/fish.qc new file mode 100644 index 000000000..11d77910e --- /dev/null +++ b/quakec/csqctest/src/ss/fish.qc @@ -0,0 +1,186 @@ +$cd id1/models/fish +$origin 0 0 24 +$base base +$skin skin + +$frame attack1 attack2 attack3 attack4 attack5 attack6 +$frame attack7 attack8 attack9 attack10 attack11 attack12 attack13 +$frame attack14 attack15 attack16 attack17 attack18 + +$frame death1 death2 death3 death4 death5 death6 death7 +$frame death8 death9 death10 death11 death12 death13 death14 death15 +$frame death16 death17 death18 death19 death20 death21 + +$frame swim1 swim2 swim3 swim4 swim5 swim6 swim7 swim8 +$frame swim9 swim10 swim11 swim12 swim13 swim14 swim15 swim16 swim17 +$frame swim18 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 pain7 pain8 +$frame pain9 + +void() swimmonster_start; + +void() f_stand1 =[ $swim1, f_stand2 ] {ai_stand();}; +void() f_stand2 =[ $swim2, f_stand3 ] {ai_stand();}; +void() f_stand3 =[ $swim3, f_stand4 ] {ai_stand();}; +void() f_stand4 =[ $swim4, f_stand5 ] {ai_stand();}; +void() f_stand5 =[ $swim5, f_stand6 ] {ai_stand();}; +void() f_stand6 =[ $swim6, f_stand7 ] {ai_stand();}; +void() f_stand7 =[ $swim7, f_stand8 ] {ai_stand();}; +void() f_stand8 =[ $swim8, f_stand9 ] {ai_stand();}; +void() f_stand9 =[ $swim9, f_stand10 ] {ai_stand();}; +void() f_stand10 =[ $swim10, f_stand11 ] {ai_stand();}; +void() f_stand11 =[ $swim11, f_stand12 ] {ai_stand();}; +void() f_stand12 =[ $swim12, f_stand13 ] {ai_stand();}; +void() f_stand13 =[ $swim13, f_stand14 ] {ai_stand();}; +void() f_stand14 =[ $swim14, f_stand15 ] {ai_stand();}; +void() f_stand15 =[ $swim15, f_stand16 ] {ai_stand();}; +void() f_stand16 =[ $swim16, f_stand17 ] {ai_stand();}; +void() f_stand17 =[ $swim17, f_stand18 ] {ai_stand();}; +void() f_stand18 =[ $swim18, f_stand1 ] {ai_stand();}; + +void() f_walk1 =[ $swim1, f_walk2 ] {ai_walk(8);}; +void() f_walk2 =[ $swim2, f_walk3 ] {ai_walk(8);}; +void() f_walk3 =[ $swim3, f_walk4 ] {ai_walk(8);}; +void() f_walk4 =[ $swim4, f_walk5 ] {ai_walk(8);}; +void() f_walk5 =[ $swim5, f_walk6 ] {ai_walk(8);}; +void() f_walk6 =[ $swim6, f_walk7 ] {ai_walk(8);}; +void() f_walk7 =[ $swim7, f_walk8 ] {ai_walk(8);}; +void() f_walk8 =[ $swim8, f_walk9 ] {ai_walk(8);}; +void() f_walk9 =[ $swim9, f_walk10 ] {ai_walk(8);}; +void() f_walk10 =[ $swim10, f_walk11 ] {ai_walk(8);}; +void() f_walk11 =[ $swim11, f_walk12 ] {ai_walk(8);}; +void() f_walk12 =[ $swim12, f_walk13 ] {ai_walk(8);}; +void() f_walk13 =[ $swim13, f_walk14 ] {ai_walk(8);}; +void() f_walk14 =[ $swim14, f_walk15 ] {ai_walk(8);}; +void() f_walk15 =[ $swim15, f_walk16 ] {ai_walk(8);}; +void() f_walk16 =[ $swim16, f_walk17 ] {ai_walk(8);}; +void() f_walk17 =[ $swim17, f_walk18 ] {ai_walk(8);}; +void() f_walk18 =[ $swim18, f_walk1 ] {ai_walk(8);}; + +void() f_run1 =[ $swim1, f_run2 ] {ai_run(12); + if (random() < 0.5) + sound (self, CHAN_VOICE, "fish/idle.wav", 1, ATTN_NORM); +}; +void() f_run2 =[ $swim3, f_run3 ] {ai_run(12);}; +void() f_run3 =[ $swim5, f_run4 ] {ai_run(12);}; +void() f_run4 =[ $swim7, f_run5 ] {ai_run(12);}; +void() f_run5 =[ $swim9, f_run6 ] {ai_run(12);}; +void() f_run6 =[ $swim11, f_run7 ] {ai_run(12);}; +void() f_run7 =[ $swim13, f_run8 ] {ai_run(12);}; +void() f_run8 =[ $swim15, f_run9 ] {ai_run(12);}; +void() f_run9 =[ $swim17, f_run1 ] {ai_run(12);}; + +void() fish_melee = +{ + local vector delta; + local float ldmg; + + if (!self.enemy) + return; // removed before stroke + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 60) + return; + + sound (self, CHAN_VOICE, "fish/bite.wav", 1, ATTN_NORM); + ldmg = (random()*2) * 3; + T_Damage (self.enemy, self, self, ldmg); +}; + +void() f_attack1 =[ $attack1, f_attack2 ] {ai_charge(10);}; +void() f_attack2 =[ $attack2, f_attack3 ] {ai_charge(10);}; +void() f_attack3 =[ $attack3, f_attack4 ] {fish_melee();}; +void() f_attack4 =[ $attack4, f_attack5 ] {ai_charge(10);}; +void() f_attack5 =[ $attack5, f_attack6 ] {ai_charge(10);}; +void() f_attack6 =[ $attack6, f_attack7 ] {ai_charge(10);}; +void() f_attack7 =[ $attack7, f_attack8 ] {ai_charge(10);}; +void() f_attack8 =[ $attack8, f_attack9 ] {ai_charge(10);}; +void() f_attack9 =[ $attack9, f_attack10] {fish_melee();}; +void() f_attack10 =[ $attack10, f_attack11] {ai_charge(10);}; +void() f_attack11 =[ $attack11, f_attack12] {ai_charge(10);}; +void() f_attack12 =[ $attack12, f_attack13] {ai_charge(10);}; +void() f_attack13 =[ $attack13, f_attack14] {ai_charge(10);}; +void() f_attack14 =[ $attack14, f_attack15] {ai_charge(10);}; +void() f_attack15 =[ $attack15, f_attack16] {fish_melee();}; +void() f_attack16 =[ $attack16, f_attack17] {ai_charge(10);}; +void() f_attack17 =[ $attack17, f_attack18] {ai_charge(10);}; +void() f_attack18 =[ $attack18, f_run1 ] {ai_charge(10);}; + +void() f_death1 =[ $death1, f_death2 ] { +sound (self, CHAN_VOICE, "fish/death.wav", 1, ATTN_NORM); +}; +void() f_death2 =[ $death2, f_death3 ] {}; +void() f_death3 =[ $death3, f_death4 ] {}; +void() f_death4 =[ $death4, f_death5 ] {}; +void() f_death5 =[ $death5, f_death6 ] {}; +void() f_death6 =[ $death6, f_death7 ] {}; +void() f_death7 =[ $death7, f_death8 ] {}; +void() f_death8 =[ $death8, f_death9 ] {}; +void() f_death9 =[ $death9, f_death10 ] {}; +void() f_death10 =[ $death10, f_death11 ] {}; +void() f_death11 =[ $death11, f_death12 ] {}; +void() f_death12 =[ $death12, f_death13 ] {}; +void() f_death13 =[ $death13, f_death14 ] {}; +void() f_death14 =[ $death14, f_death15 ] {}; +void() f_death15 =[ $death15, f_death16 ] {}; +void() f_death16 =[ $death16, f_death17 ] {}; +void() f_death17 =[ $death17, f_death18 ] {}; +void() f_death18 =[ $death18, f_death19 ] {}; +void() f_death19 =[ $death19, f_death20 ] {}; +void() f_death20 =[ $death20, f_death21 ] {}; +void() f_death21 =[ $death21, f_death21 ] {self.solid = SOLID_NOT;}; + +void() f_pain1 =[ $pain1, f_pain2 ] {}; +void() f_pain2 =[ $pain2, f_pain3 ] {ai_pain(6);}; +void() f_pain3 =[ $pain3, f_pain4 ] {ai_pain(6);}; +void() f_pain4 =[ $pain4, f_pain5 ] {ai_pain(6);}; +void() f_pain5 =[ $pain5, f_pain6 ] {ai_pain(6);}; +void() f_pain6 =[ $pain6, f_pain7 ] {ai_pain(6);}; +void() f_pain7 =[ $pain7, f_pain8 ] {ai_pain(6);}; +void() f_pain8 =[ $pain8, f_pain9 ] {ai_pain(6);}; +void() f_pain9 =[ $pain9, f_run1 ] {ai_pain(6);}; + +void(entity attacker, float damage) fish_pain = +{ + +// fish allways do pain frames + f_pain1 (); +}; + + + +/*QUAKED monster_fish (1 0 0) (-16 -16 -24) (16 16 24) Ambush +*/ +void() monster_fish = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model2 ("progs/fish.mdl"); + + precache_sound2 ("fish/death.wav"); + precache_sound2 ("fish/bite.wav"); + precache_sound2 ("fish/idle.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/fish.mdl"); + + setsize (self, '-16 -16 -24', '16 16 24'); + self.health = 25; + + self.th_stand = f_stand1; + self.th_walk = f_walk1; + self.th_run = f_run1; + self.th_die = f_death1; + self.th_pain = fish_pain; + self.th_melee = f_attack1; + + swimmonster_start (); +}; + diff --git a/quakec/csqctest/src/ss/flag.qc b/quakec/csqctest/src/ss/flag.qc new file mode 100644 index 000000000..44daa0037 --- /dev/null +++ b/quakec/csqctest/src/ss/flag.qc @@ -0,0 +1,8 @@ +/*QUAKED item_deathball (.3 .3 1) (0 0 0) (32 32 32) +*/ +void() deathball_touch; + +void() item_deathball = +{ + self.touch = deathball_touch; +}; \ No newline at end of file diff --git a/quakec/csqctest/src/ss/hknight.qc b/quakec/csqctest/src/ss/hknight.qc new file mode 100644 index 000000000..e4aad3a2c --- /dev/null +++ b/quakec/csqctest/src/ss/hknight.qc @@ -0,0 +1,436 @@ +/* +============================================================================== + +KNIGHT + +============================================================================== +*/ + +$cd id1/models/knight2 +$origin 0 0 24 +$base base +$skin skin + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 +$frame walk10 walk11 walk12 walk13 walk14 walk15 walk16 walk17 +$frame walk18 walk19 walk20 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 + +$frame pain1 pain2 pain3 pain4 pain5 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 +$frame death9 death10 death11 death12 + +$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8 +$frame deathb9 + +$frame char_a1 char_a2 char_a3 char_a4 char_a5 char_a6 char_a7 char_a8 +$frame char_a9 char_a10 char_a11 char_a12 char_a13 char_a14 char_a15 char_a16 + +$frame magica1 magica2 magica3 magica4 magica5 magica6 magica7 magica8 +$frame magica9 magica10 magica11 magica12 magica13 magica14 + +$frame magicb1 magicb2 magicb3 magicb4 magicb5 magicb6 magicb7 magicb8 +$frame magicb9 magicb10 magicb11 magicb12 magicb13 + +$frame char_b1 char_b2 char_b3 char_b4 char_b5 char_b6 + +$frame slice1 slice2 slice3 slice4 slice5 slice6 slice7 slice8 slice9 slice10 + +$frame smash1 smash2 smash3 smash4 smash5 smash6 smash7 smash8 smash9 smash10 +$frame smash11 + +$frame w_attack1 w_attack2 w_attack3 w_attack4 w_attack5 w_attack6 w_attack7 +$frame w_attack8 w_attack9 w_attack10 w_attack11 w_attack12 w_attack13 w_attack14 +$frame w_attack15 w_attack16 w_attack17 w_attack18 w_attack19 w_attack20 +$frame w_attack21 w_attack22 + +$frame magicc1 magicc2 magicc3 magicc4 magicc5 magicc6 magicc7 magicc8 +$frame magicc9 magicc10 magicc11 + + +void() hknight_char_a1; +void() hknight_run1; +void() hk_idle_sound; + +void(float offset) hknight_shot = +{ + local vector offang; + local vector org, vec; + + offang = vectoangles (self.enemy.origin - self.origin); + offang_y = offang_y + offset * 6; + + makevectors (offang); + + org = self.origin + self.mins + self.size*0.5 + v_forward * 20; + +// set missile speed + vec = normalize (v_forward); + vec_z = 0 - vec_z + (random() - 0.5)*0.1; + + launch_spike (org, vec); + newmis.classname = "knightspike"; + setmodel (newmis, "progs/k_spike.mdl"); + setsize (newmis, VEC_ORIGIN, VEC_ORIGIN); + newmis.velocity = vec*300; + sound (self, CHAN_WEAPON, "hknight/attack1.wav", 1, ATTN_NORM); +}; + +void() CheckForCharge = +{ +// check for mad charge +if (!enemy_vis) + return; +if (time < self.attack_finished) + return; +if ( fabs(self.origin_z - self.enemy.origin_z) > 20) + return; // too much height change +if ( vlen (self.origin - self.enemy.origin) < 80) + return; // use regular attack + +// charge + SUB_AttackFinished (2); + hknight_char_a1 (); + +}; + +void() CheckContinueCharge = +{ + if (time > self.attack_finished) + { + SUB_AttackFinished (3); + hknight_run1 (); + return; // done charging + } + if (random() > 0.5) + sound (self, CHAN_WEAPON, "knight/sword2.wav", 1, ATTN_NORM); + else + sound (self, CHAN_WEAPON, "knight/sword1.wav", 1, ATTN_NORM); +}; + +//=========================================================================== + +void() hknight_stand1 =[ $stand1, hknight_stand2 ] {ai_stand();}; +void() hknight_stand2 =[ $stand2, hknight_stand3 ] {ai_stand();}; +void() hknight_stand3 =[ $stand3, hknight_stand4 ] {ai_stand();}; +void() hknight_stand4 =[ $stand4, hknight_stand5 ] {ai_stand();}; +void() hknight_stand5 =[ $stand5, hknight_stand6 ] {ai_stand();}; +void() hknight_stand6 =[ $stand6, hknight_stand7 ] {ai_stand();}; +void() hknight_stand7 =[ $stand7, hknight_stand8 ] {ai_stand();}; +void() hknight_stand8 =[ $stand8, hknight_stand9 ] {ai_stand();}; +void() hknight_stand9 =[ $stand9, hknight_stand1 ] {ai_stand();}; + +//=========================================================================== + +void() hknight_walk1 =[ $walk1, hknight_walk2 ] { +hk_idle_sound(); +ai_walk(2);}; +void() hknight_walk2 =[ $walk2, hknight_walk3 ] {ai_walk(5);}; +void() hknight_walk3 =[ $walk3, hknight_walk4 ] {ai_walk(5);}; +void() hknight_walk4 =[ $walk4, hknight_walk5 ] {ai_walk(4);}; +void() hknight_walk5 =[ $walk5, hknight_walk6 ] {ai_walk(4);}; +void() hknight_walk6 =[ $walk6, hknight_walk7 ] {ai_walk(2);}; +void() hknight_walk7 =[ $walk7, hknight_walk8 ] {ai_walk(2);}; +void() hknight_walk8 =[ $walk8, hknight_walk9 ] {ai_walk(3);}; +void() hknight_walk9 =[ $walk9, hknight_walk10 ] {ai_walk(3);}; +void() hknight_walk10 =[ $walk10, hknight_walk11 ] {ai_walk(4);}; +void() hknight_walk11 =[ $walk11, hknight_walk12 ] {ai_walk(3);}; +void() hknight_walk12 =[ $walk12, hknight_walk13 ] {ai_walk(4);}; +void() hknight_walk13 =[ $walk13, hknight_walk14 ] {ai_walk(6);}; +void() hknight_walk14 =[ $walk14, hknight_walk15 ] {ai_walk(2);}; +void() hknight_walk15 =[ $walk15, hknight_walk16 ] {ai_walk(2);}; +void() hknight_walk16 =[ $walk16, hknight_walk17 ] {ai_walk(4);}; +void() hknight_walk17 =[ $walk17, hknight_walk18 ] {ai_walk(3);}; +void() hknight_walk18 =[ $walk18, hknight_walk19 ] {ai_walk(3);}; +void() hknight_walk19 =[ $walk19, hknight_walk20 ] {ai_walk(3);}; +void() hknight_walk20 =[ $walk20, hknight_walk1 ] {ai_walk(2);}; + +//=========================================================================== + +void() hknight_run1 =[ $run1, hknight_run2 ] { +hk_idle_sound(); +ai_run (20); CheckForCharge (); }; +void() hknight_run2 =[ $run2, hknight_run3 ] {ai_run(25);}; +void() hknight_run3 =[ $run3, hknight_run4 ] {ai_run(18);}; +void() hknight_run4 =[ $run4, hknight_run5 ] {ai_run(16);}; +void() hknight_run5 =[ $run5, hknight_run6 ] {ai_run(14);}; +void() hknight_run6 =[ $run6, hknight_run7 ] {ai_run(25);}; +void() hknight_run7 =[ $run7, hknight_run8 ] {ai_run(21);}; +void() hknight_run8 =[ $run8, hknight_run1 ] {ai_run(13);}; + +//============================================================================ + +void() hknight_pain1 =[ $pain1, hknight_pain2 ] {sound (self, CHAN_VOICE, "hknight/pain1.wav", 1, ATTN_NORM);}; +void() hknight_pain2 =[ $pain2, hknight_pain3 ] {}; +void() hknight_pain3 =[ $pain3, hknight_pain4 ] {}; +void() hknight_pain4 =[ $pain4, hknight_pain5 ] {}; +void() hknight_pain5 =[ $pain5, hknight_run1 ] {}; + +//============================================================================ + +void() hknight_die1 =[ $death1, hknight_die2 ] {ai_forward(10);}; +void() hknight_die2 =[ $death2, hknight_die3 ] {ai_forward(8);}; +void() hknight_die3 =[ $death3, hknight_die4 ] +{self.solid = SOLID_NOT; ai_forward(7);}; +void() hknight_die4 =[ $death4, hknight_die5 ] {}; +void() hknight_die5 =[ $death5, hknight_die6 ] {}; +void() hknight_die6 =[ $death6, hknight_die7 ] {}; +void() hknight_die7 =[ $death7, hknight_die8 ] {}; +void() hknight_die8 =[ $death8, hknight_die9 ] {ai_forward(10);}; +void() hknight_die9 =[ $death9, hknight_die10 ] {ai_forward(11);}; +void() hknight_die10 =[ $death10, hknight_die11 ] {}; +void() hknight_die11 =[ $death11, hknight_die12 ] {}; +void() hknight_die12 =[ $death12, hknight_die12 ] {}; + +void() hknight_dieb1 =[ $deathb1, hknight_dieb2 ] {}; +void() hknight_dieb2 =[ $deathb2, hknight_dieb3 ] {}; +void() hknight_dieb3 =[ $deathb3, hknight_dieb4 ] +{self.solid = SOLID_NOT;}; +void() hknight_dieb4 =[ $deathb4, hknight_dieb5 ] {}; +void() hknight_dieb5 =[ $deathb5, hknight_dieb6 ] {}; +void() hknight_dieb6 =[ $deathb6, hknight_dieb7 ] {}; +void() hknight_dieb7 =[ $deathb7, hknight_dieb8 ] {}; +void() hknight_dieb8 =[ $deathb8, hknight_dieb9 ] {}; +void() hknight_dieb9 =[ $deathb9, hknight_dieb9 ] {}; + +void() hknight_die = +{ +// check for gib + if (self.health < -40) + { + ThrowCSQCGibs(GIB_HELLKNIGHT); + return; + } + +// regular death + sound (self, CHAN_VOICE, "hknight/death1.wav", 1, ATTN_NORM); + if (random() > 0.5) + hknight_die1 (); + else + hknight_dieb1 (); +}; + + +//============================================================================ + +void() hknight_magica1 =[ $magica1, hknight_magica2 ] {ai_face();}; +void() hknight_magica2 =[ $magica2, hknight_magica3 ] {ai_face();}; +void() hknight_magica3 =[ $magica3, hknight_magica4 ] {ai_face();}; +void() hknight_magica4 =[ $magica4, hknight_magica5 ] {ai_face();}; +void() hknight_magica5 =[ $magica5, hknight_magica6 ] {ai_face();}; +void() hknight_magica6 =[ $magica6, hknight_magica7 ] {ai_face();}; +void() hknight_magica7 =[ $magica7, hknight_magica8 ] {hknight_shot(-2);}; +void() hknight_magica8 =[ $magica8, hknight_magica9 ] {hknight_shot(-1);}; +void() hknight_magica9 =[ $magica9, hknight_magica10] {hknight_shot(0);}; +void() hknight_magica10 =[ $magica10, hknight_magica11] {hknight_shot(1);}; +void() hknight_magica11 =[ $magica11, hknight_magica12] {hknight_shot(2);}; +void() hknight_magica12 =[ $magica12, hknight_magica13] {hknight_shot(3);}; +void() hknight_magica13 =[ $magica13, hknight_magica14] {ai_face();}; +void() hknight_magica14 =[ $magica14, hknight_run1 ] {ai_face();}; + +//============================================================================ + +void() hknight_magicb1 =[ $magicb1, hknight_magicb2 ] {ai_face();}; +void() hknight_magicb2 =[ $magicb2, hknight_magicb3 ] {ai_face();}; +void() hknight_magicb3 =[ $magicb3, hknight_magicb4 ] {ai_face();}; +void() hknight_magicb4 =[ $magicb4, hknight_magicb5 ] {ai_face();}; +void() hknight_magicb5 =[ $magicb5, hknight_magicb6 ] {ai_face();}; +void() hknight_magicb6 =[ $magicb6, hknight_magicb7 ] {ai_face();}; +void() hknight_magicb7 =[ $magicb7, hknight_magicb8 ] {hknight_shot(-2);}; +void() hknight_magicb8 =[ $magicb8, hknight_magicb9 ] {hknight_shot(-1);}; +void() hknight_magicb9 =[ $magicb9, hknight_magicb10] {hknight_shot(0);}; +void() hknight_magicb10 =[ $magicb10, hknight_magicb11] {hknight_shot(1);}; +void() hknight_magicb11 =[ $magicb11, hknight_magicb12] {hknight_shot(2);}; +void() hknight_magicb12 =[ $magicb12, hknight_magicb13] {hknight_shot(3);}; +void() hknight_magicb13 =[ $magicb13, hknight_run1] {ai_face();}; + +//============================================================================ + +void() hknight_magicc1 =[ $magicc1, hknight_magicc2 ] {ai_face();}; +void() hknight_magicc2 =[ $magicc2, hknight_magicc3 ] {ai_face();}; +void() hknight_magicc3 =[ $magicc3, hknight_magicc4 ] {ai_face();}; +void() hknight_magicc4 =[ $magicc4, hknight_magicc5 ] {ai_face();}; +void() hknight_magicc5 =[ $magicc5, hknight_magicc6 ] {ai_face();}; +void() hknight_magicc6 =[ $magicc6, hknight_magicc7 ] {hknight_shot(-2);}; +void() hknight_magicc7 =[ $magicc7, hknight_magicc8 ] {hknight_shot(-1);}; +void() hknight_magicc8 =[ $magicc8, hknight_magicc9 ] {hknight_shot(0);}; +void() hknight_magicc9 =[ $magicc9, hknight_magicc10] {hknight_shot(1);}; +void() hknight_magicc10 =[ $magicc10, hknight_magicc11] {hknight_shot(2);}; +void() hknight_magicc11 =[ $magicc11, hknight_run1] {hknight_shot(3);}; + +//=========================================================================== + +void() hknight_char_a1 =[ $char_a1, hknight_char_a2 ] {ai_charge(20);}; +void() hknight_char_a2 =[ $char_a2, hknight_char_a3 ] {ai_charge(25);}; +void() hknight_char_a3 =[ $char_a3, hknight_char_a4 ] {ai_charge(18);}; +void() hknight_char_a4 =[ $char_a4, hknight_char_a5 ] {ai_charge(16);}; +void() hknight_char_a5 =[ $char_a5, hknight_char_a6 ] {ai_charge(14);}; +void() hknight_char_a6 =[ $char_a6, hknight_char_a7 ] {ai_charge(20); ai_melee();}; +void() hknight_char_a7 =[ $char_a7, hknight_char_a8 ] {ai_charge(21); ai_melee();}; +void() hknight_char_a8 =[ $char_a8, hknight_char_a9 ] {ai_charge(13); ai_melee();}; +void() hknight_char_a9 =[ $char_a9, hknight_char_a10 ] {ai_charge(20); ai_melee();}; +void() hknight_char_a10=[ $char_a10, hknight_char_a11 ] {ai_charge(20); ai_melee();}; +void() hknight_char_a11=[ $char_a11, hknight_char_a12 ] {ai_charge(18); ai_melee();}; +void() hknight_char_a12=[ $char_a12, hknight_char_a13 ] {ai_charge(16);}; +void() hknight_char_a13=[ $char_a13, hknight_char_a14 ] {ai_charge(14);}; +void() hknight_char_a14=[ $char_a14, hknight_char_a15 ] {ai_charge(25);}; +void() hknight_char_a15=[ $char_a15, hknight_char_a16 ] {ai_charge(21);}; +void() hknight_char_a16=[ $char_a16, hknight_run1 ] {ai_charge(13);}; + +//=========================================================================== + +void() hknight_char_b1 =[ $char_b1, hknight_char_b2 ] +{CheckContinueCharge (); ai_charge(23); ai_melee();}; +void() hknight_char_b2 =[ $char_b2, hknight_char_b3 ] {ai_charge(17); ai_melee();}; +void() hknight_char_b3 =[ $char_b3, hknight_char_b4 ] {ai_charge(12); ai_melee();}; +void() hknight_char_b4 =[ $char_b4, hknight_char_b5 ] {ai_charge(22); ai_melee();}; +void() hknight_char_b5 =[ $char_b5, hknight_char_b6 ] {ai_charge(18); ai_melee();}; +void() hknight_char_b6 =[ $char_b6, hknight_char_b1 ] {ai_charge(8); ai_melee();}; + +//=========================================================================== + +void() hknight_slice1 =[ $slice1, hknight_slice2 ] {ai_charge(9);}; +void() hknight_slice2 =[ $slice2, hknight_slice3 ] {ai_charge(6);}; +void() hknight_slice3 =[ $slice3, hknight_slice4 ] {ai_charge(13);}; +void() hknight_slice4 =[ $slice4, hknight_slice5 ] {ai_charge(4);}; +void() hknight_slice5 =[ $slice5, hknight_slice6 ] {ai_charge(7); ai_melee();}; +void() hknight_slice6 =[ $slice6, hknight_slice7 ] {ai_charge(15); ai_melee();}; +void() hknight_slice7 =[ $slice7, hknight_slice8 ] {ai_charge(8); ai_melee();}; +void() hknight_slice8 =[ $slice8, hknight_slice9 ] {ai_charge(2); ai_melee();}; +void() hknight_slice9 =[ $slice9, hknight_slice10 ] {ai_melee();}; +void() hknight_slice10 =[ $slice10, hknight_run1 ] {ai_charge(3);}; + +//=========================================================================== + +void() hknight_smash1 =[ $smash1, hknight_smash2 ] {ai_charge(1);}; +void() hknight_smash2 =[ $smash2, hknight_smash3 ] {ai_charge(13);}; +void() hknight_smash3 =[ $smash3, hknight_smash4 ] {ai_charge(9);}; +void() hknight_smash4 =[ $smash4, hknight_smash5 ] {ai_charge(11);}; +void() hknight_smash5 =[ $smash5, hknight_smash6 ] {ai_charge(10); ai_melee();}; +void() hknight_smash6 =[ $smash6, hknight_smash7 ] {ai_charge(7); ai_melee();}; +void() hknight_smash7 =[ $smash7, hknight_smash8 ] {ai_charge(12); ai_melee();}; +void() hknight_smash8 =[ $smash8, hknight_smash9 ] {ai_charge(2); ai_melee();}; +void() hknight_smash9 =[ $smash9, hknight_smash10 ] {ai_charge(3); ai_melee();}; +void() hknight_smash10 =[ $smash10, hknight_smash11 ] {ai_charge(0);}; +void() hknight_smash11 =[ $smash11, hknight_run1 ] {ai_charge(0);}; + +//============================================================================ + +void() hknight_watk1 =[ $w_attack1, hknight_watk2 ] {ai_charge(2);}; +void() hknight_watk2 =[ $w_attack2, hknight_watk3 ] {ai_charge(0);}; +void() hknight_watk3 =[ $w_attack3, hknight_watk4 ] {ai_charge(0);}; +void() hknight_watk4 =[ $w_attack4, hknight_watk5 ] {ai_melee();}; +void() hknight_watk5 =[ $w_attack5, hknight_watk6 ] {ai_melee();}; +void() hknight_watk6 =[ $w_attack6, hknight_watk7 ] {ai_melee();}; +void() hknight_watk7 =[ $w_attack7, hknight_watk8 ] {ai_charge(1);}; +void() hknight_watk8 =[ $w_attack8, hknight_watk9 ] {ai_charge(4);}; +void() hknight_watk9 =[ $w_attack9, hknight_watk10 ] {ai_charge(5);}; +void() hknight_watk10 =[ $w_attack10, hknight_watk11 ] {ai_charge(3); ai_melee();}; +void() hknight_watk11 =[ $w_attack11, hknight_watk12 ] {ai_charge(2); ai_melee();}; +void() hknight_watk12 =[ $w_attack12, hknight_watk13 ] {ai_charge(2); ai_melee();}; +void() hknight_watk13 =[ $w_attack13, hknight_watk14 ] {ai_charge(0);}; +void() hknight_watk14 =[ $w_attack14, hknight_watk15 ] {ai_charge(0);}; +void() hknight_watk15 =[ $w_attack15, hknight_watk16 ] {ai_charge(0);}; +void() hknight_watk16 =[ $w_attack16, hknight_watk17 ] {ai_charge(1);}; +void() hknight_watk17 =[ $w_attack17, hknight_watk18 ] {ai_charge(1); ai_melee();}; +void() hknight_watk18 =[ $w_attack18, hknight_watk19 ] {ai_charge(3); ai_melee();}; +void() hknight_watk19 =[ $w_attack19, hknight_watk20 ] {ai_charge(4); ai_melee();}; +void() hknight_watk20 =[ $w_attack20, hknight_watk21 ] {ai_charge(6);}; +void() hknight_watk21 =[ $w_attack21, hknight_watk22 ] {ai_charge(7);}; +void() hknight_watk22 =[ $w_attack22, hknight_run1 ] {ai_charge(3);}; + +//============================================================================ + +void() hk_idle_sound = +{ + if (random() < 0.2) + sound (self, CHAN_VOICE, "hknight/idle.wav", 1, ATTN_NORM); +}; + +void(entity attacker, float damage) hknight_pain = +{ + if (self.pain_finished > time) + return; + + sound (self, CHAN_VOICE, "hknight/pain1.wav", 1, ATTN_NORM); + + if (time - self.pain_finished > 5) + { // allways go into pain frame if it has been a while + hknight_pain1 (); + self.pain_finished = time + 1; + return; + } + + if ((random()*30 > damage) ) + return; // didn't flinch + + self.pain_finished = time + 1; + hknight_pain1 (); +}; + +float hknight_type; + +void() hknight_melee = +{ + hknight_type = hknight_type + 1; + + sound (self, CHAN_WEAPON, "hknight/slash1.wav", 1, ATTN_NORM); + if (hknight_type == 1) + hknight_slice1 (); + else if (hknight_type == 2) + hknight_smash1 (); + else if (hknight_type == 3) + { + hknight_watk1 (); + hknight_type = 0; + } +}; + +/*QUAKED monster_hell_knight (1 0 0) (-16 -16 -24) (16 16 40) Ambush +*/ +void() monster_hell_knight = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model2 ("progs/hknight.mdl"); + precache_model2 ("progs/k_spike.mdl"); + precache_model2 ("progs/h_hellkn.mdl"); + + + precache_sound2 ("hknight/attack1.wav"); + precache_sound2 ("hknight/death1.wav"); + precache_sound2 ("hknight/pain1.wav"); + precache_sound2 ("hknight/sight1.wav"); + precache_sound ("hknight/hit.wav"); // used by C code, so don't sound2 + precache_sound2 ("hknight/slash1.wav"); + precache_sound2 ("hknight/idle.wav"); + precache_sound2 ("hknight/grunt.wav"); + + precache_sound ("knight/sword1.wav"); + precache_sound ("knight/sword2.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/hknight.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 250; + + self.th_stand = hknight_stand1; + self.th_walk = hknight_walk1; + self.th_run = hknight_run1; + self.th_melee = hknight_melee; + self.th_missile = hknight_magicc1; + self.th_pain = hknight_pain; + self.th_die = hknight_die; + + walkmonster_start (); +}; diff --git a/quakec/csqctest/src/ss/items.qc b/quakec/csqctest/src/ss/items.qc new file mode 100644 index 000000000..f3e8a7076 --- /dev/null +++ b/quakec/csqctest/src/ss/items.qc @@ -0,0 +1,1370 @@ +void() W_SetCurrentAmmo; +/* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD +BE .8 .3 .4 IN COLOR */ + + +void() SUB_regen = +{ + self.model = self.mdl; // restore original model + self.solid = SOLID_TRIGGER; // allow it to be touched again + sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM); // play respawn sound + setorigin (self, self.origin); +}; + + + +/*QUAKED noclass (0 0 0) (-8 -8 -8) (8 8 8) +prints a warning message when spawned +*/ +void() noclass = +{ + dprint ("noclass spawned at"); + dprint (vtos(self.origin)); + dprint ("\n"); + remove (self); +}; + + + +/* +============ +PlaceItem + +plants the object on the floor +============ +*/ +void() PlaceItem = +{ + local float oldz; + + self.mdl = self.model; // so it can be restored on respawn + self.flags = FL_ITEM; // make extra wide + self.solid = SOLID_TRIGGER; + self.movetype = MOVETYPE_TOSS; + self.velocity = '0 0 0'; + self.origin_z = self.origin_z + 6; + oldz = self.origin_z; + if (!droptofloor()) + { + dprint ("Bonus item fell out of level at "); + dprint (vtos(self.origin)); + dprint ("\n"); + remove(self); + return; + } +}; + +/* +============ +StartItem + +Sets the clipping size and plants the object on the floor +============ +*/ +void() StartItem = +{ + self.nextthink = time + 0.2; // items start after other solids + self.think = PlaceItem; +}; + +/* +========================================================================= + +HEALTH BOX + +========================================================================= +*/ +// +// T_Heal: add health to an entity, limiting health to max_health +// "ignore" will ignore max_health limit +// +float (entity e, float healamount, float ignore) T_Heal = +{ + if (e.health <= 0) + return 0; + if ((!ignore) && (e.health >= other.max_health)) + return 0; + healamount = ceil(healamount); + + e.health = e.health + healamount; + if ((!ignore) && (e.health >= other.max_health)) + e.health = other.max_health; + + if (e.health > 250) + e.health = 250; + return 1; +}; + +/*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth +Health box. Normally gives 25 points. +Rotten box heals 5-10 points, +megahealth will add 100 health, then +rot you down to your maximum health limit, +one point per second. +*/ + +float H_ROTTEN = 1; +float H_MEGA = 2; +.float healamount, healtype; +void() health_touch; +void() item_megahealth_rot; + +void() item_health = +{ + self.touch = health_touch; + + if (self.spawnflags & H_ROTTEN) + { + precache_model("maps/b_bh10.bsp"); + + precache_sound("items/r_item1.wav"); + setmodel(self, "maps/b_bh10.bsp"); + self.noise = "items/r_item1.wav"; + self.healamount = 15; + self.healtype = 0; + } + else + if (self.spawnflags & H_MEGA) + { + precache_model("maps/b_bh100.bsp"); + precache_sound("items/r_item2.wav"); + setmodel(self, "maps/b_bh100.bsp"); + self.noise = "items/r_item2.wav"; + self.healamount = 100; + self.healtype = 2; + } + else + { + precache_model("maps/b_bh25.bsp"); + precache_sound("items/health1.wav"); + setmodel(self, "maps/b_bh25.bsp"); + self.noise = "items/health1.wav"; + self.healamount = 25; + self.healtype = 1; + } + setsize (self, '0 0 0', '32 32 56'); + StartItem (); +}; + + +void() health_touch = +{ + local string s; + + if (other.classname != "player") + return; + + if (self.healtype == 2) // Megahealth? Ignore max_health... + { + if (other.health >= 250) + return; + if (!T_Heal(other, self.healamount, 1)) + return; + } + else + { + if (!T_Heal(other, self.healamount, 0)) + return; + } + + sprint(other, "You receive "); + s = ftos(self.healamount); + sprint(other, s); + sprint(other, " health\n"); + +// health touch sound + sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM); + + stuffcmd (other, "bf\n"); + + self.model = string_null; + self.solid = SOLID_NOT; + + // Megahealth = rot down the player's super health + if (self.healtype == 2) + { + other.items = other.items | IT_SUPERHEALTH; + self.nextthink = time + 5; + self.think = item_megahealth_rot; + self.owner = other; + } + else + { + if (deathmatch != 2) // deathmatch 2 is the silly old rules + { + if (deathmatch) + self.nextthink = time + 20; + self.think = SUB_regen; + } + } + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + +void() item_megahealth_rot = +{ + other = self.owner; + + if (other.health > other.max_health) + { + other.health = other.health - 1; + self.nextthink = time + 1; + return; + } + +// it is possible for a player to die and respawn between rots, so don't +// just blindly subtract the flag off + other.items = other.items - (other.items & IT_SUPERHEALTH); + + if (deathmatch == 1) // deathmatch 2 is silly old rules + { + self.nextthink = time + 20; + self.think = SUB_regen; + } +}; + +/* +=============================================================================== + +ARMOR + +=============================================================================== +*/ + +void() armor_touch; + +void() armor_touch = +{ + local float type, value, bit; + + if (other.health <= 0) + return; + if (other.classname != "player") + return; + + if (self.classname == "item_armor1") + { + type = 0.3; + value = 100; + bit = IT_ARMOR1; + } + if (self.classname == "item_armor2") + { + type = 0.6; + value = 150; + bit = IT_ARMOR2; + } + if (self.classname == "item_armorInv") + { + type = 0.8; + value = 200; + bit = IT_ARMOR3; + } + if (other.armortype*other.armorvalue >= type*value) + return; + + other.armortype = type; + other.armorvalue = value; + other.items = other.items - (other.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + bit; + + self.solid = SOLID_NOT; + self.model = string_null; + if (deathmatch == 1) + self.nextthink = time + 20; + self.think = SUB_regen; + + sprint(other, "You got armor\n"); +// armor touch sound + sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + + +/*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() item_armor1 = +{ + self.touch = armor_touch; + precache_model ("progs/armor.mdl"); + setmodel (self, "progs/armor.mdl"); + self.skin = 0; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() item_armor2 = +{ + self.touch = armor_touch; + precache_model ("progs/armor.mdl"); + setmodel (self, "progs/armor.mdl"); + self.skin = 1; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() item_armorInv = +{ + self.touch = armor_touch; + precache_model ("progs/armor.mdl"); + setmodel (self, "progs/armor.mdl"); + self.skin = 2; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/* +=============================================================================== + +WEAPONS + +=============================================================================== +*/ + +void() bound_other_ammo = +{ + if (other.ammo_shells > 100) + other.ammo_shells = 100; + if (other.ammo_nails > 200) + other.ammo_nails = 200; + if (other.ammo_rockets > 100) + other.ammo_rockets = 100; + if (other.ammo_cells > 100) + other.ammo_cells = 100; +}; + + +float(float w) RankForWeapon = +{ + if (w == IT_LIGHTNING) + return 1; + if (w == IT_ROCKET_LAUNCHER) + return 2; + if (w == IT_SUPER_NAILGUN) + return 3; + if (w == IT_GRENADE_LAUNCHER) + return 4; + if (w == IT_SUPER_SHOTGUN) + return 5; + if (w == IT_NAILGUN) + return 6; + return 7; +}; + +/* +============= +Deathmatch_Weapon + +Deathmatch weapon change rules for picking up a weapon + +.float ammo_shells, ammo_nails, ammo_rockets, ammo_cells; +============= +*/ +void(float old, float new) Deathmatch_Weapon = +{ + local float or, nr; + +// change self.weapon if desired + or = RankForWeapon (self.weapon); + nr = RankForWeapon (new); + if ( nr < or ) + self.weapon = new; +}; + +/* +============= +weapon_touch +============= +*/ +float() W_BestWeapon; + +void() weapon_touch = +{ + local float hadammo, best, new, old; + local entity stemp; + local float leave; + + if (!(other.flags & FL_CLIENT)) + return; + +// if the player was using his best weapon, change up to the new one if better + stemp = self; + self = other; + best = W_BestWeapon(); + self = stemp; + + if (deathmatch == 2 || coop) + leave = 1; + else + leave = 0; + + if (self.classname == "weapon_nailgun") + { + if (leave && (other.items & IT_NAILGUN) ) + return; + hadammo = other.ammo_nails; + new = IT_NAILGUN; + other.ammo_nails = other.ammo_nails + 30; + } + else if (self.classname == "weapon_supernailgun") + { + if (leave && (other.items & IT_SUPER_NAILGUN) ) + return; + hadammo = other.ammo_rockets; + new = IT_SUPER_NAILGUN; + other.ammo_nails = other.ammo_nails + 30; + } + else if (self.classname == "weapon_supershotgun") + { + if (leave && (other.items & IT_SUPER_SHOTGUN) ) + return; + hadammo = other.ammo_rockets; + new = IT_SUPER_SHOTGUN; + other.ammo_shells = other.ammo_shells + 5; + } + else if (self.classname == "weapon_rocketlauncher") + { + if (leave && (other.items & IT_ROCKET_LAUNCHER) ) + return; + hadammo = other.ammo_rockets; + new = IT_ROCKET_LAUNCHER; + other.ammo_rockets = other.ammo_rockets + 5; + } + else if (self.classname == "weapon_grenadelauncher") + { + if (leave && (other.items & IT_GRENADE_LAUNCHER) ) + return; + hadammo = other.ammo_rockets; + new = IT_GRENADE_LAUNCHER; + other.ammo_rockets = other.ammo_rockets + 5; + } + else if (self.classname == "weapon_lightning") + { + if (leave && (other.items & IT_LIGHTNING) ) + return; + hadammo = other.ammo_rockets; + new = IT_LIGHTNING; + other.ammo_cells = other.ammo_cells + 15; + } + else + objerror ("weapon_touch: unknown classname"); + + sprint (other, "You got the "); + sprint (other, self.netname); + sprint (other, "\n"); +// weapon touch sound + sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + + bound_other_ammo (); + +// change to the weapon + old = other.items; + other.items = other.items | new; + + stemp = self; + self = other; + + if (!deathmatch) + self.weapon = new; + else + Deathmatch_Weapon (old, new); + + W_SetCurrentAmmo(); + + self = stemp; + + if (leave) + return; + +// remove it in single player, or setup for respawning in deathmatch + self.model = string_null; + self.solid = SOLID_NOT; + if (deathmatch == 1) + self.nextthink = time + 30; + self.think = SUB_regen; + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + + +/*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() weapon_supershotgun = +{ + precache_model ("progs/g_shot.mdl"); + setmodel (self, "progs/g_shot.mdl"); + self.weapon = IT_SUPER_SHOTGUN; + self.netname = "Double-barrelled Shotgun"; + self.touch = weapon_touch; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() weapon_nailgun = +{ + precache_model ("progs/g_nail.mdl"); + setmodel (self, "progs/g_nail.mdl"); + self.weapon = IT_NAILGUN; + self.netname = "nailgun"; + self.touch = weapon_touch; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() weapon_supernailgun = +{ + precache_model ("progs/g_nail2.mdl"); + setmodel (self, "progs/g_nail2.mdl"); + self.weapon = IT_SUPER_NAILGUN; + self.netname = "Super Nailgun"; + self.touch = weapon_touch; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() weapon_grenadelauncher = +{ + precache_model ("progs/g_rock.mdl"); + setmodel (self, "progs/g_rock.mdl"); + self.weapon = 3; + self.netname = "Grenade Launcher"; + self.touch = weapon_touch; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + +/*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() weapon_rocketlauncher = +{ + precache_model ("progs/g_rock2.mdl"); + setmodel (self, "progs/g_rock2.mdl"); + self.weapon = 3; + self.netname = "Rocket Launcher"; + self.touch = weapon_touch; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + + +/*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32) +*/ + +void() weapon_lightning = +{ + precache_model ("progs/g_light.mdl"); + setmodel (self, "progs/g_light.mdl"); + self.weapon = 3; + self.netname = "Thunderbolt"; + self.touch = weapon_touch; + setsize (self, '-16 -16 0', '16 16 56'); + StartItem (); +}; + + +/* +=============================================================================== + +AMMO + +=============================================================================== +*/ + +void() ammo_touch = +{ +local entity stemp; +local float best; + + if (other.classname != "player") + return; + if (other.health <= 0) + return; + +// if the player was using his best weapon, change up to the new one if better + stemp = self; + self = other; + best = W_BestWeapon(); + self = stemp; + + +// shotgun + if (self.weapon == 1) + { + if (other.ammo_shells >= 100) + return; + other.ammo_shells = other.ammo_shells + self.aflag; + } + +// spikes + if (self.weapon == 2) + { + if (other.ammo_nails >= 200) + return; + other.ammo_nails = other.ammo_nails + self.aflag; + } + +// rockets + if (self.weapon == 3) + { + if (other.ammo_rockets >= 100) + return; + other.ammo_rockets = other.ammo_rockets + self.aflag; + } + +// cells + if (self.weapon == 4) + { + if (other.ammo_cells >= 100) + return; + other.ammo_cells = other.ammo_cells + self.aflag; + } + + bound_other_ammo (); + + sprint (other, "You got the "); + sprint (other, self.netname); + sprint (other, "\n"); +// ammo touch sound + sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + +// change to a better weapon if appropriate + + if ( other.weapon == best ) + { + stemp = self; + self = other; + self.weapon = W_BestWeapon(); + W_SetCurrentAmmo (); + self = stemp; + } + +// if changed current ammo, update it + stemp = self; + self = other; + W_SetCurrentAmmo(); + self = stemp; + +// remove it in single player, or setup for respawning in deathmatch + self.model = string_null; + self.solid = SOLID_NOT; + if (deathmatch == 1) + self.nextthink = time + 30; + self.think = SUB_regen; + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + + + + +float WEAPON_BIG2 = 1; + +/*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big +*/ + +void() item_shells = +{ + self.touch = ammo_touch; + + if (self.spawnflags & WEAPON_BIG2) + { + precache_model ("maps/b_shell1.bsp"); + setmodel (self, "maps/b_shell1.bsp"); + self.aflag = 40; + } + else + { + precache_model ("maps/b_shell0.bsp"); + setmodel (self, "maps/b_shell0.bsp"); + self.aflag = 20; + } + self.weapon = 1; + self.netname = "shells"; + setsize (self, '0 0 0', '32 32 56'); + StartItem (); +}; + +/*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big +*/ + +void() item_spikes = +{ + self.touch = ammo_touch; + + if (self.spawnflags & WEAPON_BIG2) + { + precache_model ("maps/b_nail1.bsp"); + setmodel (self, "maps/b_nail1.bsp"); + self.aflag = 50; + } + else + { + precache_model ("maps/b_nail0.bsp"); + setmodel (self, "maps/b_nail0.bsp"); + self.aflag = 25; + } + self.weapon = 2; + self.netname = "nails"; + setsize (self, '0 0 0', '32 32 56'); + StartItem (); +}; + +/*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big +*/ + +void() item_rockets = +{ + self.touch = ammo_touch; + + if (self.spawnflags & WEAPON_BIG2) + { + precache_model ("maps/b_rock1.bsp"); + setmodel (self, "maps/b_rock1.bsp"); + self.aflag = 10; + } + else + { + precache_model ("maps/b_rock0.bsp"); + setmodel (self, "maps/b_rock0.bsp"); + self.aflag = 5; + } + self.weapon = 3; + self.netname = "rockets"; + setsize (self, '0 0 0', '32 32 56'); + StartItem (); +}; + + +/*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big +*/ + +void() item_cells = +{ + self.touch = ammo_touch; + + if (self.spawnflags & WEAPON_BIG2) + { + precache_model ("maps/b_batt1.bsp"); + setmodel (self, "maps/b_batt1.bsp"); + self.aflag = 12; + } + else + { + precache_model ("maps/b_batt0.bsp"); + setmodel (self, "maps/b_batt0.bsp"); + self.aflag = 6; + } + self.weapon = 4; + self.netname = "cells"; + setsize (self, '0 0 0', '32 32 56'); + StartItem (); +}; + + +/*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big +DO NOT USE THIS!!!! IT WILL BE REMOVED! +*/ + +float WEAPON_SHOTGUN = 1; +float WEAPON_ROCKET = 2; +float WEAPON_SPIKES = 4; +float WEAPON_BIG = 8; +void() item_weapon = +{ + self.touch = ammo_touch; + + if (self.spawnflags & WEAPON_SHOTGUN) + { + if (self.spawnflags & WEAPON_BIG) + { + precache_model ("maps/b_shell1.bsp"); + setmodel (self, "maps/b_shell1.bsp"); + self.aflag = 40; + } + else + { + precache_model ("maps/b_shell0.bsp"); + setmodel (self, "maps/b_shell0.bsp"); + self.aflag = 20; + } + self.weapon = 1; + self.netname = "shells"; + } + + if (self.spawnflags & WEAPON_SPIKES) + { + if (self.spawnflags & WEAPON_BIG) + { + precache_model ("maps/b_nail1.bsp"); + setmodel (self, "maps/b_nail1.bsp"); + self.aflag = 40; + } + else + { + precache_model ("maps/b_nail0.bsp"); + setmodel (self, "maps/b_nail0.bsp"); + self.aflag = 20; + } + self.weapon = 2; + self.netname = "spikes"; + } + + if (self.spawnflags & WEAPON_ROCKET) + { + if (self.spawnflags & WEAPON_BIG) + { + precache_model ("maps/b_rock1.bsp"); + setmodel (self, "maps/b_rock1.bsp"); + self.aflag = 10; + } + else + { + precache_model ("maps/b_rock0.bsp"); + setmodel (self, "maps/b_rock0.bsp"); + self.aflag = 5; + } + self.weapon = 3; + self.netname = "rockets"; + } + + setsize (self, '0 0 0', '32 32 56'); + StartItem (); +}; + + +/* +=============================================================================== + +KEYS + +=============================================================================== +*/ + +void() key_touch = +{ + if (other.classname != "player") + return; + if (other.health <= 0) + return; + if (other.items & self.items) + return; + + sprint (other, "You got the "); + sprint (other, self.netname); + sprint (other,"\n"); + + sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + other.items = other.items | self.items; + + if (!coop) + { + self.solid = SOLID_NOT; + self.model = string_null; + } + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + + +void() key_setsounds = +{ + if (world.worldtype == 0) + { + precache_sound ("misc/medkey.wav"); + self.noise = "misc/medkey.wav"; + } + if (world.worldtype == 1) + { + precache_sound ("misc/runekey.wav"); + self.noise = "misc/runekey.wav"; + } + if (world.worldtype == 2) + { + precache_sound2 ("misc/basekey.wav"); + self.noise = "misc/basekey.wav"; + } +}; + +/*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) +SILVER key +In order for keys to work +you MUST set your maps +worldtype to one of the +following: +0: medieval +1: metal +2: base +*/ + +void() item_key1 = +{ + if (world.worldtype == 0) + { + precache_model ("progs/w_s_key.mdl"); + setmodel (self, "progs/w_s_key.mdl"); + self.netname = "silver key"; + } + else if (world.worldtype == 1) + { + precache_model ("progs/m_s_key.mdl"); + setmodel (self, "progs/m_s_key.mdl"); + self.netname = "silver runekey"; + } + else if (world.worldtype == 2) + { + precache_model2 ("progs/b_s_key.mdl"); + setmodel (self, "progs/b_s_key.mdl"); + self.netname = "silver keycard"; + } + key_setsounds(); + self.touch = key_touch; + self.items = IT_KEY1; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + +/*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) +GOLD key +In order for keys to work +you MUST set your maps +worldtype to one of the +following: +0: medieval +1: metal +2: base +*/ + +void() item_key2 = +{ + if (world.worldtype == 0) + { + precache_model ("progs/w_g_key.mdl"); + setmodel (self, "progs/w_g_key.mdl"); + self.netname = "gold key"; + } + if (world.worldtype == 1) + { + precache_model ("progs/m_g_key.mdl"); + setmodel (self, "progs/m_g_key.mdl"); + self.netname = "gold runekey"; + } + if (world.worldtype == 2) + { + precache_model2 ("progs/b_g_key.mdl"); + setmodel (self, "progs/b_g_key.mdl"); + self.netname = "gold keycard"; + } + key_setsounds(); + self.touch = key_touch; + self.items = IT_KEY2; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + + + +/* +=============================================================================== + +END OF LEVEL RUNES + +=============================================================================== +*/ + +void() sigil_touch = +{ + if (other.classname != "player") + return; + if (other.health <= 0) + return; + + centerprint (other, "You got the rune!"); + + sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + self.solid = SOLID_NOT; + self.model = string_null; + serverflags = serverflags | (self.spawnflags & 15); + self.classname = ""; // so rune doors won't find it + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + + +/*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4 +End of level sigil, pick up to end episode and return to jrstart. +*/ + +void() item_sigil = +{ + if (!self.spawnflags) + objerror ("no spawnflags"); + + precache_sound ("misc/runekey.wav"); + self.noise = "misc/runekey.wav"; + + if (self.spawnflags & 1) + { + precache_model ("progs/end1.mdl"); + setmodel (self, "progs/end1.mdl"); + } + if (self.spawnflags & 2) + { + precache_model2 ("progs/end2.mdl"); + setmodel (self, "progs/end2.mdl"); + } + if (self.spawnflags & 4) + { + precache_model2 ("progs/end3.mdl"); + setmodel (self, "progs/end3.mdl"); + } + if (self.spawnflags & 8) + { + precache_model2 ("progs/end4.mdl"); + setmodel (self, "progs/end4.mdl"); + } + + self.touch = sigil_touch; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + +/* +=============================================================================== + +POWERUPS + +=============================================================================== +*/ + +void() powerup_touch; + + +void() powerup_touch = +{ + if (other.classname != "player") + return; + if (other.health <= 0) + return; + + sprint (other, "You got the "); + sprint (other, self.netname); + sprint (other,"\n"); + + if (deathmatch) + { + self.mdl = self.model; + + if ((self.classname == "item_artifact_invulnerability") || + (self.classname == "item_artifact_invisibility")) + self.nextthink = time + 60*5; + else + self.nextthink = time + 60; + + self.think = SUB_regen; + } + + sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + self.solid = SOLID_NOT; + other.items = other.items | self.items; + self.model = string_null; + +// do the apropriate action + if (self.classname == "item_artifact_envirosuit") + { + other.rad_time = 1; + other.radsuit_finished = time + 30; + } + + if (self.classname == "item_artifact_invulnerability") + { + other.invincible_time = 1; + other.invincible_finished = time + 30; + } + + if (self.classname == "item_artifact_invisibility") + { + other.invisible_time = 1; + other.invisible_finished = time + 30; + } + + if (self.classname == "item_artifact_super_damage") + { + other.super_time = 1; + other.super_damage_finished = time + 30; + } + + activator = other; + SUB_UseTargets(); // fire all targets / killtargets +}; + + + +/*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32) +Player is invulnerable for 30 seconds +*/ +void() item_artifact_invulnerability = +{ + self.touch = powerup_touch; + + precache_model ("progs/invulner.mdl"); + precache_sound ("items/protect.wav"); + precache_sound ("items/protect2.wav"); + precache_sound ("items/protect3.wav"); + self.noise = "items/protect.wav"; + setmodel (self, "progs/invulner.mdl"); + self.netname = "Pentagram of Protection"; + self.items = IT_INVULNERABILITY; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + +/*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32) +Player takes no damage from water or slime for 30 seconds +*/ +void() item_artifact_envirosuit = +{ + self.touch = powerup_touch; + + precache_model ("progs/suit.mdl"); + precache_sound ("items/suit.wav"); + precache_sound ("items/suit2.wav"); + self.noise = "items/suit.wav"; + setmodel (self, "progs/suit.mdl"); + self.netname = "Biosuit"; + self.items = IT_SUIT; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + + +/*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32) +Player is invisible for 30 seconds +*/ +void() item_artifact_invisibility = +{ + self.touch = powerup_touch; + + precache_model ("progs/invisibl.mdl"); + precache_sound ("items/inv1.wav"); + precache_sound ("items/inv2.wav"); + precache_sound ("items/inv3.wav"); + self.noise = "items/inv1.wav"; + setmodel (self, "progs/invisibl.mdl"); + self.netname = "Ring of Shadows"; + self.items = IT_INVISIBILITY; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + + +/*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32) +The next attack from the player will do 4x damage +*/ +void() item_artifact_super_damage = +{ + self.touch = powerup_touch; + + precache_model ("progs/quaddama.mdl"); + precache_sound ("items/damage.wav"); + precache_sound ("items/damage2.wav"); + precache_sound ("items/damage3.wav"); + self.noise = "items/damage.wav"; + setmodel (self, "progs/quaddama.mdl"); + self.netname = "Quad Damage"; + self.items = IT_QUAD; + setsize (self, '-16 -16 -24', '16 16 32'); + StartItem (); +}; + + + +/* +=============================================================================== + +PLAYER BACKPACKS + +=============================================================================== +*/ + +void() BackpackTouch = +{ + local string s; + local float best, old, new; + local entity stemp; + local float acount; + + if (other.classname != "player") + return; + if (other.health <= 0) + return; + + acount = 0; + sprint (other, "You get "); + + if (self.items) + if ((other.items & self.items) == 0) + { + acount = 1; + sprint (other, "the "); + sprint (other, self.netname); + } + +// if the player was using his best weapon, change up to the new one if better + stemp = self; + self = other; + best = W_BestWeapon(); + self = stemp; + +// change weapons + other.ammo_shells = other.ammo_shells + self.ammo_shells; + other.ammo_nails = other.ammo_nails + self.ammo_nails; + other.ammo_rockets = other.ammo_rockets + self.ammo_rockets; + other.ammo_cells = other.ammo_cells + self.ammo_cells; + + new = self.items; + if (!new) + new = other.weapon; + old = other.items; + other.items = other.items | new; + + bound_other_ammo (); + + if (self.ammo_shells) + { + if (acount) + sprint(other, ", "); + acount = 1; + s = ftos(self.ammo_shells); + sprint (other, s); + sprint (other, " shells"); + } + if (self.ammo_nails) + { + if (acount) + sprint(other, ", "); + acount = 1; + s = ftos(self.ammo_nails); + sprint (other, s); + sprint (other, " nails"); + } + if (self.ammo_rockets) + { + if (acount) + sprint(other, ", "); + acount = 1; + s = ftos(self.ammo_rockets); + sprint (other, s); + sprint (other, " rockets"); + } + if (self.ammo_cells) + { + if (acount) + sprint(other, ", "); + acount = 1; + s = ftos(self.ammo_cells); + sprint (other, s); + sprint (other, " cells"); + } + + sprint (other, "\n"); +// backpack touch sound + sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM); + stuffcmd (other, "bf\n"); + +// remove the backpack, change self to the player + remove(self); + self = other; + +// change to the weapon + if (!deathmatch) + self.weapon = new; + else + Deathmatch_Weapon (old, new); + + W_SetCurrentAmmo (); +}; + +/* +=============== +DropBackpack +=============== +*/ +void() DropBackpack = +{ + local entity item; + + if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells)) + return; // nothing in it + + item = spawn(); + item.origin = self.origin - '0 0 24'; + + item.items = self.weapon; + if (item.items == IT_AXE) + item.netname = "Axe"; + else if (item.items == IT_SHOTGUN) + item.netname = "Shotgun"; + else if (item.items == IT_SUPER_SHOTGUN) + item.netname = "Double-barrelled Shotgun"; + else if (item.items == IT_NAILGUN) + item.netname = "Nailgun"; + else if (item.items == IT_SUPER_NAILGUN) + item.netname = "Super Nailgun"; + else if (item.items == IT_GRENADE_LAUNCHER) + item.netname = "Grenade Launcher"; + else if (item.items == IT_ROCKET_LAUNCHER) + item.netname = "Rocket Launcher"; + else if (item.items == IT_LIGHTNING) + item.netname = "Thunderbolt"; + else + item.netname = ""; + + item.ammo_shells = self.ammo_shells; + item.ammo_nails = self.ammo_nails; + item.ammo_rockets = self.ammo_rockets; + item.ammo_cells = self.ammo_cells; + + item.velocity_z = 300; + item.velocity_x = -100 + (random() * 200); + item.velocity_y = -100 + (random() * 200); + + item.flags = FL_ITEM; + item.solid = SOLID_TRIGGER; + item.movetype = MOVETYPE_TOSS; + setmodel (item, "progs/backpack.mdl"); + setsize (item, '-16 -16 0', '16 16 56'); + item.touch = BackpackTouch; + + item.nextthink = time + 120; // remove after 2 minutes + item.think = SUB_Remove; +}; diff --git a/quakec/csqctest/src/ss/knight.qc b/quakec/csqctest/src/ss/knight.qc new file mode 100644 index 000000000..bb26c071e --- /dev/null +++ b/quakec/csqctest/src/ss/knight.qc @@ -0,0 +1,266 @@ +/* +============================================================================== + +KNIGHT + +============================================================================== +*/ + +$cd id1/models/knight +$origin 0 0 24 +$base base +$skin badass3 + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9 + +$frame runb1 runb2 runb3 runb4 runb5 runb6 runb7 runb8 + +//frame runc1 runc2 runc3 runc4 runc5 runc6 + +$frame runattack1 runattack2 runattack3 runattack4 runattack5 +$frame runattack6 runattack7 runattack8 runattack9 runattack10 +$frame runattack11 + +$frame pain1 pain2 pain3 + +$frame painb1 painb2 painb3 painb4 painb5 painb6 painb7 painb8 painb9 +$frame painb10 painb11 + +//frame attack1 attack2 attack3 attack4 attack5 attack6 attack7 +//frame attack8 attack9 attack10 attack11 + +$frame attackb1 attackb1 attackb2 attackb3 attackb4 attackb5 +$frame attackb6 attackb7 attackb8 attackb9 attackb10 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 +$frame walk10 walk11 walk12 walk13 walk14 + +$frame kneel1 kneel2 kneel3 kneel4 kneel5 + +$frame standing2 standing3 standing4 standing5 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 +$frame death9 death10 + +$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8 +$frame deathb9 deathb10 deathb11 + +void() knight_stand1 =[ $stand1, knight_stand2 ] {ai_stand();}; +void() knight_stand2 =[ $stand2, knight_stand3 ] {ai_stand();}; +void() knight_stand3 =[ $stand3, knight_stand4 ] {ai_stand();}; +void() knight_stand4 =[ $stand4, knight_stand5 ] {ai_stand();}; +void() knight_stand5 =[ $stand5, knight_stand6 ] {ai_stand();}; +void() knight_stand6 =[ $stand6, knight_stand7 ] {ai_stand();}; +void() knight_stand7 =[ $stand7, knight_stand8 ] {ai_stand();}; +void() knight_stand8 =[ $stand8, knight_stand9 ] {ai_stand();}; +void() knight_stand9 =[ $stand9, knight_stand1 ] {ai_stand();}; + +void() knight_walk1 =[ $walk1, knight_walk2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "knight/idle.wav", 1, ATTN_IDLE); +ai_walk(3);}; +void() knight_walk2 =[ $walk2, knight_walk3 ] {ai_walk(2);}; +void() knight_walk3 =[ $walk3, knight_walk4 ] {ai_walk(3);}; +void() knight_walk4 =[ $walk4, knight_walk5 ] {ai_walk(4);}; +void() knight_walk5 =[ $walk5, knight_walk6 ] {ai_walk(3);}; +void() knight_walk6 =[ $walk6, knight_walk7 ] {ai_walk(3);}; +void() knight_walk7 =[ $walk7, knight_walk8 ] {ai_walk(3);}; +void() knight_walk8 =[ $walk8, knight_walk9 ] {ai_walk(4);}; +void() knight_walk9 =[ $walk9, knight_walk10 ] {ai_walk(3);}; +void() knight_walk10 =[ $walk10, knight_walk11 ] {ai_walk(3);}; +void() knight_walk11 =[ $walk11, knight_walk12 ] {ai_walk(2);}; +void() knight_walk12 =[ $walk12, knight_walk13 ] {ai_walk(3);}; +void() knight_walk13 =[ $walk13, knight_walk14 ] {ai_walk(4);}; +void() knight_walk14 =[ $walk14, knight_walk1 ] {ai_walk(3);}; + + +void() knight_run1 =[ $runb1, knight_run2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "knight/idle.wav", 1, ATTN_IDLE); +ai_run(16);}; +void() knight_run2 =[ $runb2, knight_run3 ] {ai_run(20);}; +void() knight_run3 =[ $runb3, knight_run4 ] {ai_run(13);}; +void() knight_run4 =[ $runb4, knight_run5 ] {ai_run(7);}; +void() knight_run5 =[ $runb5, knight_run6 ] {ai_run(16);}; +void() knight_run6 =[ $runb6, knight_run7 ] {ai_run(20);}; +void() knight_run7 =[ $runb7, knight_run8 ] {ai_run(14);}; +void() knight_run8 =[ $runb8, knight_run1 ] {ai_run(6);}; + + +void() knight_runatk1 =[ $runattack1, knight_runatk2 ] +{ +if (random() > 0.5) + sound (self, CHAN_WEAPON, "knight/sword2.wav", 1, ATTN_NORM); +else + sound (self, CHAN_WEAPON, "knight/sword1.wav", 1, ATTN_NORM); +ai_charge(20); +}; +void() knight_runatk2 =[ $runattack2, knight_runatk3 ] {ai_charge_side();}; +void() knight_runatk3 =[ $runattack3, knight_runatk4 ] {ai_charge_side();}; +void() knight_runatk4 =[ $runattack4, knight_runatk5 ] {ai_charge_side();}; +void() knight_runatk5 =[ $runattack5, knight_runatk6 ] {ai_melee_side();}; +void() knight_runatk6 =[ $runattack6, knight_runatk7 ] {ai_melee_side();}; +void() knight_runatk7 =[ $runattack7, knight_runatk8 ] {ai_melee_side();}; +void() knight_runatk8 =[ $runattack8, knight_runatk9 ] {ai_melee_side();}; +void() knight_runatk9 =[ $runattack9, knight_runatk10 ] {ai_melee_side();}; +void() knight_runatk10 =[ $runattack10, knight_runatk11 ] {ai_charge_side();}; +void() knight_runatk11 =[ $runattack11, knight_run1 ] {ai_charge(10);}; + +void() knight_atk1 =[ $attackb1, knight_atk2 ] +{ +sound (self, CHAN_WEAPON, "knight/sword1.wav", 1, ATTN_NORM); +ai_charge(0);}; +void() knight_atk2 =[ $attackb2, knight_atk3 ] {ai_charge(7);}; +void() knight_atk3 =[ $attackb3, knight_atk4 ] {ai_charge(4);}; +void() knight_atk4 =[ $attackb4, knight_atk5 ] {ai_charge(0);}; +void() knight_atk5 =[ $attackb5, knight_atk6 ] {ai_charge(3);}; +void() knight_atk6 =[ $attackb6, knight_atk7 ] {ai_charge(4); ai_melee();}; +void() knight_atk7 =[ $attackb7, knight_atk8 ] {ai_charge(1); ai_melee();}; +void() knight_atk8 =[ $attackb8, knight_atk9 ] {ai_charge(3); +ai_melee();}; +void() knight_atk9 =[ $attackb9, knight_atk10] {ai_charge(1);}; +void() knight_atk10=[ $attackb10, knight_run1 ] {ai_charge(5);}; + +//void() knight_atk9 =[ $attack9, knight_atk10 ] {}; +//void() knight_atk10 =[ $attack10, knight_atk11 ] {}; +//void() knight_atk11 =[ $attack11, knight_run1 ] {}; + +//=========================================================================== + +void() knight_pain1 =[ $pain1, knight_pain2 ] {}; +void() knight_pain2 =[ $pain2, knight_pain3 ] {}; +void() knight_pain3 =[ $pain3, knight_run1 ] {}; + +void() knight_painb1 =[ $painb1, knight_painb2 ] {ai_painforward(0);}; +void() knight_painb2 =[ $painb2, knight_painb3 ] {ai_painforward(3);}; +void() knight_painb3 =[ $painb3, knight_painb4 ] {}; +void() knight_painb4 =[ $painb4, knight_painb5 ] {}; +void() knight_painb5 =[ $painb5, knight_painb6 ] {ai_painforward(2);}; +void() knight_painb6 =[ $painb6, knight_painb7 ] {ai_painforward(4);}; +void() knight_painb7 =[ $painb7, knight_painb8 ] {ai_painforward(2);}; +void() knight_painb8 =[ $painb8, knight_painb9 ] {ai_painforward(5);}; +void() knight_painb9 =[ $painb9, knight_painb10 ] {ai_painforward(5);}; +void() knight_painb10 =[ $painb10, knight_painb11 ] {ai_painforward(0);}; +void() knight_painb11 =[ $painb11, knight_run1 ] {}; + +void(entity attacker, float damage) knight_pain = +{ + local float r; + + if (self.pain_finished > time) + return; + + r = random(); + + sound (self, CHAN_VOICE, "knight/khurt.wav", 1, ATTN_NORM); + if (r < 0.85) + { + knight_pain1 (); + self.pain_finished = time + 1; + } + else + { + knight_painb1 (); + self.pain_finished = time + 1; + } + +}; + +//=========================================================================== + +void() knight_bow1 =[ $kneel1, knight_bow2 ] {ai_turn();}; +void() knight_bow2 =[ $kneel2, knight_bow3 ] {ai_turn();}; +void() knight_bow3 =[ $kneel3, knight_bow4 ] {ai_turn();}; +void() knight_bow4 =[ $kneel4, knight_bow5 ] {ai_turn();}; + +void() knight_bow5 =[ $kneel5, knight_bow5 ] {ai_turn();}; + +void() knight_bow6 =[ $kneel4, knight_bow7 ] {ai_turn();}; +void() knight_bow7 =[ $kneel3, knight_bow8 ] {ai_turn();}; +void() knight_bow8 =[ $kneel2, knight_bow9 ] {ai_turn();}; +void() knight_bow9 =[ $kneel1, knight_bow10 ] {ai_turn();}; +void() knight_bow10 =[ $walk1, knight_walk1 ] {ai_turn();}; + + + +void() knight_die1 =[ $death1, knight_die2 ] {}; +void() knight_die2 =[ $death2, knight_die3 ] {}; +void() knight_die3 =[ $death3, knight_die4 ] +{self.solid = SOLID_NOT;}; +void() knight_die4 =[ $death4, knight_die5 ] {}; +void() knight_die5 =[ $death5, knight_die6 ] {}; +void() knight_die6 =[ $death6, knight_die7 ] {}; +void() knight_die7 =[ $death7, knight_die8 ] {}; +void() knight_die8 =[ $death8, knight_die9 ] {}; +void() knight_die9 =[ $death9, knight_die10] {}; +void() knight_die10=[ $death10, knight_die10] {}; + + +void() knight_dieb1 =[ $deathb1, knight_dieb2 ] {}; +void() knight_dieb2 =[ $deathb2, knight_dieb3 ] {}; +void() knight_dieb3 =[ $deathb3, knight_dieb4 ] +{self.solid = SOLID_NOT;}; +void() knight_dieb4 =[ $deathb4, knight_dieb5 ] {}; +void() knight_dieb5 =[ $deathb5, knight_dieb6 ] {}; +void() knight_dieb6 =[ $deathb6, knight_dieb7 ] {}; +void() knight_dieb7 =[ $deathb7, knight_dieb8 ] {}; +void() knight_dieb8 =[ $deathb8, knight_dieb9 ] {}; +void() knight_dieb9 =[ $deathb9, knight_dieb10] {}; +void() knight_dieb10 = [ $deathb10, knight_dieb11] {}; +void() knight_dieb11 = [ $deathb11, knight_dieb11] {}; + + +void() knight_die = +{ +// check for gib + if (self.health < -40) + { + ThrowCSQCGibs(GIB_KNIGHT); + return; + } + +// regular death + sound (self, CHAN_VOICE, "knight/kdeath.wav", 1, ATTN_NORM); + if (random() < 0.5) + knight_die1 (); + else + knight_dieb1 (); +}; + + +/*QUAKED monster_knight (1 0 0) (-16 -16 -24) (16 16 40) Ambush +*/ +void() monster_knight = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/knight.mdl"); + precache_model ("progs/h_knight.mdl"); + + precache_sound ("knight/kdeath.wav"); + precache_sound ("knight/khurt.wav"); + precache_sound ("knight/ksight.wav"); + precache_sound ("knight/sword1.wav"); + precache_sound ("knight/sword2.wav"); + precache_sound ("knight/idle.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/knight.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 75; + + self.th_stand = knight_stand1; + self.th_walk = knight_walk1; + self.th_run = knight_run1; + self.th_melee = knight_atk1; + self.th_pain = knight_pain; + self.th_die = knight_die; + + walkmonster_start (); +}; diff --git a/quakec/csqctest/src/ss/misc.qc b/quakec/csqctest/src/ss/misc.qc new file mode 100644 index 000000000..0eab91d53 --- /dev/null +++ b/quakec/csqctest/src/ss/misc.qc @@ -0,0 +1,671 @@ + +/*QUAKED info_null (0 0.5 0) (-4 -4 -4) (4 4 4) +Used as a positional target for spotlights, etc. +*/ +void() info_null = +{ + remove(self); +}; + +/*QUAKED info_notnull (0 0.5 0) (-4 -4 -4) (4 4 4) +Used as a positional target for lightning. +*/ +void() info_notnull = +{ +}; + +//============================================================================ + +float START_OFF = 1; + +void() light_use = +{ + if (self.spawnflags & START_OFF) + { + lightstyle(self.style, "m"); + self.spawnflags = self.spawnflags - START_OFF; + } + else + { + lightstyle(self.style, "a"); + self.spawnflags = self.spawnflags + START_OFF; + } +}; + +/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) START_OFF +Non-displayed light. +Default light value is 300 +Default style is 0 +If targeted, it will toggle between on or off. +*/ +void() light = +{ + if (!self.targetname) + { // inert light + remove(self); + return; + } + + if (self.style >= 32) + { + self.use = light_use; + if (self.spawnflags & START_OFF) + lightstyle(self.style, "a"); + else + lightstyle(self.style, "m"); + } +}; + +/*QUAKED light_fluoro (0 1 0) (-8 -8 -8) (8 8 8) START_OFF +Non-displayed light. +Default light value is 300 +Default style is 0 +If targeted, it will toggle between on or off. +Makes steady fluorescent humming sound +*/ +void() light_fluoro = +{ + if (self.style >= 32) + { + self.use = light_use; + if (self.spawnflags & START_OFF) + lightstyle(self.style, "a"); + else + lightstyle(self.style, "m"); + } + + precache_sound ("ambience/fl_hum1.wav"); + ambientsound (self.origin, "ambience/fl_hum1.wav", 0.5, ATTN_STATIC); +}; + +/*QUAKED light_fluorospark (0 1 0) (-8 -8 -8) (8 8 8) +Non-displayed light. +Default light value is 300 +Default style is 10 +Makes sparking, broken fluorescent sound +*/ +void() light_fluorospark = +{ + if (!self.style) + self.style = 10; + + precache_sound ("ambience/buzz1.wav"); + ambientsound (self.origin, "ambience/buzz1.wav", 0.5, ATTN_STATIC); +}; + +/*QUAKED light_globe (0 1 0) (-8 -8 -8) (8 8 8) +Sphere globe light. +Default light value is 300 +Default style is 0 +*/ +void() light_globe = +{ + precache_model ("progs/s_light.spr"); + setmodel (self, "progs/s_light.spr"); + makestatic (self); +}; + +void() FireAmbient = +{ + precache_sound ("ambience/fire1.wav"); +// attenuate fast + ambientsound (self.origin, "ambience/fire1.wav", 0.5, ATTN_STATIC); +}; + +/*QUAKED light_torch_small_walltorch (0 .5 0) (-10 -10 -20) (10 10 20) +Short wall torch +Default light value is 200 +Default style is 0 +*/ +void() light_torch_small_walltorch = +{ + precache_model ("progs/flame.mdl"); + setmodel (self, "progs/flame.mdl"); + FireAmbient (); + makestatic (self); +}; + +/*QUAKED light_flame_large_yellow (0 1 0) (-10 -10 -12) (12 12 18) +Large yellow flame ball +*/ +void() light_flame_large_yellow = +{ + precache_model ("progs/flame2.mdl"); + setmodel (self, "progs/flame2.mdl"); + self.frame = 1; + FireAmbient (); + makestatic (self); +}; + +/*QUAKED light_flame_small_yellow (0 1 0) (-8 -8 -8) (8 8 8) START_OFF +Small yellow flame ball +*/ +void() light_flame_small_yellow = +{ + precache_model ("progs/flame2.mdl"); + setmodel (self, "progs/flame2.mdl"); + FireAmbient (); + makestatic (self); +}; + +/*QUAKED light_flame_small_white (0 1 0) (-10 -10 -40) (10 10 40) START_OFF +Small white flame ball +*/ +void() light_flame_small_white = +{ + precache_model ("progs/flame2.mdl"); + setmodel (self, "progs/flame2.mdl"); + FireAmbient (); + makestatic (self); +}; + +//============================================================================ + + +/*QUAKED misc_fireball (0 .5 .8) (-8 -8 -8) (8 8 8) +Lava Balls +*/ + +void() fire_fly; +void() fire_touch; +void() misc_fireball = +{ + + precache_model ("progs/lavaball.mdl"); + self.classname = "fireball"; + self.nextthink = time + (random() * 5); + self.think = fire_fly; + if (!self.speed) + self.speed = 1000; +}; + +void() fire_fly = +{ +local entity fireball; + + fireball = spawn(); + fireball.solid = SOLID_TRIGGER; + fireball.movetype = MOVETYPE_TOSS; + fireball.velocity = '0 0 1000'; + fireball.velocity_x = (random() * 100) - 50; + fireball.velocity_y = (random() * 100) - 50; + fireball.velocity_z = self.speed + (random() * 200); + fireball.classname = "fireball"; + setmodel (fireball, "progs/lavaball.mdl"); + setsize (fireball, '0 0 0', '0 0 0'); + setorigin (fireball, self.origin); + fireball.nextthink = time + 5; + fireball.think = SUB_Remove; + fireball.touch = fire_touch; + + self.nextthink = time + (random() * 5) + 3; + self.think = fire_fly; +}; + + +void() fire_touch = +{ + T_Damage (other, self, self, 20); + remove(self); +}; + +//============================================================================ + + +void() barrel_explode = +{ + self.takedamage = DAMAGE_NO; + self.classname = "explo_box"; + // did say self.owner + T_RadiusDamage (self, self, 160, world); + sound (self, CHAN_VOICE, "weapons/r_exp3.wav", 1, ATTN_NORM); + particle (self.origin, '0 0 0', 75, 255); + + self.origin_z = self.origin_z + 32; + BecomeExplosion (); +}; + + + +/*QUAKED misc_explobox (0 .5 .8) (0 0 0) (32 32 64) +TESTING THING +*/ + +void() misc_explobox = +{ + local float oldz; + + self.solid = SOLID_BBOX; + self.movetype = MOVETYPE_NONE; + precache_model ("maps/b_explob.bsp"); + setmodel (self, "maps/b_explob.bsp"); + precache_sound ("weapons/r_exp3.wav"); + self.health = 20; + self.th_die = barrel_explode; + self.takedamage = DAMAGE_AIM; + + self.origin_z = self.origin_z + 2; + oldz = self.origin_z; + droptofloor(); + if (oldz - self.origin_z > 250) + { + dprint ("item fell out of level at "); + dprint (vtos(self.origin)); + dprint ("\n"); + remove(self); + } +}; + + + + +/*QUAKED misc_explobox2 (0 .5 .8) (0 0 0) (32 32 64) +Smaller exploding box, REGISTERED ONLY +*/ + +void() misc_explobox2 = +{ + local float oldz; + + self.solid = SOLID_BBOX; + self.movetype = MOVETYPE_NONE; + precache_model2 ("maps/b_exbox2.bsp"); + setmodel (self, "maps/b_exbox2.bsp"); + precache_sound ("weapons/r_exp3.wav"); + self.health = 20; + self.th_die = barrel_explode; + self.takedamage = DAMAGE_AIM; + + self.origin_z = self.origin_z + 2; + oldz = self.origin_z; + droptofloor(); + if (oldz - self.origin_z > 250) + { + dprint ("item fell out of level at "); + dprint (vtos(self.origin)); + dprint ("\n"); + remove(self); + } +}; + +//============================================================================ + +float SPAWNFLAG_SUPERSPIKE = 1; +float SPAWNFLAG_LASER = 2; + +void(vector org, vector vec) LaunchLaser; + +void() spikeshooter_use = +{ + if (self.spawnflags & SPAWNFLAG_LASER) + { + sound (self, CHAN_VOICE, "enforcer/enfire.wav", 1, ATTN_NORM); + LaunchLaser (self.origin, self.movedir); + } + else + { + sound (self, CHAN_VOICE, "weapons/spike2.wav", 1, ATTN_NORM); + launch_spike (self.origin, self.movedir); + newmis.velocity = self.movedir * 500; + if (self.spawnflags & SPAWNFLAG_SUPERSPIKE) + newmis.touch = superspike_touch; + } +}; + +void() shooter_think = +{ + spikeshooter_use (); + self.nextthink = time + self.wait; + newmis.velocity = self.movedir * 500; +}; + + +/*QUAKED trap_spikeshooter (0 .5 .8) (-8 -8 -8) (8 8 8) superspike laser +When triggered, fires a spike in the direction set in QuakeEd. +Laser is only for REGISTERED. +*/ + +void() trap_spikeshooter = +{ + SetMovedir (); + self.use = spikeshooter_use; + if (self.spawnflags & SPAWNFLAG_LASER) + { + precache_model2 ("progs/laser.mdl"); + + precache_sound2 ("enforcer/enfire.wav"); + precache_sound2 ("enforcer/enfstop.wav"); + } + else + precache_sound ("weapons/spike2.wav"); +}; + + +/*QUAKED trap_shooter (0 .5 .8) (-8 -8 -8) (8 8 8) superspike laser +Continuously fires spikes. +"wait" time between spike (1.0 default) +"nextthink" delay before firing first spike, so multiple shooters can be stagered. +*/ +void() trap_shooter = +{ + trap_spikeshooter (); + + if (self.wait == 0) + self.wait = 1; + self.nextthink = self.nextthink + self.wait + self.ltime; + self.think = shooter_think; +}; + + + +/* +=============================================================================== + + +=============================================================================== +*/ + + +void() make_bubbles; +void() bubble_remove; +void() bubble_bob; + +/*QUAKED air_bubbles (0 .5 .8) (-8 -8 -8) (8 8 8) + +testing air bubbles +*/ + +void() air_bubbles = + +{ + if (deathmatch) + { + remove (self); + return; + } + precache_model ("progs/s_bubble.spr"); + self.nextthink = time + 1; + self.think = make_bubbles; +}; + +void() make_bubbles = +{ +local entity bubble; + + bubble = spawn(); + setmodel (bubble, "progs/s_bubble.spr"); + setorigin (bubble, self.origin); + bubble.movetype = MOVETYPE_NOCLIP; + bubble.solid = SOLID_NOT; + bubble.velocity = '0 0 15'; + bubble.nextthink = time + 0.5; + bubble.think = bubble_bob; + bubble.touch = bubble_remove; + bubble.classname = "bubble"; + bubble.frame = 0; + bubble.cnt = 0; + setsize (bubble, '-8 -8 -8', '8 8 8'); + self.nextthink = time + random() + 0.5; + self.think = make_bubbles; +}; + +void() bubble_split = +{ +local entity bubble; + bubble = spawn(); + setmodel (bubble, "progs/s_bubble.spr"); + setorigin (bubble, self.origin); + bubble.movetype = MOVETYPE_NOCLIP; + bubble.solid = SOLID_NOT; + bubble.velocity = self.velocity; + bubble.nextthink = time + 0.5; + bubble.think = bubble_bob; + bubble.touch = bubble_remove; + bubble.classname = "bubble"; + bubble.frame = 1; + bubble.cnt = 10; + setsize (bubble, '-8 -8 -8', '8 8 8'); + self.frame = 1; + self.cnt = 10; + if (self.waterlevel != 3) + remove (self); +}; + +void() bubble_remove = +{ + if (other.classname == self.classname) + { +// dprint ("bump"); + return; + } + remove(self); +}; + +void() bubble_bob = +{ +local float rnd1, rnd2, rnd3; + + self.cnt = self.cnt + 1; + if (self.cnt == 4) + bubble_split(); + if (self.cnt == 20) + remove(self); + + rnd1 = self.velocity_x + (-10 + (random() * 20)); + rnd2 = self.velocity_y + (-10 + (random() * 20)); + rnd3 = self.velocity_z + 10 + random() * 10; + + if (rnd1 > 10) + rnd1 = 5; + if (rnd1 < -10) + rnd1 = -5; + + if (rnd2 > 10) + rnd2 = 5; + if (rnd2 < -10) + rnd2 = -5; + + if (rnd3 < 10) + rnd3 = 15; + if (rnd3 > 30) + rnd3 = 25; + + self.velocity_x = rnd1; + self.velocity_y = rnd2; + self.velocity_z = rnd3; + + self.nextthink = time + 0.5; + self.think = bubble_bob; +}; + +/*~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~> +~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~<~>~*/ + +/*QUAKED viewthing (0 .5 .8) (-8 -8 -8) (8 8 8) + +Just for the debugging level. Don't use +*/ + +void() viewthing = + +{ + self.movetype = MOVETYPE_NONE; + self.solid = SOLID_NOT; + precache_model ("progs/player.mdl"); + setmodel (self, "progs/player.mdl"); +}; + + +/* +============================================================================== + +SIMPLE BMODELS + +============================================================================== +*/ + +void() func_wall_use = +{ // change to alternate textures + self.frame = 1 - self.frame; +}; + +/*QUAKED func_wall (0 .5 .8) ? +This is just a solid wall if not inhibitted +*/ +void() func_wall = +{ + self.angles = '0 0 0'; + self.movetype = MOVETYPE_PUSH; // so it doesn't get pushed by anything + self.solid = SOLID_BSP; + self.use = func_wall_use; + setmodel (self, self.model); +}; + + +/*QUAKED func_illusionary (0 .5 .8) ? +A simple entity that looks solid but lets you walk through it. +*/ +void() func_illusionary = + +{ + self.angles = '0 0 0'; + self.movetype = MOVETYPE_NONE; + self.solid = SOLID_NOT; + setmodel (self, self.model); + makestatic (self); +}; + +/*QUAKED func_episodegate (0 .5 .8) ? E1 E2 E3 E4 +This bmodel will appear if the episode has allready been completed, so players can't reenter it. +*/ +void() func_episodegate = + +{ + if (!(serverflags & self.spawnflags)) + return; // can still enter episode + + self.angles = '0 0 0'; + self.movetype = MOVETYPE_PUSH; // so it doesn't get pushed by anything + self.solid = SOLID_BSP; + self.use = func_wall_use; + setmodel (self, self.model); +}; + +/*QUAKED func_bossgate (0 .5 .8) ? +This bmodel appears unless players have all of the episode sigils. +*/ +void() func_bossgate = + +{ + if ( (serverflags & 15) == 15) + return; // all episodes completed + self.angles = '0 0 0'; + self.movetype = MOVETYPE_PUSH; // so it doesn't get pushed by anything + self.solid = SOLID_BSP; + self.use = func_wall_use; + setmodel (self, self.model); +}; + +//============================================================================ +/*QUAKED ambient_suck_wind (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_suck_wind = +{ + precache_sound ("ambience/suck1.wav"); + ambientsound (self.origin, "ambience/suck1.wav", 1, ATTN_STATIC); +}; + +/*QUAKED ambient_drone (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_drone = +{ + precache_sound ("ambience/drone6.wav"); + ambientsound (self.origin, "ambience/drone6.wav", 0.5, ATTN_STATIC); +}; + +/*QUAKED ambient_flouro_buzz (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_flouro_buzz = +{ + precache_sound ("ambience/buzz1.wav"); + ambientsound (self.origin, "ambience/buzz1.wav", 1, ATTN_STATIC); +}; +/*QUAKED ambient_drip (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_drip = +{ + precache_sound ("ambience/drip1.wav"); + ambientsound (self.origin, "ambience/drip1.wav", 0.5, ATTN_STATIC); +}; +/*QUAKED ambient_comp_hum (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_comp_hum = +{ + precache_sound ("ambience/comp1.wav"); + ambientsound (self.origin, "ambience/comp1.wav", 1, ATTN_STATIC); +}; +/*QUAKED ambient_thunder (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_thunder = +{ + precache_sound ("ambience/thunder1.wav"); + ambientsound (self.origin, "ambience/thunder1.wav", 0.5, ATTN_STATIC); +}; +/*QUAKED ambient_light_buzz (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_light_buzz = +{ + precache_sound ("ambience/fl_hum1.wav"); + ambientsound (self.origin, "ambience/fl_hum1.wav", 0.5, ATTN_STATIC); +}; +/*QUAKED ambient_swamp1 (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_swamp1 = +{ + precache_sound ("ambience/swamp1.wav"); + ambientsound (self.origin, "ambience/swamp1.wav", 0.5, ATTN_STATIC); +}; +/*QUAKED ambient_swamp2 (0.3 0.1 0.6) (-10 -10 -8) (10 10 8) +*/ +void() ambient_swamp2 = +{ + precache_sound ("ambience/swamp2.wav"); + ambientsound (self.origin, "ambience/swamp2.wav", 0.5, ATTN_STATIC); +}; + +//============================================================================ +/* +void() noise_think = +{ + self.nextthink = time + 0.5; + sound (self, 1, "enforcer/enfire.wav", 1, ATTN_NORM); + sound (self, 2, "enforcer/enfstop.wav", 1, ATTN_NORM); + sound (self, 3, "enforcer/sight1.wav", 1, ATTN_NORM); + sound (self, 4, "enforcer/sight2.wav", 1, ATTN_NORM); + sound (self, 5, "enforcer/sight3.wav", 1, ATTN_NORM); + sound (self, 6, "enforcer/sight4.wav", 1, ATTN_NORM); + sound (self, 7, "enforcer/pain1.wav", 1, ATTN_NORM); +}; +*/ +/*QUAKED misc_noisemaker (1 0.5 0) (-10 -10 -10) (10 10 10) + +For optimzation testing, starts a lot of sounds. +*/ +/* +void() misc_noisemaker = + +{ + precache_sound2 ("enforcer/enfire.wav"); + precache_sound2 ("enforcer/enfstop.wav"); + precache_sound2 ("enforcer/sight1.wav"); + precache_sound2 ("enforcer/sight2.wav"); + precache_sound2 ("enforcer/sight3.wav"); + precache_sound2 ("enforcer/sight4.wav"); + precache_sound2 ("enforcer/pain1.wav"); + precache_sound2 ("enforcer/pain2.wav"); + precache_sound2 ("enforcer/death1.wav"); + precache_sound2 ("enforcer/idle1.wav"); + + self.nextthink = time + 0.1 + random(); + self.think = noise_think; +};*/ diff --git a/quakec/csqctest/src/ss/monsters.qc b/quakec/csqctest/src/ss/monsters.qc new file mode 100644 index 000000000..556bd24a0 --- /dev/null +++ b/quakec/csqctest/src/ss/monsters.qc @@ -0,0 +1,232 @@ +/* ALL MONSTERS SHOULD BE 1 0 0 IN COLOR */ + +// name =[framenum, nexttime, nextthink] {code} +// expands to: +// name () +// { +// self.frame=framenum; +// self.nextthink = time + nexttime; +// self.think = nextthink +// +// }; + + +/* +================ +monster_use + +Using a monster makes it angry at the current activator +================ +*/ +void() monster_use = +{ + if (self.enemy) + return; + if (self.health <= 0) + return; + if (activator.items & IT_INVISIBILITY) + return; + if (activator.flags & FL_NOTARGET) + return; + if (activator.classname != "player") + return; + +// delay reaction so if the monster is teleported, its sound is still +// heard + self.enemy = activator; + self.nextthink = time + 0.1; + self.think = FoundTarget; +}; + +/* +================ +monster_death_use + +When a mosnter dies, it fires all of its targets with the current +enemy as activator. +================ +*/ +void() monster_death_use = +{ + +// fall to ground + if (self.flags & FL_FLY) + self.flags = self.flags - FL_FLY; + if (self.flags & FL_SWIM) + self.flags = self.flags - FL_SWIM; + + if (!self.target) + return; + + activator = self.enemy; + SUB_UseTargets (); +}; + + +//============================================================================ + +void() walkmonster_start_go = +{ + self.origin_z = self.origin_z + 1; // raise off floor a bit + droptofloor(); + + if (!walkmove(0,0)) + { + dprint ("walkmonster in wall at: "); + dprint (vtos(self.origin)); + dprint ("\n"); + } + + self.takedamage = DAMAGE_AIM; + + self.ideal_yaw = self.angles * '0 1 0'; + if (!self.yaw_speed) + self.yaw_speed = 20; + self.view_ofs = '0 0 25'; + self.use = monster_use; + + self.flags = self.flags | FL_MONSTER; + + if (self.target!="") + { + self.goalentity = self.movetarget = find(world, targetname, self.target); + self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin); + if (!self.movetarget) + { + dprint ("Monster can't find target at "); + dprint (vtos(self.origin)); + dprint ("\n"); + } +// this used to be an objerror + if (self.movetarget.classname == "path_corner") + self.th_walk (); + else + self.pausetime = 99999999; + self.th_stand (); + } + else + { + self.pausetime = 99999999; + self.th_stand (); + } + +// spread think times so they don't all happen at same time + self.nextthink = self.nextthink + random()*0.5; +}; + + +void() walkmonster_start = +{ +// delay drop to floor to make sure all doors have been spawned +// spread think times so they don't all happen at same time + self.nextthink = self.nextthink + random()*0.5; + self.think = walkmonster_start_go; + total_monsters = total_monsters + 1; +}; + + + +void() flymonster_start_go = +{ + self.takedamage = DAMAGE_AIM; + + self.ideal_yaw = self.angles * '0 1 0'; + if (!self.yaw_speed) + self.yaw_speed = 10; + self.view_ofs = '0 0 25'; + self.use = monster_use; + + self.flags = self.flags | FL_FLY; + self.flags = self.flags | FL_MONSTER; + + if (!walkmove(0,0)) + { + dprint ("flymonster in wall at: "); + dprint (vtos(self.origin)); + dprint ("\n"); + } + + if (self.target!="") + { + self.goalentity = self.movetarget = find(world, targetname, self.target); + if (!self.movetarget) + { + dprint ("Monster can't find target at "); + dprint (vtos(self.origin)); + dprint ("\n"); + } +// this used to be an objerror + if (self.movetarget.classname == "path_corner") + self.th_walk (); + else + self.pausetime = 99999999; + self.th_stand (); + } + else + { + self.pausetime = 99999999; + self.th_stand (); + } +}; + +void() flymonster_start = +{ +// spread think times so they don't all happen at same time + self.nextthink = self.nextthink + random()*0.5; + self.think = flymonster_start_go; + total_monsters = total_monsters + 1; +}; + + +void() swimmonster_start_go = +{ + if (deathmatch) + { + remove(self); + return; + } + + self.takedamage = DAMAGE_AIM; + total_monsters = total_monsters + 1; + + self.ideal_yaw = self.angles * '0 1 0'; + if (!self.yaw_speed) + self.yaw_speed = 10; + self.view_ofs = '0 0 10'; + self.use = monster_use; + + self.flags = self.flags | FL_SWIM; + self.flags = self.flags | FL_MONSTER; + + if (self.target !="") + { + self.goalentity = self.movetarget = find(world, targetname, self.target); + if (!self.movetarget) + { + dprint ("Monster can't find target at "); + dprint (vtos(self.origin)); + dprint ("\n"); + } +// this used to be an objerror + self.ideal_yaw = vectoyaw(self.goalentity.origin - self.origin); + self.th_walk (); + } + else + { + self.pausetime = 99999999; + self.th_stand (); + } + +// spread think times so they don't all happen at same time + self.nextthink = self.nextthink + random()*0.5; +}; + +void() swimmonster_start = +{ +// spread think times so they don't all happen at same time + self.nextthink = self.nextthink + random()*0.5; + self.think = swimmonster_start_go; + total_monsters = total_monsters + 1; +}; + + diff --git a/quakec/csqctest/src/ss/ogre.qc b/quakec/csqctest/src/ss/ogre.qc new file mode 100644 index 000000000..1767a8a20 --- /dev/null +++ b/quakec/csqctest/src/ss/ogre.qc @@ -0,0 +1,460 @@ +/* +============================================================================== + +OGRE + +============================================================================== +*/ + +$cd id1/models/ogre_c +$origin 0 0 24 +$base base +$skin base + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 +$frame walk8 walk9 walk10 walk11 walk12 walk13 walk14 walk15 walk16 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 + +$frame swing1 swing2 swing3 swing4 swing5 swing6 swing7 +$frame swing8 swing9 swing10 swing11 swing12 swing13 swing14 + +$frame smash1 smash2 smash3 smash4 smash5 smash6 smash7 +$frame smash8 smash9 smash10 smash11 smash12 smash13 smash14 + +$frame shoot1 shoot2 shoot3 shoot4 shoot5 shoot6 + +$frame pain1 pain2 pain3 pain4 pain5 + +$frame painb1 painb2 painb3 + +$frame painc1 painc2 painc3 painc4 painc5 painc6 + +$frame paind1 paind2 paind3 paind4 paind5 paind6 paind7 paind8 paind9 paind10 +$frame paind11 paind12 paind13 paind14 paind15 paind16 + +$frame paine1 paine2 paine3 paine4 paine5 paine6 paine7 paine8 paine9 paine10 +$frame paine11 paine12 paine13 paine14 paine15 + +$frame death1 death2 death3 death4 death5 death6 +$frame death7 death8 death9 death10 death11 death12 +$frame death13 death14 + +$frame bdeath1 bdeath2 bdeath3 bdeath4 bdeath5 bdeath6 +$frame bdeath7 bdeath8 bdeath9 bdeath10 + +$frame pull1 pull2 pull3 pull4 pull5 pull6 pull7 pull8 pull9 pull10 pull11 + +//============================================================================= + + +void() OgreGrenadeExplode = +{ + T_RadiusDamage (self, self.owner, 40, world); +#if 1 + BecomeExplosion(); +#else + sound (self, CHAN_VOICE, "weapons/r_exp3.wav", 1, ATTN_NORM); + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_EXPLOSION); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + + self.velocity = '0 0 0'; + self.touch = SUB_Null; + setmodel (self, "progs/s_explod.spr"); + self.solid = SOLID_NOT; + s_explode1 (); +#endif +}; + +void() OgreGrenadeTouch = +{ + if (other == self.owner) + return; // don't explode on owner + if (other.takedamage == DAMAGE_AIM) + { + OgreGrenadeExplode(); + return; + } + sound (self, CHAN_VOICE, "weapons/bounce.wav", 1, ATTN_NORM); // bounce sound + if (self.velocity == '0 0 0') + self.avelocity = '0 0 0'; +}; + +/* +================ +OgreFireGrenade +================ +*/ +void() OgreFireGrenade = +{ + local entity missile; + + self.effects = self.effects | EF_MUZZLEFLASH; + + sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM); + + missile = spawn (); + missile.owner = self; + missile.movetype = MOVETYPE_BOUNCE; + missile.solid = SOLID_BBOX; + +// set missile speed + + makevectors (self.angles); + + missile.velocity = normalize(self.enemy.origin - self.origin); + missile.velocity = missile.velocity * 600; + missile.velocity_z = 200; + + missile.avelocity = '300 300 300'; + + missile.angles = vectoangles(missile.velocity); + + missile.touch = OgreGrenadeTouch; + +// set missile duration + missile.nextthink = time + 2.5; + missile.think = OgreGrenadeExplode; + + setmodel (missile, "progs/grenade.mdl"); + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, self.origin); +}; + + +//============================================================================= + +/* +================ +chainsaw + +FIXME +================ +*/ +void(float side) chainsaw = +{ +local vector delta; +local float ldmg; + + if (!self.enemy) + return; + if (!CanDamage (self.enemy, self)) + return; + + ai_charge(10); + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 100) + return; + + ldmg = (random()*3) * 4; + T_Damage (self.enemy, self, self, ldmg); + + if (side) + { + makevectors (self.angles); + if (side == 1) + SpawnMeatSpray (self.origin + v_forward*16, crandom() * 100 * v_right); + else + SpawnMeatSpray (self.origin + v_forward*16, side * v_right); + } +}; + + +void() ogre_stand1 =[ $stand1, ogre_stand2 ] {ai_stand();}; +void() ogre_stand2 =[ $stand2, ogre_stand3 ] {ai_stand();}; +void() ogre_stand3 =[ $stand3, ogre_stand4 ] {ai_stand();}; +void() ogre_stand4 =[ $stand4, ogre_stand5 ] {ai_stand();}; +void() ogre_stand5 =[ $stand5, ogre_stand6 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "ogre/ogidle.wav", 1, ATTN_IDLE); +ai_stand(); +}; +void() ogre_stand6 =[ $stand6, ogre_stand7 ] {ai_stand();}; +void() ogre_stand7 =[ $stand7, ogre_stand8 ] {ai_stand();}; +void() ogre_stand8 =[ $stand8, ogre_stand9 ] {ai_stand();}; +void() ogre_stand9 =[ $stand9, ogre_stand1 ] {ai_stand();}; + +void() ogre_walk1 =[ $walk1, ogre_walk2 ] {ai_walk(3);}; +void() ogre_walk2 =[ $walk2, ogre_walk3 ] {ai_walk(2);}; +void() ogre_walk3 =[ $walk3, ogre_walk4 ] { +ai_walk(2); +if (random() < 0.2) + sound (self, CHAN_VOICE, "ogre/ogidle.wav", 1, ATTN_IDLE); +}; +void() ogre_walk4 =[ $walk4, ogre_walk5 ] {ai_walk(2);}; +void() ogre_walk5 =[ $walk5, ogre_walk6 ] {ai_walk(2);}; +void() ogre_walk6 =[ $walk6, ogre_walk7 ] { +ai_walk(5); +if (random() < 0.1) + sound (self, CHAN_VOICE, "ogre/ogdrag.wav", 1, ATTN_IDLE); +}; +void() ogre_walk7 =[ $walk7, ogre_walk8 ] {ai_walk(3);}; +void() ogre_walk8 =[ $walk8, ogre_walk9 ] {ai_walk(2);}; +void() ogre_walk9 =[ $walk9, ogre_walk10 ] {ai_walk(3);}; +void() ogre_walk10 =[ $walk10, ogre_walk11 ] {ai_walk(1);}; +void() ogre_walk11 =[ $walk11, ogre_walk12 ] {ai_walk(2);}; +void() ogre_walk12 =[ $walk12, ogre_walk13 ] {ai_walk(3);}; +void() ogre_walk13 =[ $walk13, ogre_walk14 ] {ai_walk(3);}; +void() ogre_walk14 =[ $walk14, ogre_walk15 ] {ai_walk(3);}; +void() ogre_walk15 =[ $walk15, ogre_walk16 ] {ai_walk(3);}; +void() ogre_walk16 =[ $walk16, ogre_walk1 ] {ai_walk(4);}; + +void() ogre_run1 =[ $run1, ogre_run2 ] {ai_run(9); +if (random() < 0.2) + sound (self, CHAN_VOICE, "ogre/ogidle2.wav", 1, ATTN_IDLE); +}; +void() ogre_run2 =[ $run2, ogre_run3 ] {ai_run(12);}; +void() ogre_run3 =[ $run3, ogre_run4 ] {ai_run(8);}; +void() ogre_run4 =[ $run4, ogre_run5 ] {ai_run(22);}; +void() ogre_run5 =[ $run5, ogre_run6 ] {ai_run(16);}; +void() ogre_run6 =[ $run6, ogre_run7 ] {ai_run(4);}; +void() ogre_run7 =[ $run7, ogre_run8 ] {ai_run(13);}; +void() ogre_run8 =[ $run8, ogre_run1 ] {ai_run(24);}; + +void() ogre_swing1 =[ $swing1, ogre_swing2 ] {ai_charge(11); +sound (self, CHAN_WEAPON, "ogre/ogsawatk.wav", 1, ATTN_NORM); +}; +void() ogre_swing2 =[ $swing2, ogre_swing3 ] {ai_charge(1);}; +void() ogre_swing3 =[ $swing3, ogre_swing4 ] {ai_charge(4);}; +void() ogre_swing4 =[ $swing4, ogre_swing5 ] {ai_charge(13);}; +void() ogre_swing5 =[ $swing5, ogre_swing6 ] {ai_charge(9); chainsaw(0);self.angles_y = self.angles_y + random()*25;}; +void() ogre_swing6 =[ $swing6, ogre_swing7 ] {chainsaw(200);self.angles_y = self.angles_y + random()* 25;}; +void() ogre_swing7 =[ $swing7, ogre_swing8 ] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;}; +void() ogre_swing8 =[ $swing8, ogre_swing9 ] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;}; +void() ogre_swing9 =[ $swing9, ogre_swing10 ] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;}; +void() ogre_swing10 =[ $swing10, ogre_swing11 ] {chainsaw(-200);self.angles_y = self.angles_y + random()* 25;}; +void() ogre_swing11 =[ $swing11, ogre_swing12 ] {chainsaw(0);self.angles_y = self.angles_y + random()* 25;}; +void() ogre_swing12 =[ $swing12, ogre_swing13 ] {ai_charge(3);}; +void() ogre_swing13 =[ $swing13, ogre_swing14 ] {ai_charge(8);}; +void() ogre_swing14 =[ $swing14, ogre_run1 ] {ai_charge(9);}; + +void() ogre_smash1 =[ $smash1, ogre_smash2 ] {ai_charge(6); +sound (self, CHAN_WEAPON, "ogre/ogsawatk.wav", 1, ATTN_NORM); +}; +void() ogre_smash2 =[ $smash2, ogre_smash3 ] {ai_charge(0);}; +void() ogre_smash3 =[ $smash3, ogre_smash4 ] {ai_charge(0);}; +void() ogre_smash4 =[ $smash4, ogre_smash5 ] {ai_charge(1);}; +void() ogre_smash5 =[ $smash5, ogre_smash6 ] {ai_charge(4);}; +void() ogre_smash6 =[ $smash6, ogre_smash7 ] {ai_charge(4); chainsaw(0);}; +void() ogre_smash7 =[ $smash7, ogre_smash8 ] {ai_charge(4); chainsaw(0);}; +void() ogre_smash8 =[ $smash8, ogre_smash9 ] {ai_charge(10); chainsaw(0);}; +void() ogre_smash9 =[ $smash9, ogre_smash10 ] {ai_charge(13); chainsaw(0);}; +void() ogre_smash10 =[ $smash10, ogre_smash11 ] {chainsaw(1);}; +void() ogre_smash11 =[ $smash11, ogre_smash12 ] {ai_charge(2); chainsaw(0); +self.nextthink = self.nextthink + random()*0.2;}; // slight variation +void() ogre_smash12 =[ $smash12, ogre_smash13 ] {ai_charge(0);}; +void() ogre_smash13 =[ $smash13, ogre_smash14 ] {ai_charge(4);}; +void() ogre_smash14 =[ $smash14, ogre_run1 ] {ai_charge(12);}; + +void() ogre_nail1 =[ $shoot1, ogre_nail2 ] {ai_face();}; +void() ogre_nail2 =[ $shoot2, ogre_nail3 ] {ai_face();}; +void() ogre_nail3 =[ $shoot2, ogre_nail4 ] {ai_face();}; +void() ogre_nail4 =[ $shoot3, ogre_nail5 ] {ai_face();OgreFireGrenade();}; +void() ogre_nail5 =[ $shoot4, ogre_nail6 ] {ai_face();}; +void() ogre_nail6 =[ $shoot5, ogre_nail7 ] {ai_face();}; +void() ogre_nail7 =[ $shoot6, ogre_run1 ] {ai_face();}; + +void() ogre_pain1 =[ $pain1, ogre_pain2 ] {}; +void() ogre_pain2 =[ $pain2, ogre_pain3 ] {}; +void() ogre_pain3 =[ $pain3, ogre_pain4 ] {}; +void() ogre_pain4 =[ $pain4, ogre_pain5 ] {}; +void() ogre_pain5 =[ $pain5, ogre_run1 ] {}; + + +void() ogre_painb1 =[ $painb1, ogre_painb2 ] {}; +void() ogre_painb2 =[ $painb2, ogre_painb3 ] {}; +void() ogre_painb3 =[ $painb3, ogre_run1 ] {}; + + +void() ogre_painc1 =[ $painc1, ogre_painc2 ] {}; +void() ogre_painc2 =[ $painc2, ogre_painc3 ] {}; +void() ogre_painc3 =[ $painc3, ogre_painc4 ] {}; +void() ogre_painc4 =[ $painc4, ogre_painc5 ] {}; +void() ogre_painc5 =[ $painc5, ogre_painc6 ] {}; +void() ogre_painc6 =[ $painc6, ogre_run1 ] {}; + + +void() ogre_paind1 =[ $paind1, ogre_paind2 ] {}; +void() ogre_paind2 =[ $paind2, ogre_paind3 ] {ai_pain(10);}; +void() ogre_paind3 =[ $paind3, ogre_paind4 ] {ai_pain(9);}; +void() ogre_paind4 =[ $paind4, ogre_paind5 ] {ai_pain(4);}; +void() ogre_paind5 =[ $paind5, ogre_paind6 ] {}; +void() ogre_paind6 =[ $paind6, ogre_paind7 ] {}; +void() ogre_paind7 =[ $paind7, ogre_paind8 ] {}; +void() ogre_paind8 =[ $paind8, ogre_paind9 ] {}; +void() ogre_paind9 =[ $paind9, ogre_paind10 ] {}; +void() ogre_paind10=[ $paind10, ogre_paind11 ] {}; +void() ogre_paind11=[ $paind11, ogre_paind12 ] {}; +void() ogre_paind12=[ $paind12, ogre_paind13 ] {}; +void() ogre_paind13=[ $paind13, ogre_paind14 ] {}; +void() ogre_paind14=[ $paind14, ogre_paind15 ] {}; +void() ogre_paind15=[ $paind15, ogre_paind16 ] {}; +void() ogre_paind16=[ $paind16, ogre_run1 ] {}; + +void() ogre_paine1 =[ $paine1, ogre_paine2 ] {}; +void() ogre_paine2 =[ $paine2, ogre_paine3 ] {ai_pain(10);}; +void() ogre_paine3 =[ $paine3, ogre_paine4 ] {ai_pain(9);}; +void() ogre_paine4 =[ $paine4, ogre_paine5 ] {ai_pain(4);}; +void() ogre_paine5 =[ $paine5, ogre_paine6 ] {}; +void() ogre_paine6 =[ $paine6, ogre_paine7 ] {}; +void() ogre_paine7 =[ $paine7, ogre_paine8 ] {}; +void() ogre_paine8 =[ $paine8, ogre_paine9 ] {}; +void() ogre_paine9 =[ $paine9, ogre_paine10 ] {}; +void() ogre_paine10=[ $paine10, ogre_paine11 ] {}; +void() ogre_paine11=[ $paine11, ogre_paine12 ] {}; +void() ogre_paine12=[ $paine12, ogre_paine13 ] {}; +void() ogre_paine13=[ $paine13, ogre_paine14 ] {}; +void() ogre_paine14=[ $paine14, ogre_paine15 ] {}; +void() ogre_paine15=[ $paine15, ogre_run1 ] {}; + + +void(entity attacker, float damage) ogre_pain = +{ + local float r; + +// don't make multiple pain sounds right after each other + if (self.pain_finished > time) + return; + + sound (self, CHAN_VOICE, "ogre/ogpain1.wav", 1, ATTN_NORM); + + r = random(); + + if (r < 0.25) + { + ogre_pain1 (); + self.pain_finished = time + 1; + } + else if (r < 0.5) + { + ogre_painb1 (); + self.pain_finished = time + 1; + } + else if (r < 0.75) + { + ogre_painc1 (); + self.pain_finished = time + 1; + } + else if (r < 0.88) + { + ogre_paind1 (); + self.pain_finished = time + 2; + } + else + { + ogre_paine1 (); + self.pain_finished = time + 2; + } +}; + +void() ogre_die1 =[ $death1, ogre_die2 ] {}; +void() ogre_die2 =[ $death2, ogre_die3 ] {}; +void() ogre_die3 =[ $death3, ogre_die4 ] +{self.solid = SOLID_NOT; +self.ammo_rockets = 2;DropBackpack();}; +void() ogre_die4 =[ $death4, ogre_die5 ] {}; +void() ogre_die5 =[ $death5, ogre_die6 ] {}; +void() ogre_die6 =[ $death6, ogre_die7 ] {}; +void() ogre_die7 =[ $death7, ogre_die8 ] {}; +void() ogre_die8 =[ $death8, ogre_die9 ] {}; +void() ogre_die9 =[ $death9, ogre_die10 ] {}; +void() ogre_die10 =[ $death10, ogre_die11 ] {}; +void() ogre_die11 =[ $death11, ogre_die12 ] {}; +void() ogre_die12 =[ $death12, ogre_die13 ] {}; +void() ogre_die13 =[ $death13, ogre_die14 ] {}; +void() ogre_die14 =[ $death14, ogre_die14 ] {}; + +void() ogre_bdie1 =[ $bdeath1, ogre_bdie2 ] {}; +void() ogre_bdie2 =[ $bdeath2, ogre_bdie3 ] {ai_forward(5);}; +void() ogre_bdie3 =[ $bdeath3, ogre_bdie4 ] +{self.solid = SOLID_NOT; +self.ammo_rockets = 2;DropBackpack();}; +void() ogre_bdie4 =[ $bdeath4, ogre_bdie5 ] {ai_forward(1);}; +void() ogre_bdie5 =[ $bdeath5, ogre_bdie6 ] {ai_forward(3);}; +void() ogre_bdie6 =[ $bdeath6, ogre_bdie7 ] {ai_forward(7);}; +void() ogre_bdie7 =[ $bdeath7, ogre_bdie8 ] {ai_forward(25);}; +void() ogre_bdie8 =[ $bdeath8, ogre_bdie9 ] {}; +void() ogre_bdie9 =[ $bdeath9, ogre_bdie10 ] {}; +void() ogre_bdie10 =[ $bdeath10, ogre_bdie10 ] {}; + +void() ogre_die = +{ +// check for gib + if (self.health < -80) + { + ThrowCSQCGibs(GIB_OGRE); + return; + } + + sound (self, CHAN_VOICE, "ogre/ogdth.wav", 1, ATTN_NORM); + + if (random() < 0.5) + ogre_die1 (); + else + ogre_bdie1 (); +}; + +void() ogre_melee = +{ + if (random() > 0.5) + ogre_smash1 (); + else + ogre_swing1 (); +}; + + +/*QUAKED monster_ogre (1 0 0) (-32 -32 -24) (32 32 64) Ambush + +*/ +void() monster_ogre = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/ogre.mdl"); + precache_model ("progs/h_ogre.mdl"); + precache_model ("progs/grenade.mdl"); + + precache_sound ("ogre/ogdrag.wav"); + precache_sound ("ogre/ogdth.wav"); + precache_sound ("ogre/ogidle.wav"); + precache_sound ("ogre/ogidle2.wav"); + precache_sound ("ogre/ogpain1.wav"); + precache_sound ("ogre/ogsawatk.wav"); + precache_sound ("ogre/ogwake.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/ogre.mdl"); + + setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX); + self.health = 200; + + self.th_stand = ogre_stand1; + self.th_walk = ogre_walk1; + self.th_run = ogre_run1; + self.th_die = ogre_die; + self.th_melee = ogre_melee; + self.th_missile = ogre_nail1; + self.th_pain = ogre_pain; + + walkmonster_start(); +}; + +void() monster_ogre_marksman = +{ + monster_ogre (); +}; + + diff --git a/quakec/csqctest/src/ss/oldone.qc b/quakec/csqctest/src/ss/oldone.qc new file mode 100644 index 000000000..fe0fead30 --- /dev/null +++ b/quakec/csqctest/src/ss/oldone.qc @@ -0,0 +1,283 @@ +/* +============================================================================== + +OLD ONE + +============================================================================== +*/ +$cd id1/models/old_one +$origin 0 0 24 +$base base +$skin skin +$scale 1 + +void() finale_1; +void() finale_2; +void() finale_3; +void() finale_4; + + +entity shub; + +$frame old1 old2 old3 old4 old5 old6 old7 old8 old9 +$frame old10 old11 old12 old13 old14 old15 old16 old17 old18 old19 +$frame old20 old21 old22 old23 old24 old25 old26 old27 old28 old29 +$frame old30 old31 old32 old33 old34 old35 old36 old37 old38 old39 +$frame old40 old41 old42 old43 old44 old45 old46 + +$frame shake1 shake2 shake3 shake4 shake5 shake6 shake7 shake8 +$frame shake9 shake10 shake11 shake12 shake12 shake13 shake14 +$frame shake15 shake16 shake17 shake18 shake19 shake20 + +//void() old_stand =[ $old1, old_stand ] {}; + +void() old_idle1 =[ $old1, old_idle2 ] {}; +void() old_idle2 =[ $old2, old_idle3 ] {}; +void() old_idle3 =[ $old3, old_idle4 ] {}; +void() old_idle4 =[ $old4, old_idle5 ] {}; +void() old_idle5 =[ $old5, old_idle6 ] {}; +void() old_idle6 =[ $old6, old_idle7 ] {}; +void() old_idle7 =[ $old7, old_idle8 ] {}; +void() old_idle8 =[ $old8, old_idle9 ] {}; +void() old_idle9 =[ $old9, old_idle10 ] {}; +void() old_idle10 =[ $old10, old_idle11 ] {}; +void() old_idle11 =[ $old11, old_idle12 ] {}; +void() old_idle12 =[ $old12, old_idle13 ] {}; +void() old_idle13 =[ $old13, old_idle14 ] {}; +void() old_idle14 =[ $old14, old_idle15 ] {}; +void() old_idle15 =[ $old15, old_idle16 ] {}; +void() old_idle16 =[ $old16, old_idle17 ] {}; +void() old_idle17 =[ $old17, old_idle18 ] {}; +void() old_idle18 =[ $old18, old_idle19 ] {}; +void() old_idle19 =[ $old19, old_idle20 ] {}; +void() old_idle20 =[ $old20, old_idle21 ] {}; +void() old_idle21 =[ $old21, old_idle22 ] {}; +void() old_idle22 =[ $old22, old_idle23 ] {}; +void() old_idle23 =[ $old23, old_idle24 ] {}; +void() old_idle24 =[ $old24, old_idle25 ] {}; +void() old_idle25 =[ $old25, old_idle26 ] {}; +void() old_idle26 =[ $old26, old_idle27 ] {}; +void() old_idle27 =[ $old27, old_idle28 ] {}; +void() old_idle28 =[ $old28, old_idle29 ] {}; +void() old_idle29 =[ $old29, old_idle30 ] {}; +void() old_idle30 =[ $old30, old_idle31 ] {}; +void() old_idle31 =[ $old31, old_idle32 ] {}; +void() old_idle32 =[ $old32, old_idle33 ] {}; +void() old_idle33 =[ $old33, old_idle34 ] {}; +void() old_idle34 =[ $old34, old_idle35 ] {}; +void() old_idle35 =[ $old35, old_idle36 ] {}; +void() old_idle36 =[ $old36, old_idle37 ] {}; +void() old_idle37 =[ $old37, old_idle38 ] {}; +void() old_idle38 =[ $old38, old_idle39 ] {}; +void() old_idle39 =[ $old39, old_idle40 ] {}; +void() old_idle40 =[ $old40, old_idle41 ] {}; +void() old_idle41 =[ $old41, old_idle42 ] {}; +void() old_idle42 =[ $old42, old_idle43 ] {}; +void() old_idle43 =[ $old43, old_idle44 ] {}; +void() old_idle44 =[ $old44, old_idle45 ] {}; +void() old_idle45 =[ $old45, old_idle46 ] {}; +void() old_idle46 =[ $old46, old_idle1 ] {}; + + +void() old_thrash1 =[ $shake1, old_thrash2 ] {lightstyle(0, "m");}; +void() old_thrash2 =[ $shake2, old_thrash3 ] {lightstyle(0, "k");}; +void() old_thrash3 =[ $shake3, old_thrash4 ] {lightstyle(0, "k");}; +void() old_thrash4 =[ $shake4, old_thrash5 ] {lightstyle(0, "i");}; +void() old_thrash5 =[ $shake5, old_thrash6 ] {lightstyle(0, "g");}; +void() old_thrash6 =[ $shake6, old_thrash7 ] {lightstyle(0, "e");}; +void() old_thrash7 =[ $shake7, old_thrash8 ] {lightstyle(0, "c");}; +void() old_thrash8 =[ $shake8, old_thrash9 ] {lightstyle(0, "a");}; +void() old_thrash9 =[ $shake9, old_thrash10 ] {lightstyle(0, "c");}; +void() old_thrash10 =[ $shake10, old_thrash11 ] {lightstyle(0, "e");}; +void() old_thrash11 =[ $shake11, old_thrash12 ] {lightstyle(0, "g");}; +void() old_thrash12 =[ $shake12, old_thrash13 ] {lightstyle(0, "i");}; +void() old_thrash13 =[ $shake13, old_thrash14 ] {lightstyle(0, "k");}; +void() old_thrash14 =[ $shake14, old_thrash15 ] {lightstyle(0, "m");}; +void() old_thrash15 =[ $shake15, old_thrash16 ] {lightstyle(0, "m"); +self.cnt = self.cnt + 1; +if (self.cnt != 3) + self.think = old_thrash1; +}; +void() old_thrash16 =[ $shake16, old_thrash17 ] {lightstyle(0, "g");}; +void() old_thrash17 =[ $shake17, old_thrash18 ] {lightstyle(0, "c");}; +void() old_thrash18 =[ $shake18, old_thrash19 ] {lightstyle(0, "b");}; +void() old_thrash19 =[ $shake19, old_thrash20 ] {lightstyle(0, "a");}; +void() old_thrash20 =[ $shake20, old_thrash20 ] {finale_4();}; + +//============================================================================ + +void() finale_1 = +{ + local entity pos, pl; + local entity timer; + + intermission_exittime = time + 10000000; // never allow exit + intermission_running = 1; + + // find the intermission spot + pos = find (world, classname, "info_intermission"); + if (!pos) + error ("no info_intermission"); + pl = find (world, classname, "misc_teleporttrain"); + if (!pl) + error ("no teleporttrain"); + remove (pl); + + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, ""); + + pl = find (world, classname, "player"); + while (pl != world) + { + pl.view_ofs = '0 0 0'; + pl.angles = other.v_angle = pos.mangle; + pl.fixangle = TRUE; // turn this way immediately + pl.map = self.map; + pl.nextthink = time + 0.5; + pl.takedamage = DAMAGE_NO; + pl.solid = SOLID_NOT; + pl.movetype = MOVETYPE_NONE; + pl.modelindex = 0; + setorigin (pl, pos.origin); + pl = find (pl, classname, "player"); + } + + // make fake versions of all players as standins, and move the real + // players to the intermission spot + + // wait for 1 second + timer = spawn(); + timer.nextthink = time + 1; + timer.think = finale_2; +}; + +void() finale_2 = +{ + local vector o; + + // start a teleport splash inside shub + + o = shub.origin - '0 100 0'; + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_TELEPORT); + WriteCoord (MSG_BROADCAST, o_x); + WriteCoord (MSG_BROADCAST, o_y); + WriteCoord (MSG_BROADCAST, o_z); + + sound (shub, CHAN_VOICE, "misc/r_tele1.wav", 1, ATTN_NORM); + + self.nextthink = time + 2; + self.think = finale_3; +}; + +void() finale_3 = +{ + // start shub thrashing wildly + shub.think = old_thrash1; + sound (shub, CHAN_VOICE, "boss2/death.wav", 1, ATTN_NORM); + lightstyle(0, "abcdefghijklmlkjihgfedcb"); +}; + +void() finale_4 = +{ + // throw tons of meat chunks + local vector oldo; + local float x, y, z; + local float r; + local entity n; + + sound (self, CHAN_VOICE, "boss2/pop2.wav", 1, ATTN_NORM); + + oldo = self.origin; + + z = 16; + while (z <= 144) + { + x = -64; + while (x <= 64) + { + y = -64; + while (y <= 64) + { + self.origin_x = oldo_x + x; + self.origin_y = oldo_y + y; + self.origin_z = oldo_z + z; + + r = random(); + if (r < 0.3) + ThrowGib ("progs/gib1.mdl", -999); + else if (r < 0.6) + ThrowGib ("progs/gib2.mdl", -999); + else + ThrowGib ("progs/gib3.mdl", -999); + y = y + 32; + } + x = x + 32; + } + z = z + 96; + } + // start the end text + WriteByte (MSG_ALL, SVC_FINALE); + WriteString (MSG_ALL, "Congratulations and well done! You have\nbeaten the hideous Shub-Niggurath, and\nher hundreds of ugly changelings and\nmonsters. You have proven that your\nskill and your cunning are greater than\nall the powers of Quake. You are the\nmaster now. Id Software salutes you."); + +// put a player model down + n = spawn(); + setmodel (n, "progs/player.mdl"); + oldo = oldo - '32 264 0'; + setorigin (n, oldo); + n.angles = '0 290 0'; + n.frame = 1; + + remove (self); + +// switch cd track + WriteByte (MSG_ALL, SVC_CDTRACK); + WriteByte (MSG_ALL, 3); + WriteByte (MSG_ALL, 3); + lightstyle(0, "m"); +}; + +//============================================================================ + +void () nopain = +{ + self.health = 40000; +}; + +//============================================================================ + + +/*QUAKED monster_oldone (1 0 0) (-16 -16 -24) (16 16 32) +*/ +void() monster_oldone = +{ + if (deathmatch) + { + remove(self); + return; + } + + precache_model2 ("progs/oldone.mdl"); + + precache_sound2 ("boss2/death.wav"); + precache_sound2 ("boss2/idle.wav"); + precache_sound2 ("boss2/sight.wav"); + precache_sound2 ("boss2/pop2.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/oldone.mdl"); + setsize (self, '-160 -128 -24', '160 128 256'); + + self.health = 40000; // kill by telefrag + self.think = old_idle1; + self.nextthink = time + 0.1; + self.takedamage = DAMAGE_YES; + self.th_pain = nopain; + self.th_die = finale_1; + shub = self; + + total_monsters = total_monsters + 1; +}; + diff --git a/quakec/csqctest/src/ss/plats.qc b/quakec/csqctest/src/ss/plats.qc new file mode 100644 index 000000000..8e325c0f3 --- /dev/null +++ b/quakec/csqctest/src/ss/plats.qc @@ -0,0 +1,361 @@ + + +void() plat_center_touch; +void() plat_outside_touch; +void() plat_trigger_use; +void() plat_go_up; +void() plat_go_down; +void() plat_crush; +float PLAT_LOW_TRIGGER = 1; + +void() plat_spawn_inside_trigger = +{ + local entity trigger; + local vector tmin, tmax; + +// +// middle trigger +// + trigger = spawn(); + trigger.touch = plat_center_touch; + trigger.movetype = MOVETYPE_NONE; + trigger.solid = SOLID_TRIGGER; + trigger.enemy = self; + + tmin = self.mins + '25 25 0'; + tmax = self.maxs - '25 25 -8'; + tmin_z = tmax_z - (self.pos1_z - self.pos2_z + 8); + if (self.spawnflags & PLAT_LOW_TRIGGER) + tmax_z = tmin_z + 8; + + if (self.size_x <= 50) + { + tmin_x = (self.mins_x + self.maxs_x) / 2; + tmax_x = tmin_x + 1; + } + if (self.size_y <= 50) + { + tmin_y = (self.mins_y + self.maxs_y) / 2; + tmax_y = tmin_y + 1; + } + + setsize (trigger, tmin, tmax); +}; + +void() plat_hit_top = +{ + sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM); + self.state = STATE_TOP; + self.think = plat_go_down; + self.nextthink = self.ltime + 3; +}; + +void() plat_hit_bottom = +{ + sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM); + self.state = STATE_BOTTOM; +}; + +void() plat_go_down = +{ + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM); + self.state = STATE_DOWN; + SUB_CalcMove (self.pos2, self.speed, plat_hit_bottom); +}; + +void() plat_go_up = +{ + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM); + self.state = STATE_UP; + SUB_CalcMove (self.pos1, self.speed, plat_hit_top); +}; + +void() plat_center_touch = +{ + if (other.classname != "player") + return; + + if (other.health <= 0) + return; + + self = self.enemy; + if (self.state == STATE_BOTTOM) + plat_go_up (); + else if (self.state == STATE_TOP) + self.nextthink = self.ltime + 1; // delay going down +}; + +void() plat_outside_touch = +{ + if (other.classname != "player") + return; + + if (other.health <= 0) + return; + +//dprint ("plat_outside_touch\n"); + self = self.enemy; + if (self.state == STATE_TOP) + plat_go_down (); +}; + +void() plat_trigger_use = +{ + if (self.think) + return; // allready activated + plat_go_down(); +}; + + +void() plat_crush = +{ +//dprint ("plat_crush\n"); + + T_Damage (other, self, self, 1); + + if (self.state == STATE_UP) + plat_go_down (); + else if (self.state == STATE_DOWN) + plat_go_up (); + else + objerror ("plat_crush: bad self.state\n"); +}; + +void() plat_use = +{ + self.use = SUB_Null; + if (self.state != STATE_UP) + objerror ("plat_use: not in up state"); + plat_go_down(); +}; + + +/*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER +speed default 150 + +Plats are always drawn in the extended position, so they will light correctly. + +If the plat is the target of another trigger or button, it will start out disabled in the extended position until it is trigger, when it will lower and become a normal plat. + +If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determined by the model's height. +Set "sounds" to one of the following: +1) base fast +2) chain slow +*/ + + +void() func_plat = +{ + if (!self.t_length) + self.t_length = 80; + if (!self.t_width) + self.t_width = 10; + + if (self.sounds == 0) + self.sounds = 2; +// FIX THIS TO LOAD A GENERIC PLAT SOUND + + if (self.sounds == 1) + { + precache_sound ("plats/plat1.wav"); + precache_sound ("plats/plat2.wav"); + self.noise = "plats/plat1.wav"; + self.noise1 = "plats/plat2.wav"; + } + + if (self.sounds == 2) + { + precache_sound ("plats/medplat1.wav"); + precache_sound ("plats/medplat2.wav"); + self.noise = "plats/medplat1.wav"; + self.noise1 = "plats/medplat2.wav"; + } + + + self.mangle = self.angles; + self.angles = '0 0 0'; + + self.classname = "plat"; + self.solid = SOLID_BSP; + self.movetype = MOVETYPE_PUSH; + setorigin (self, self.origin); + setmodel (self, self.model); + setsize (self, self.mins , self.maxs); + + self.blocked = plat_crush; + if (!self.speed) + self.speed = 150; + +// pos1 is the top position, pos2 is the bottom + self.pos1 = self.origin; + self.pos2 = self.origin; + if (self.height) + self.pos2_z = self.origin_z - self.height; + else + self.pos2_z = self.origin_z - self.size_z + 8; + + self.use = plat_trigger_use; + + plat_spawn_inside_trigger (); // the "start moving" trigger + + if (self.targetname!="") + { + self.state = STATE_UP; + self.use = plat_use; + } + else + { + setorigin (self, self.pos2); + self.state = STATE_BOTTOM; + } +}; + +//============================================================================ + +void() train_next; +void() func_train_find; + +void() train_blocked = +{ + if (time < self.attack_finished) + return; + self.attack_finished = time + 0.5; + T_Damage (other, self, self, self.dmg); +}; +void() train_use = +{ + if (self.think != func_train_find) + return; // already activated + train_next(); +}; + +void() train_wait = +{ + if (self.wait) + { + self.nextthink = self.ltime + self.wait; + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM); + } + else + self.nextthink = self.ltime + 0.1; + + self.think = train_next; +}; + +void() train_next = +{ + local entity targ; + + targ = find (world, targetname, self.target); + self.target = targ.target; + if (!self.target) + objerror ("train_next: no next target"); + if (targ.wait) + self.wait = targ.wait; + else + self.wait = 0; + sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM); + SUB_CalcMove (targ.origin - self.mins, self.speed, train_wait); +}; + +void() func_train_find = + +{ + local entity targ; + + targ = find (world, targetname, self.target); + self.target = targ.target; + setorigin (self, targ.origin - self.mins); + if (!self.targetname) + { // not triggered, so start immediately + self.nextthink = self.ltime + 0.1; + self.think = train_next; + } +}; + +/*QUAKED func_train (0 .5 .8) ? +Trains are moving platforms that players can ride. +The targets origin specifies the min point of the train at each corner. +The train spawns at the first target it is pointing at. +If the train is the target of a button or trigger, it will not begin moving until activated. +speed default 100 +dmg default 2 +sounds +1) ratchet metal + +*/ +void() func_train = +{ + if (!self.speed) + self.speed = 100; + if (!self.target) + objerror ("func_train without a target"); + if (!self.dmg) + self.dmg = 2; + + if (self.sounds == 0) + { + self.noise = ("misc/null.wav"); + precache_sound ("misc/null.wav"); + self.noise1 = ("misc/null.wav"); + precache_sound ("misc/null.wav"); + } + + if (self.sounds == 1) + { + self.noise = ("plats/train2.wav"); + precache_sound ("plats/train2.wav"); + self.noise1 = ("plats/train1.wav"); + precache_sound ("plats/train1.wav"); + } + + self.cnt = 1; + self.solid = SOLID_BSP; + self.movetype = MOVETYPE_PUSH; + self.blocked = train_blocked; + self.use = train_use; + self.classname = "train"; + + setmodel (self, self.model); + setsize (self, self.mins , self.maxs); + setorigin (self, self.origin); + +// start trains on the second frame, to make sure their targets have had +// a chance to spawn + self.nextthink = self.ltime + 0.1; + self.think = func_train_find; +}; + +/*QUAKED misc_teleporttrain (0 .5 .8) (-8 -8 -8) (8 8 8) +This is used for the final bos +*/ +void() misc_teleporttrain = +{ + if (!self.speed) + self.speed = 100; + if (!self.target) + objerror ("func_train without a target"); + + self.cnt = 1; + self.solid = SOLID_NOT; + self.movetype = MOVETYPE_PUSH; + self.blocked = train_blocked; + self.use = train_use; + self.avelocity = '100 200 300'; + + self.noise = ("misc/null.wav"); + precache_sound ("misc/null.wav"); + self.noise1 = ("misc/null.wav"); + precache_sound ("misc/null.wav"); + + precache_model2 ("progs/teleport.mdl"); + setmodel (self, "progs/teleport.mdl"); + setsize (self, self.mins , self.maxs); + setorigin (self, self.origin); + +// start trains on the second frame, to make sure their targets have had +// a chance to spawn + self.nextthink = self.ltime + 0.1; + self.think = func_train_find; +}; + diff --git a/quakec/csqctest/src/ss/player.qc b/quakec/csqctest/src/ss/player.qc new file mode 100644 index 000000000..204c46875 --- /dev/null +++ b/quakec/csqctest/src/ss/player.qc @@ -0,0 +1,700 @@ + +void() bubble_bob; + +/* +============================================================================== + +PLAYER + +============================================================================== +*/ + +$cd id1/models/player_4 +$origin 0 -6 24 +$base base +$skin skin + +// +// running +// +$frame axrun1 axrun2 axrun3 axrun4 axrun5 axrun6 + +$frame rockrun1 rockrun2 rockrun3 rockrun4 rockrun5 rockrun6 + +// +// standing +// +$frame stand1 stand2 stand3 stand4 stand5 + +$frame axstnd1 axstnd2 axstnd3 axstnd4 axstnd5 axstnd6 +$frame axstnd7 axstnd8 axstnd9 axstnd10 axstnd11 axstnd12 + + +// +// pain +// +$frame axpain1 axpain2 axpain3 axpain4 axpain5 axpain6 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + + +// +// death +// + +$frame axdeth1 axdeth2 axdeth3 axdeth4 axdeth5 axdeth6 +$frame axdeth7 axdeth8 axdeth9 + +$frame deatha1 deatha2 deatha3 deatha4 deatha5 deatha6 deatha7 deatha8 +$frame deatha9 deatha10 deatha11 + +$frame deathb1 deathb2 deathb3 deathb4 deathb5 deathb6 deathb7 deathb8 +$frame deathb9 + +$frame deathc1 deathc2 deathc3 deathc4 deathc5 deathc6 deathc7 deathc8 +$frame deathc9 deathc10 deathc11 deathc12 deathc13 deathc14 deathc15 + +$frame deathd1 deathd2 deathd3 deathd4 deathd5 deathd6 deathd7 +$frame deathd8 deathd9 + +$frame deathe1 deathe2 deathe3 deathe4 deathe5 deathe6 deathe7 +$frame deathe8 deathe9 + +// +// attacks +// +$frame nailatt1 nailatt2 + +$frame light1 light2 + +$frame rockatt1 rockatt2 rockatt3 rockatt4 rockatt5 rockatt6 + +$frame shotatt1 shotatt2 shotatt3 shotatt4 shotatt5 shotatt6 + +$frame axatt1 axatt2 axatt3 axatt4 axatt5 axatt6 + +$frame axattb1 axattb2 axattb3 axattb4 axattb5 axattb6 + +$frame axattc1 axattc2 axattc3 axattc4 axattc5 axattc6 + +$frame axattd1 axattd2 axattd3 axattd4 axattd5 axattd6 + + +/* +============================================================================== +PLAYER +============================================================================== +*/ + +void() player_run; + +void() player_stand1 =[ $axstnd1, player_stand1 ] +{ + self.weaponframe=0; + if (self.velocity_x || self.velocity_y) + { + self.walkframe=0; + player_run(); + return; + } + + if (self.weapon == IT_AXE) + { + if (self.walkframe >= 12) + self.walkframe = 0; + self.frame = $axstnd1 + self.walkframe; + } + else + { + if (self.walkframe >= 5) + self.walkframe = 0; + self.frame = $stand1 + self.walkframe; + } + self.walkframe = self.walkframe + 1; +}; + +void() player_run =[ $rockrun1, player_run ] +{ + self.weaponframe=0; + if (!self.velocity_x && !self.velocity_y) + { + self.walkframe=0; + player_stand1(); + return; + } + + if (self.weapon == IT_AXE) + { + if (self.walkframe == 6) + self.walkframe = 0; + self.frame = $axrun1 + self.walkframe; + } + else + { + if (self.walkframe == 6) + self.walkframe = 0; + self.frame = self.frame + self.walkframe; + } + self.walkframe = self.walkframe + 1; +}; + + +void() player_shot1 = [$shotatt1, player_shot2 ] {self.weaponframe=1; +self.effects = self.effects | EF_MUZZLEFLASH;}; +void() player_shot2 = [$shotatt2, player_shot3 ] {self.weaponframe=2;}; +void() player_shot3 = [$shotatt3, player_shot4 ] {self.weaponframe=3;}; +void() player_shot4 = [$shotatt4, player_shot5 ] {self.weaponframe=4;}; +void() player_shot5 = [$shotatt5, player_shot6 ] {self.weaponframe=5;}; +void() player_shot6 = [$shotatt6, player_run ] {self.weaponframe=6;}; + +void() player_axe1 = [$axatt1, player_axe2 ] {self.weaponframe=1;}; +void() player_axe2 = [$axatt2, player_axe3 ] {self.weaponframe=2;}; +void() player_axe3 = [$axatt3, player_axe4 ] {self.weaponframe=3;W_FireAxe();}; +void() player_axe4 = [$axatt4, player_run ] {self.weaponframe=4;}; + +void() player_axeb1 = [$axattb1, player_axeb2 ] {self.weaponframe=5;}; +void() player_axeb2 = [$axattb2, player_axeb3 ] {self.weaponframe=6;}; +void() player_axeb3 = [$axattb3, player_axeb4 ] {self.weaponframe=7;W_FireAxe();}; +void() player_axeb4 = [$axattb4, player_run ] {self.weaponframe=8;}; + +void() player_axec1 = [$axattc1, player_axec2 ] {self.weaponframe=1;}; +void() player_axec2 = [$axattc2, player_axec3 ] {self.weaponframe=2;}; +void() player_axec3 = [$axattc3, player_axec4 ] {self.weaponframe=3;W_FireAxe();}; +void() player_axec4 = [$axattc4, player_run ] {self.weaponframe=4;}; + +void() player_axed1 = [$axattd1, player_axed2 ] {self.weaponframe=5;}; +void() player_axed2 = [$axattd2, player_axed3 ] {self.weaponframe=6;}; +void() player_axed3 = [$axattd3, player_axed4 ] {self.weaponframe=7;W_FireAxe();}; +void() player_axed4 = [$axattd4, player_run ] {self.weaponframe=8;}; + + +//============================================================================ + +void() player_nail1 =[$nailatt1, player_nail2 ] +{ + self.effects = self.effects | EF_MUZZLEFLASH; + + if (!self.button0) + {player_run ();return;} + self.weaponframe = self.weaponframe + 1; + if (self.weaponframe == 9) + self.weaponframe = 1; + SuperDamageSound(); + W_FireSpikes (4); + self.attack_finished = time + 0.2; +}; +void() player_nail2 =[$nailatt2, player_nail1 ] +{ + self.effects = self.effects | EF_MUZZLEFLASH; + + if (!self.button0) + {player_run ();return;} + self.weaponframe = self.weaponframe + 1; + if (self.weaponframe == 9) + self.weaponframe = 1; + SuperDamageSound(); + W_FireSpikes (-4); + self.attack_finished = time + 0.2; +}; + +//============================================================================ + +void() player_light1 =[$light1, player_light2 ] +{ + self.effects = self.effects | EF_MUZZLEFLASH; + + if (!self.button0) + {player_run ();return;} + self.weaponframe = self.weaponframe + 1; + if (self.weaponframe == 5) + self.weaponframe = 1; + SuperDamageSound(); + W_FireLightning(); + self.attack_finished = time + 0.2; +}; +void() player_light2 =[$light2, player_light1 ] +{ + self.effects = self.effects | EF_MUZZLEFLASH; + + if (!self.button0) + {player_run ();return;} + self.weaponframe = self.weaponframe + 1; + if (self.weaponframe == 5) + self.weaponframe = 1; + SuperDamageSound(); + W_FireLightning(); + self.attack_finished = time + 0.2; +}; + +//============================================================================ + + +void() player_rocket1 =[$rockatt1, player_rocket2 ] {self.weaponframe=1; +self.effects = self.effects | EF_MUZZLEFLASH;}; +void() player_rocket2 =[$rockatt2, player_rocket3 ] {self.weaponframe=2;}; +void() player_rocket3 =[$rockatt3, player_rocket4 ] {self.weaponframe=3;}; +void() player_rocket4 =[$rockatt4, player_rocket5 ] {self.weaponframe=4;}; +void() player_rocket5 =[$rockatt5, player_rocket6 ] {self.weaponframe=5;}; +void() player_rocket6 =[$rockatt6, player_run ] {self.weaponframe=6;}; +void(float num_bubbles) DeathBubbles; + +void() PainSound = +{ +local float rs; + + if (self.health < 0) + return; + + if (damage_attacker.classname == "teledeath") + { + sound (self, CHAN_VOICE, "player/teledth1.wav", 1, ATTN_NONE); + return; + } + +// water pain sounds + if (self.watertype == CONTENT_WATER && self.waterlevel == 3) + { + DeathBubbles(1); + if (random() > 0.5) + sound (self, CHAN_VOICE, "player/drown1.wav", 1, ATTN_NORM); + else + sound (self, CHAN_VOICE, "player/drown2.wav", 1, ATTN_NORM); + return; + } + +// slime pain sounds + if (self.watertype == CONTENT_SLIME) + { +// FIX ME put in some steam here + if (random() > 0.5) + sound (self, CHAN_VOICE, "player/lburn1.wav", 1, ATTN_NORM); + else + sound (self, CHAN_VOICE, "player/lburn2.wav", 1, ATTN_NORM); + return; + } + + if (self.watertype == CONTENT_LAVA) + { + if (random() > 0.5) + sound (self, CHAN_VOICE, "player/lburn1.wav", 1, ATTN_NORM); + else + sound (self, CHAN_VOICE, "player/lburn2.wav", 1, ATTN_NORM); + return; + } + + if (self.pain_finished > time) + { + self.axhitme = 0; + return; + } + self.pain_finished = time + 0.5; + +// don't make multiple pain sounds right after each other + +// ax pain sound + if (self.axhitme == 1) + { + self.axhitme = 0; + sound (self, CHAN_VOICE, "player/axhit1.wav", 1, ATTN_NORM); + return; + } + + + rs = rint((random() * 5) + 1); + + self.noise = ""; + if (rs == 1) + self.noise = "player/pain1.wav"; + else if (rs == 2) + self.noise = "player/pain2.wav"; + else if (rs == 3) + self.noise = "player/pain3.wav"; + else if (rs == 4) + self.noise = "player/pain4.wav"; + else if (rs == 5) + self.noise = "player/pain5.wav"; + else + self.noise = "player/pain6.wav"; + + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM); + return; +}; + +void() player_pain1 = [ $pain1, player_pain2 ] {PainSound();self.weaponframe=0;}; +void() player_pain2 = [ $pain2, player_pain3 ] {}; +void() player_pain3 = [ $pain3, player_pain4 ] {}; +void() player_pain4 = [ $pain4, player_pain5 ] {}; +void() player_pain5 = [ $pain5, player_pain6 ] {}; +void() player_pain6 = [ $pain6, player_run ] {}; + +void() player_axpain1 = [ $axpain1, player_axpain2 ] {PainSound();self.weaponframe=0;}; +void() player_axpain2 = [ $axpain2, player_axpain3 ] {}; +void() player_axpain3 = [ $axpain3, player_axpain4 ] {}; +void() player_axpain4 = [ $axpain4, player_axpain5 ] {}; +void() player_axpain5 = [ $axpain5, player_axpain6 ] {}; +void() player_axpain6 = [ $axpain6, player_run ] {}; + +void() player_pain = +{ + if (self.weaponframe) + return; + + if (self.invisible_finished > time) + return; // eyes don't have pain frames + + if (self.weapon == IT_AXE) + player_axpain1 (); + else + player_pain1 (); +}; + +void() player_diea1; +void() player_dieb1; +void() player_diec1; +void() player_died1; +void() player_diee1; +void() player_die_ax1; + +void() DeathBubblesSpawn = +{ +local entity bubble; + if (self.owner.waterlevel != 3) + return; + bubble = spawn(); + setmodel (bubble, "progs/s_bubble.spr"); + setorigin (bubble, self.owner.origin + '0 0 24'); + bubble.movetype = MOVETYPE_NOCLIP; + bubble.solid = SOLID_NOT; + bubble.velocity = '0 0 15'; + bubble.nextthink = time + 0.5; + bubble.think = bubble_bob; + bubble.classname = "bubble"; + bubble.frame = 0; + bubble.cnt = 0; + setsize (bubble, '-8 -8 -8', '8 8 8'); + self.nextthink = time + 0.1; + self.think = DeathBubblesSpawn; + self.air_finished = self.air_finished + 1; + if (self.air_finished >= self.bubble_count) + remove(self); +}; + +void(float num_bubbles) DeathBubbles = +{ +local entity bubble_spawner; + + bubble_spawner = spawn(); + setorigin (bubble_spawner, self.origin); + bubble_spawner.movetype = MOVETYPE_NONE; + bubble_spawner.solid = SOLID_NOT; + bubble_spawner.nextthink = time + 0.1; + bubble_spawner.think = DeathBubblesSpawn; + bubble_spawner.air_finished = 0; + bubble_spawner.owner = self; + bubble_spawner.bubble_count = num_bubbles; + return; +}; + + +void() DeathSound = +{ +local float rs; + + // water death sounds + if (self.waterlevel == 3) + { + DeathBubbles(20); + sound (self, CHAN_VOICE, "player/h2odeath.wav", 1, ATTN_NONE); + return; + } + + rs = rint ((random() * 4) + 1); + if (rs == 1) + self.noise = "player/death1.wav"; + if (rs == 2) + self.noise = "player/death2.wav"; + if (rs == 3) + self.noise = "player/death3.wav"; + if (rs == 4) + self.noise = "player/death4.wav"; + if (rs == 5) + self.noise = "player/death5.wav"; + + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NONE); + return; +}; + + +void() PlayerDead = +{ + self.nextthink = -1; +// allow respawn after a certain time + self.deadflag = DEAD_DEAD; +}; + +vector(float dm) VelocityForDamage = +{ + local vector v; + + v_x = 100 * crandom(); + v_y = 100 * crandom(); + v_z = 200 + 100 * random(); + + if (dm > -50) + { +// dprint ("level 1\n"); + v = v * 0.7; + } + else if (dm > -200) + { +// dprint ("level 3\n"); + v = v * 2; + } + else + v = v * 10; + + return v; +}; + +float(entity ent) NotInCSQC = +{ + return FALSE; +}; + +void(string gibname, float dm) ThrowGib = +{ + local entity new; + + new = spawn(); + new.origin = self.origin; + setmodel (new, gibname); + setsize (new, '0 0 0', '0 0 0'); + new.velocity = VelocityForDamage (dm); + new.movetype = MOVETYPE_BOUNCE; + new.solid = SOLID_NOT; + new.avelocity_x = random()*600; + new.avelocity_y = random()*600; + new.avelocity_z = random()*600; + new.think = SUB_Remove; + new.ltime = time; + new.nextthink = time + 10 + random()*10; + new.frame = 0; + new.flags = 0; + + self.SendEntity = NotInCSQC; +}; + +//fixme: remove +void(string gibname, float dm) ThrowHead = +{ + setmodel (self, gibname); + self.frame = 0; + self.nextthink = -1; + self.movetype = MOVETYPE_BOUNCE; + self.takedamage = DAMAGE_NO; + self.solid = SOLID_NOT; + self.view_ofs = '0 0 8'; + setsize (self, '-16 -16 0', '16 16 56'); + self.velocity = VelocityForDamage (dm); + self.origin_z = self.origin_z - 24; + self.flags = self.flags - (self.flags & FL_ONGROUND); + self.avelocity = crandom() * '0 600 0'; +}; + +float(entity ent) WriteGibs = +{ + WriteByte(MSG_ENTITY, CLASS_GIB); + WriteByte(MSG_ENTITY, self.cnt); + WriteByte(MSG_ENTITY, -self.health); + WriteCoord(MSG_ENTITY, self.origin_x); + WriteCoord(MSG_ENTITY, self.origin_y); + WriteCoord(MSG_ENTITY, self.origin_z); + return TRUE; +}; + +void(float type) ThrowCSQCGibs = +{ + self.cnt = type; + self.Version = self.Version+1; + self.SendEntity = WriteGibs; + if (type != GIB_PLAYER) + { //schedule removal after a second. + self.think = SUB_Remove; + self.nextthink = time+1; + } + + switch(type) + { + case GIB_PLAYER: + ThrowGib ("progs/h_player.mdl", self.health); + break; + case GIB_SOLDIER: + ThrowGib ("progs/h_guard.mdl", self.health); + break; + } + ThrowGib ("progs/gib1.mdl", self.health); + ThrowGib ("progs/gib2.mdl", self.health); + ThrowGib ("progs/gib3.mdl", self.health); +}; + + +void() GibPlayer = +{ + ThrowCSQCGibs(0); + + self.deadflag = DEAD_DEAD; + + if (damage_attacker.classname == "teledeath") + { + sound (self, CHAN_VOICE, "player/teledth1.wav", 1, ATTN_NONE); + return; + } + + if (damage_attacker.classname == "teledeath2") + { + sound (self, CHAN_VOICE, "player/teledth1.wav", 1, ATTN_NONE); + return; + } + + if (random() < 0.5) + sound (self, CHAN_VOICE, "player/gib.wav", 1, ATTN_NONE); + else + sound (self, CHAN_VOICE, "player/udeath.wav", 1, ATTN_NONE); +}; + +void() PlayerDie = +{ + local float i; + + self.items = self.items - (self.items & IT_INVISIBILITY); + self.invisible_finished = 0; // don't die as eyes + self.invincible_finished = 0; + self.super_damage_finished = 0; + self.radsuit_finished = 0; + self.modelindex = modelindex_player; // don't use eyes + + if (deathmatch || coop) + DropBackpack(); + + self.weaponmodel=""; + self.view_ofs = '0 0 -8'; + self.deadflag = DEAD_DYING; + self.solid = SOLID_NOT; + self.flags = self.flags - (self.flags & FL_ONGROUND); + self.movetype = MOVETYPE_TOSS; + if (self.velocity_z < 10) + self.velocity_z = self.velocity_z + random()*300; + + if (self.health < -40) + { + GibPlayer (); + self.modelindex = 0; + return; + } + + DeathSound(); + + self.angles_x = 0; + self.angles_z = 0; + + if (self.weapon == IT_AXE) + { + player_die_ax1 (); + } + else + { + i = 1 + floor(random()*6); + + if (i == 1) + player_diea1(); + else if (i == 2) + player_dieb1(); + else if (i == 3) + player_diec1(); + else if (i == 4) + player_died1(); + else + player_diee1(); + } +}; + +void() set_suicide_frame = +{ // used by kill command and diconnect command + local entity b; + if (self.model != "progs/player.mdl") + return; // already gibbed + self.frame = $deatha11; + self.solid = SOLID_NOT; + self.movetype = MOVETYPE_TOSS; + self.deadflag = DEAD_DEAD; + self.nextthink = -1; +}; + + +void() player_diea1 = [ $deatha1, player_diea2 ] {}; +void() player_diea2 = [ $deatha2, player_diea3 ] {}; +void() player_diea3 = [ $deatha3, player_diea4 ] {}; +void() player_diea4 = [ $deatha4, player_diea5 ] {}; +void() player_diea5 = [ $deatha5, player_diea6 ] {}; +void() player_diea6 = [ $deatha6, player_diea7 ] {}; +void() player_diea7 = [ $deatha7, player_diea8 ] {}; +void() player_diea8 = [ $deatha8, player_diea9 ] {}; +void() player_diea9 = [ $deatha9, player_diea10 ] {}; +void() player_diea10 = [ $deatha10, player_diea11 ] {}; +void() player_diea11 = [ $deatha11, player_diea11 ] {PlayerDead();}; + +void() player_dieb1 = [ $deathb1, player_dieb2 ] {}; +void() player_dieb2 = [ $deathb2, player_dieb3 ] {}; +void() player_dieb3 = [ $deathb3, player_dieb4 ] {}; +void() player_dieb4 = [ $deathb4, player_dieb5 ] {}; +void() player_dieb5 = [ $deathb5, player_dieb6 ] {}; +void() player_dieb6 = [ $deathb6, player_dieb7 ] {}; +void() player_dieb7 = [ $deathb7, player_dieb8 ] {}; +void() player_dieb8 = [ $deathb8, player_dieb9 ] {}; +void() player_dieb9 = [ $deathb9, player_dieb9 ] {PlayerDead();}; + +void() player_diec1 = [ $deathc1, player_diec2 ] {}; +void() player_diec2 = [ $deathc2, player_diec3 ] {}; +void() player_diec3 = [ $deathc3, player_diec4 ] {}; +void() player_diec4 = [ $deathc4, player_diec5 ] {}; +void() player_diec5 = [ $deathc5, player_diec6 ] {}; +void() player_diec6 = [ $deathc6, player_diec7 ] {}; +void() player_diec7 = [ $deathc7, player_diec8 ] {}; +void() player_diec8 = [ $deathc8, player_diec9 ] {}; +void() player_diec9 = [ $deathc9, player_diec10 ] {}; +void() player_diec10 = [ $deathc10, player_diec11 ] {}; +void() player_diec11 = [ $deathc11, player_diec12 ] {}; +void() player_diec12 = [ $deathc12, player_diec13 ] {}; +void() player_diec13 = [ $deathc13, player_diec14 ] {}; +void() player_diec14 = [ $deathc14, player_diec15 ] {}; +void() player_diec15 = [ $deathc15, player_diec15 ] {PlayerDead();}; + +void() player_died1 = [ $deathd1, player_died2 ] {}; +void() player_died2 = [ $deathd2, player_died3 ] {}; +void() player_died3 = [ $deathd3, player_died4 ] {}; +void() player_died4 = [ $deathd4, player_died5 ] {}; +void() player_died5 = [ $deathd5, player_died6 ] {}; +void() player_died6 = [ $deathd6, player_died7 ] {}; +void() player_died7 = [ $deathd7, player_died8 ] {}; +void() player_died8 = [ $deathd8, player_died9 ] {}; +void() player_died9 = [ $deathd9, player_died9 ] {PlayerDead();}; + +void() player_diee1 = [ $deathe1, player_diee2 ] {}; +void() player_diee2 = [ $deathe2, player_diee3 ] {}; +void() player_diee3 = [ $deathe3, player_diee4 ] {}; +void() player_diee4 = [ $deathe4, player_diee5 ] {}; +void() player_diee5 = [ $deathe5, player_diee6 ] {}; +void() player_diee6 = [ $deathe6, player_diee7 ] {}; +void() player_diee7 = [ $deathe7, player_diee8 ] {}; +void() player_diee8 = [ $deathe8, player_diee9 ] {}; +void() player_diee9 = [ $deathe9, player_diee9 ] {PlayerDead();}; + +void() player_die_ax1 = [ $axdeth1, player_die_ax2 ] {}; +void() player_die_ax2 = [ $axdeth2, player_die_ax3 ] {}; +void() player_die_ax3 = [ $axdeth3, player_die_ax4 ] {}; +void() player_die_ax4 = [ $axdeth4, player_die_ax5 ] {}; +void() player_die_ax5 = [ $axdeth5, player_die_ax6 ] {}; +void() player_die_ax6 = [ $axdeth6, player_die_ax7 ] {}; +void() player_die_ax7 = [ $axdeth7, player_die_ax8 ] {}; +void() player_die_ax8 = [ $axdeth8, player_die_ax9 ] {}; +void() player_die_ax9 = [ $axdeth9, player_die_ax9 ] {PlayerDead();}; diff --git a/quakec/csqctest/src/ss/shalrath.qc b/quakec/csqctest/src/ss/shalrath.qc new file mode 100644 index 000000000..be1700b13 --- /dev/null +++ b/quakec/csqctest/src/ss/shalrath.qc @@ -0,0 +1,240 @@ +/* +============================================================================== + +SHAL-RATH + +============================================================================== +*/ +$cd id1/models/shalrath +$origin 0 0 24 +$base base +$skin skin +$scale 0.7 + +$frame attack1 attack2 attack3 attack4 attack5 attack6 attack7 attack8 +$frame attack9 attack10 attack11 + +$frame pain1 pain2 pain3 pain4 pain5 + +$frame death1 death2 death3 death4 death5 death6 death7 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 walk10 +$frame walk11 walk12 + +void() shalrath_pain; +void() ShalMissile; +void() shal_stand =[ $walk1, shal_stand ] {ai_stand();}; + +void() shal_walk1 =[ $walk2, shal_walk2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "shalrath/idle.wav", 1, ATTN_IDLE); +ai_walk(6);}; +void() shal_walk2 =[ $walk3, shal_walk3 ] {ai_walk(4);}; +void() shal_walk3 =[ $walk4, shal_walk4 ] {ai_walk(0);}; +void() shal_walk4 =[ $walk5, shal_walk5 ] {ai_walk(0);}; +void() shal_walk5 =[ $walk6, shal_walk6 ] {ai_walk(0);}; +void() shal_walk6 =[ $walk7, shal_walk7 ] {ai_walk(0);}; +void() shal_walk7 =[ $walk8, shal_walk8 ] {ai_walk(5);}; +void() shal_walk8 =[ $walk9, shal_walk9 ] {ai_walk(6);}; +void() shal_walk9 =[ $walk10, shal_walk10 ] {ai_walk(5);}; +void() shal_walk10 =[ $walk11, shal_walk11 ] {ai_walk(0);}; +void() shal_walk11 =[ $walk12, shal_walk12 ] {ai_walk(4);}; +void() shal_walk12 =[ $walk1, shal_walk1 ] {ai_walk(5);}; + +void() shal_run1 =[ $walk2, shal_run2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "shalrath/idle.wav", 1, ATTN_IDLE); +ai_run(6);}; +void() shal_run2 =[ $walk3, shal_run3 ] {ai_run(4);}; +void() shal_run3 =[ $walk4, shal_run4 ] {ai_run(0);}; +void() shal_run4 =[ $walk5, shal_run5 ] {ai_run(0);}; +void() shal_run5 =[ $walk6, shal_run6 ] {ai_run(0);}; +void() shal_run6 =[ $walk7, shal_run7 ] {ai_run(0);}; +void() shal_run7 =[ $walk8, shal_run8 ] {ai_run(5);}; +void() shal_run8 =[ $walk9, shal_run9 ] {ai_run(6);}; +void() shal_run9 =[ $walk10, shal_run10 ] {ai_run(5);}; +void() shal_run10 =[ $walk11, shal_run11 ] {ai_run(0);}; +void() shal_run11 =[ $walk12, shal_run12 ] {ai_run(4);}; +void() shal_run12 =[ $walk1, shal_run1 ] {ai_run(5);}; + +void() shal_attack1 =[ $attack1, shal_attack2 ] { +sound (self, CHAN_VOICE, "shalrath/attack.wav", 1, ATTN_NORM); +ai_face(); +}; +void() shal_attack2 =[ $attack2, shal_attack3 ] {ai_face();}; +void() shal_attack3 =[ $attack3, shal_attack4 ] {ai_face();}; +void() shal_attack4 =[ $attack4, shal_attack5 ] {ai_face();}; +void() shal_attack5 =[ $attack5, shal_attack6 ] {ai_face();}; +void() shal_attack6 =[ $attack6, shal_attack7 ] {ai_face();}; +void() shal_attack7 =[ $attack7, shal_attack8 ] {ai_face();}; +void() shal_attack8 =[ $attack8, shal_attack9 ] {ai_face();}; +void() shal_attack9 =[ $attack9, shal_attack10 ] {ShalMissile();}; +void() shal_attack10 =[ $attack10, shal_attack11 ] {ai_face();}; +void() shal_attack11 =[ $attack11, shal_run1 ] {}; + +void() shal_pain1 =[ $pain1, shal_pain2 ] {}; +void() shal_pain2 =[ $pain2, shal_pain3 ] {}; +void() shal_pain3 =[ $pain3, shal_pain4 ] {}; +void() shal_pain4 =[ $pain4, shal_pain5 ] {}; +void() shal_pain5 =[ $pain5, shal_run1 ] {}; + +void() shal_death1 =[ $death1, shal_death2 ] {}; +void() shal_death2 =[ $death2, shal_death3 ] {}; +void() shal_death3 =[ $death3, shal_death4 ] {}; +void() shal_death4 =[ $death4, shal_death5 ] {}; +void() shal_death5 =[ $death5, shal_death6 ] {}; +void() shal_death6 =[ $death6, shal_death7 ] {}; +void() shal_death7 =[ $death7, shal_death7 ] {}; + + +void() shalrath_pain = +{ + if (self.pain_finished > time) + return; + + sound (self, CHAN_VOICE, "shalrath/pain.wav", 1, ATTN_NORM); + shal_pain1(); + self.pain_finished = time + 3; +}; + +void() shalrath_die = +{ +// check for gib + if (self.health < -90) + { + ThrowCSQCGibs(GIB_SHALRATH); + return; + } + + sound (self, CHAN_VOICE, "shalrath/death.wav", 1, ATTN_NORM); + shal_death1(); + self.solid = SOLID_NOT; + // insert death sounds here +}; + +/* +================ +ShalMissile +================ +*/ +void() ShalMissileTouch; +void() ShalHome; +void() ShalMissile = +{ + local entity missile; + local vector dir; + local float dist, flytime; + + dir = normalize((self.enemy.origin + '0 0 10') - self.origin); + dist = vlen (self.enemy.origin - self.origin); + flytime = dist * 0.002; + if (flytime < 0.1) + flytime = 0.1; + + self.effects = self.effects | EF_MUZZLEFLASH; + sound (self, CHAN_WEAPON, "shalrath/attack2.wav", 1, ATTN_NORM); + + missile = spawn (); + missile.owner = self; + + missile.solid = SOLID_BBOX; + missile.movetype = MOVETYPE_FLYMISSILE; + setmodel (missile, "progs/v_spike.mdl"); + + setsize (missile, '0 0 0', '0 0 0'); + + missile.origin = self.origin + '0 0 10'; + missile.velocity = dir * 400; + missile.avelocity = '300 300 300'; + missile.nextthink = flytime + time; + missile.think = ShalHome; + missile.enemy = self.enemy; + missile.touch = ShalMissileTouch; +}; + +void() ShalHome = +{ + local vector dir, vtemp; + vtemp = self.enemy.origin + '0 0 10'; + if (self.enemy.health < 1) + { + remove(self); + return; + } + dir = normalize(vtemp - self.origin); + if (skill == 3) + self.velocity = dir * 350; + else + self.velocity = dir * 250; + self.nextthink = time + 0.2; + self.think = ShalHome; +}; + +void() ShalMissileTouch = +{ + if (other == self.owner) + return; // don't explode on owner + + if (other.classname == "monster_zombie") + T_Damage (other, self, self, 110); + T_RadiusDamage (self, self.owner, 40, world); + +#if 1 + BecomeExplosion(); +#else + sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM); + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_EXPLOSION); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + + self.velocity = '0 0 0'; + self.touch = SUB_Null; + setmodel (self, "progs/s_explod.spr"); + self.solid = SOLID_NOT; + s_explode1 (); +#endif +}; + +//================================================================= + +/*QUAKED monster_shalrath (1 0 0) (-32 -32 -24) (32 32 48) Ambush +*/ +void() monster_shalrath = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model2 ("progs/shalrath.mdl"); + precache_model2 ("progs/h_shal.mdl"); + precache_model2 ("progs/v_spike.mdl"); + + precache_sound2 ("shalrath/attack.wav"); + precache_sound2 ("shalrath/attack2.wav"); + precache_sound2 ("shalrath/death.wav"); + precache_sound2 ("shalrath/idle.wav"); + precache_sound2 ("shalrath/pain.wav"); + precache_sound2 ("shalrath/sight.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/shalrath.mdl"); + setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX); + self.health = 400; + + self.th_stand = shal_stand; + self.th_walk = shal_walk1; + self.th_run = shal_run1; + self.th_die = shalrath_die; + self.th_pain = shalrath_pain; + self.th_missile = shal_attack1; + + self.think = walkmonster_start; + self.nextthink = time + 0.1 + random ()*0.1; + +}; diff --git a/quakec/csqctest/src/ss/shambler.qc b/quakec/csqctest/src/ss/shambler.qc new file mode 100644 index 000000000..adeaa7b4f --- /dev/null +++ b/quakec/csqctest/src/ss/shambler.qc @@ -0,0 +1,363 @@ +/* +============================================================================== + +SHAMBLER + +============================================================================== +*/ + +$cd id1/models/shams +$origin 0 0 24 +$base base +$skin base + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 stand9 +$frame stand10 stand11 stand12 stand13 stand14 stand15 stand16 stand17 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 +$frame walk8 walk9 walk10 walk11 walk12 + +$frame run1 run2 run3 run4 run5 run6 + +$frame smash1 smash2 smash3 smash4 smash5 smash6 smash7 +$frame smash8 smash9 smash10 smash11 smash12 + +$frame swingr1 swingr2 swingr3 swingr4 swingr5 +$frame swingr6 swingr7 swingr8 swingr9 + +$frame swingl1 swingl2 swingl3 swingl4 swingl5 +$frame swingl6 swingl7 swingl8 swingl9 + +$frame magic1 magic2 magic3 magic4 magic5 +$frame magic6 magic7 magic8 magic9 magic10 magic11 magic12 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + +$frame death1 death2 death3 death4 death5 death6 +$frame death7 death8 death9 death10 death11 + +void() sham_stand1 =[ $stand1, sham_stand2 ] {ai_stand();}; +void() sham_stand2 =[ $stand2, sham_stand3 ] {ai_stand();}; +void() sham_stand3 =[ $stand3, sham_stand4 ] {ai_stand();}; +void() sham_stand4 =[ $stand4, sham_stand5 ] {ai_stand();}; +void() sham_stand5 =[ $stand5, sham_stand6 ] {ai_stand();}; +void() sham_stand6 =[ $stand6, sham_stand7 ] {ai_stand();}; +void() sham_stand7 =[ $stand7, sham_stand8 ] {ai_stand();}; +void() sham_stand8 =[ $stand8, sham_stand9 ] {ai_stand();}; +void() sham_stand9 =[ $stand9, sham_stand10] {ai_stand();}; +void() sham_stand10 =[ $stand10, sham_stand11] {ai_stand();}; +void() sham_stand11 =[ $stand11, sham_stand12] {ai_stand();}; +void() sham_stand12 =[ $stand12, sham_stand13] {ai_stand();}; +void() sham_stand13 =[ $stand13, sham_stand14] {ai_stand();}; +void() sham_stand14 =[ $stand14, sham_stand15] {ai_stand();}; +void() sham_stand15 =[ $stand15, sham_stand16] {ai_stand();}; +void() sham_stand16 =[ $stand16, sham_stand17] {ai_stand();}; +void() sham_stand17 =[ $stand17, sham_stand1 ] {ai_stand();}; + +void() sham_walk1 =[ $walk1, sham_walk2 ] {ai_walk(10);}; +void() sham_walk2 =[ $walk2, sham_walk3 ] {ai_walk(9);}; +void() sham_walk3 =[ $walk3, sham_walk4 ] {ai_walk(9);}; +void() sham_walk4 =[ $walk4, sham_walk5 ] {ai_walk(5);}; +void() sham_walk5 =[ $walk5, sham_walk6 ] {ai_walk(6);}; +void() sham_walk6 =[ $walk6, sham_walk7 ] {ai_walk(12);}; +void() sham_walk7 =[ $walk7, sham_walk8 ] {ai_walk(8);}; +void() sham_walk8 =[ $walk8, sham_walk9 ] {ai_walk(3);}; +void() sham_walk9 =[ $walk9, sham_walk10] {ai_walk(13);}; +void() sham_walk10 =[ $walk10, sham_walk11] {ai_walk(9);}; +void() sham_walk11 =[ $walk11, sham_walk12] {ai_walk(7);}; +void() sham_walk12 =[ $walk12, sham_walk1 ] {ai_walk(7); +if (random() > 0.8) + sound (self, CHAN_VOICE, "shambler/sidle.wav", 1, ATTN_IDLE);}; + +void() sham_run1 =[ $run1, sham_run2 ] {ai_run(20);}; +void() sham_run2 =[ $run2, sham_run3 ] {ai_run(24);}; +void() sham_run3 =[ $run3, sham_run4 ] {ai_run(20);}; +void() sham_run4 =[ $run4, sham_run5 ] {ai_run(20);}; +void() sham_run5 =[ $run5, sham_run6 ] {ai_run(24);}; +void() sham_run6 =[ $run6, sham_run1 ] {ai_run(20); +if (random() > 0.8) + sound (self, CHAN_VOICE, "shambler/sidle.wav", 1, ATTN_IDLE); +}; + +void() sham_smash1 =[ $smash1, sham_smash2 ] { +sound (self, CHAN_VOICE, "shambler/melee1.wav", 1, ATTN_NORM); +ai_charge(2);}; +void() sham_smash2 =[ $smash2, sham_smash3 ] {ai_charge(6);}; +void() sham_smash3 =[ $smash3, sham_smash4 ] {ai_charge(6);}; +void() sham_smash4 =[ $smash4, sham_smash5 ] {ai_charge(5);}; +void() sham_smash5 =[ $smash5, sham_smash6 ] {ai_charge(4);}; +void() sham_smash6 =[ $smash6, sham_smash7 ] {ai_charge(1);}; +void() sham_smash7 =[ $smash7, sham_smash8 ] {ai_charge(0);}; +void() sham_smash8 =[ $smash8, sham_smash9 ] {ai_charge(0);}; +void() sham_smash9 =[ $smash9, sham_smash10 ] {ai_charge(0);}; +void() sham_smash10 =[ $smash10, sham_smash11 ] { +local vector delta; +local float ldmg; + + if (!self.enemy) + return; + ai_charge(0); + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 100) + return; + if (!CanDamage (self.enemy, self)) + return; + + ldmg = (random()*3) * 40; + T_Damage (self.enemy, self, self, ldmg); + sound (self, CHAN_VOICE, "shambler/smack.wav", 1, ATTN_NORM); + + SpawnMeatSpray (self.origin + v_forward*16, crandom() * 100 * v_right); + SpawnMeatSpray (self.origin + v_forward*16, crandom() * 100 * v_right); +}; +void() sham_smash11 =[ $smash11, sham_smash12 ] {ai_charge(5);}; +void() sham_smash12 =[ $smash12, sham_run1 ] {ai_charge(4);}; + +void() sham_swingr1; + +void(float side) ShamClaw = +{ +local vector delta; +local float ldmg; + + if (!self.enemy) + return; + ai_charge(10); + + delta = self.enemy.origin - self.origin; + + if (vlen(delta) > 100) + return; + + ldmg = (random()*3) * 20; + T_Damage (self.enemy, self, self, ldmg); + sound (self, CHAN_VOICE, "shambler/smack.wav", 1, ATTN_NORM); + + if (side) + { + makevectors (self.angles); + SpawnMeatSpray (self.origin + v_forward*16, side * v_right); + } +}; + +void() sham_swingl1 =[ $swingl1, sham_swingl2 ] { +sound (self, CHAN_VOICE, "shambler/melee2.wav", 1, ATTN_NORM); +ai_charge(5);}; +void() sham_swingl2 =[ $swingl2, sham_swingl3 ] {ai_charge(3);}; +void() sham_swingl3 =[ $swingl3, sham_swingl4 ] {ai_charge(7);}; +void() sham_swingl4 =[ $swingl4, sham_swingl5 ] {ai_charge(3);}; +void() sham_swingl5 =[ $swingl5, sham_swingl6 ] {ai_charge(7);}; +void() sham_swingl6 =[ $swingl6, sham_swingl7 ] {ai_charge(9);}; +void() sham_swingl7 =[ $swingl7, sham_swingl8 ] {ai_charge(5); ShamClaw(250);}; +void() sham_swingl8 =[ $swingl8, sham_swingl9 ] {ai_charge(4);}; +void() sham_swingl9 =[ $swingl9, sham_run1 ] { +ai_charge(8); +if (random()<0.5) + self.think = sham_swingr1; +}; + +void() sham_swingr1 =[ $swingr1, sham_swingr2 ] { +sound (self, CHAN_VOICE, "shambler/melee1.wav", 1, ATTN_NORM); +ai_charge(1);}; +void() sham_swingr2 =[ $swingr2, sham_swingr3 ] {ai_charge(8);}; +void() sham_swingr3 =[ $swingr3, sham_swingr4 ] {ai_charge(14);}; +void() sham_swingr4 =[ $swingr4, sham_swingr5 ] {ai_charge(7);}; +void() sham_swingr5 =[ $swingr5, sham_swingr6 ] {ai_charge(3);}; +void() sham_swingr6 =[ $swingr6, sham_swingr7 ] {ai_charge(6);}; +void() sham_swingr7 =[ $swingr7, sham_swingr8 ] {ai_charge(6); ShamClaw(-250);}; +void() sham_swingr8 =[ $swingr8, sham_swingr9 ] {ai_charge(3);}; +void() sham_swingr9 =[ $swingr9, sham_run1 ] {ai_charge(1); +ai_charge(10); +if (random()<0.5) + self.think = sham_swingl1; +}; + +void() sham_melee = +{ + local float chance; + + chance = random(); + if (chance > 0.6 || self.health == 600) + sham_smash1 (); + else if (chance > 0.3) + sham_swingr1 (); + else + sham_swingl1 (); +}; + + +//============================================================================ + +void() CastLightning = +{ + local vector org, dir; + + self.effects = self.effects | EF_MUZZLEFLASH; + + ai_face (); + + org = self.origin + '0 0 40'; + + dir = self.enemy.origin + '0 0 16' - org; + dir = normalize (dir); + + traceline (org, self.origin + dir*600, TRUE, self); + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_LIGHTNING1); + WriteEntity (MSG_BROADCAST, self); + WriteCoord (MSG_BROADCAST, org_x); + WriteCoord (MSG_BROADCAST, org_y); + WriteCoord (MSG_BROADCAST, org_z); + WriteCoord (MSG_BROADCAST, trace_endpos_x); + WriteCoord (MSG_BROADCAST, trace_endpos_y); + WriteCoord (MSG_BROADCAST, trace_endpos_z); + + LightningDamage (org, trace_endpos, self, 10); +}; + +void() sham_magic1 =[ $magic1, sham_magic2 ] {ai_face(); + sound (self, CHAN_WEAPON, "shambler/sattck1.wav", 1, ATTN_NORM); +}; +void() sham_magic2 =[ $magic2, sham_magic3 ] {ai_face();}; +void() sham_magic3 =[ $magic3, sham_magic4 ] {ai_face();self.nextthink = self.nextthink + 0.2; +local entity o; + +self.effects = self.effects | EF_MUZZLEFLASH; +ai_face(); +self.owner = spawn(); +o = self.owner; +setmodel (o, "progs/s_light.mdl"); +setorigin (o, self.origin); +o.angles = self.angles; +o.nextthink = time + 0.7; +o.think = SUB_Remove; +}; +void() sham_magic4 =[ $magic4, sham_magic5 ] +{ +self.effects = self.effects | EF_MUZZLEFLASH; +self.owner.frame = 1; +}; +void() sham_magic5 =[ $magic5, sham_magic6 ] +{ +self.effects = self.effects | EF_MUZZLEFLASH; +self.owner.frame = 2; +}; +void() sham_magic6 =[ $magic6, sham_magic9 ] +{ +remove (self.owner); +CastLightning(); +sound (self, CHAN_WEAPON, "shambler/sboom.wav", 1, ATTN_NORM); +}; +void() sham_magic9 =[ $magic9, sham_magic10 ] +{CastLightning();}; +void() sham_magic10 =[ $magic10, sham_magic11 ] +{CastLightning();}; +void() sham_magic11 =[ $magic11, sham_magic12 ] +{ +if (skill == 3) + CastLightning(); +}; +void() sham_magic12 =[ $magic12, sham_run1 ] {}; + + + +void() sham_pain1 =[ $pain1, sham_pain2 ] {}; +void() sham_pain2 =[ $pain2, sham_pain3 ] {}; +void() sham_pain3 =[ $pain3, sham_pain4 ] {}; +void() sham_pain4 =[ $pain4, sham_pain5 ] {}; +void() sham_pain5 =[ $pain5, sham_pain6 ] {}; +void() sham_pain6 =[ $pain6, sham_run1 ] {}; + +void(entity attacker, float damage) sham_pain = +{ + sound (self, CHAN_VOICE, "shambler/shurt2.wav", 1, ATTN_NORM); + + if (self.health <= 0) + return; // allready dying, don't go into pain frame + + if (random()*400 > damage) + return; // didn't flinch + + if (self.pain_finished > time) + return; + self.pain_finished = time + 2; + + sham_pain1 (); +}; + + +//============================================================================ + +void() sham_death1 =[ $death1, sham_death2 ] {}; +void() sham_death2 =[ $death2, sham_death3 ] {}; +void() sham_death3 =[ $death3, sham_death4 ] {self.solid = SOLID_NOT;}; +void() sham_death4 =[ $death4, sham_death5 ] {}; +void() sham_death5 =[ $death5, sham_death6 ] {}; +void() sham_death6 =[ $death6, sham_death7 ] {}; +void() sham_death7 =[ $death7, sham_death8 ] {}; +void() sham_death8 =[ $death8, sham_death9 ] {}; +void() sham_death9 =[ $death9, sham_death10 ] {}; +void() sham_death10 =[ $death10, sham_death11 ] {}; +void() sham_death11 =[ $death11, sham_death11 ] {}; + +void() sham_die = +{ +// check for gib + if (self.health < -60) + { + ThrowCSQCGibs(GIB_SHAMBLER); + return; + } + +// regular death + sound (self, CHAN_VOICE, "shambler/sdeath.wav", 1, ATTN_NORM); + sham_death1 (); +}; + +//============================================================================ + + +/*QUAKED monster_shambler (1 0 0) (-32 -32 -24) (32 32 64) Ambush +*/ +void() monster_shambler = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/shambler.mdl"); + precache_model ("progs/s_light.mdl"); + precache_model ("progs/h_shams.mdl"); + precache_model ("progs/bolt.mdl"); + + precache_sound ("shambler/sattck1.wav"); + precache_sound ("shambler/sboom.wav"); + precache_sound ("shambler/sdeath.wav"); + precache_sound ("shambler/shurt2.wav"); + precache_sound ("shambler/sidle.wav"); + precache_sound ("shambler/ssight.wav"); + precache_sound ("shambler/melee1.wav"); + precache_sound ("shambler/melee2.wav"); + precache_sound ("shambler/smack.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + setmodel (self, "progs/shambler.mdl"); + + setsize (self, VEC_HULL2_MIN, VEC_HULL2_MAX); + self.health = 600; + + self.th_stand = sham_stand1; + self.th_walk = sham_walk1; + self.th_run = sham_run1; + self.th_die = sham_die; + self.th_melee = sham_melee; + self.th_missile = sham_magic1; + self.th_pain = sham_pain; + + walkmonster_start(); +}; diff --git a/quakec/csqctest/src/ss/soldier.qc b/quakec/csqctest/src/ss/soldier.qc new file mode 100644 index 000000000..84148007c --- /dev/null +++ b/quakec/csqctest/src/ss/soldier.qc @@ -0,0 +1,322 @@ +/* +============================================================================== + +SOLDIER / PLAYER + +============================================================================== +*/ + +$cd id1/models/soldier3 +$origin 0 -6 24 +$base base +$skin skin + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 +$frame death9 death10 + +$frame deathc1 deathc2 deathc3 deathc4 deathc5 deathc6 deathc7 deathc8 +$frame deathc9 deathc10 deathc11 + +$frame load1 load2 load3 load4 load5 load6 load7 load8 load9 load10 load11 + +$frame pain1 pain2 pain3 pain4 pain5 pain6 + +$frame painb1 painb2 painb3 painb4 painb5 painb6 painb7 painb8 painb9 painb10 +$frame painb11 painb12 painb13 painb14 + +$frame painc1 painc2 painc3 painc4 painc5 painc6 painc7 painc8 painc9 painc10 +$frame painc11 painc12 painc13 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 + +$frame shoot1 shoot2 shoot3 shoot4 shoot5 shoot6 shoot7 shoot8 shoot9 + +$frame prowl_1 prowl_2 prowl_3 prowl_4 prowl_5 prowl_6 prowl_7 prowl_8 +$frame prowl_9 prowl_10 prowl_11 prowl_12 prowl_13 prowl_14 prowl_15 prowl_16 +$frame prowl_17 prowl_18 prowl_19 prowl_20 prowl_21 prowl_22 prowl_23 prowl_24 + +float(float f) mapsoldieframetoplayer = +{ + switch(f) + { + case $stand1 .. $stand8: + return $stand1; + case $death1 .. $deathc11; + return $deatha1; + case $load1 .. $load11; + return 0; //never used! + case $death1 .. $deathc11; + return $deatha1; + case $pain1 .. $painc13; + return $pain1; + case $prowl_1 .. $prowl_24; + case $run1 .. $run8; + return $rockrun1; + case $shoot1 .. $shoot9; + return $shotatt1; + } + return f; +}; + +float(entity to) SendSoldier = +{ + WriteByte(MSG_ENTITY, CLASS_PLAYER); + WriteByte(MSG_ENTITY, mapsoldieframetoplayer (self.frame)); //for clientside animation selection, in a way compatable with not having csqc. + WriteByte(MSG_ENTITY, self.angles_x*(256/360)); + WriteByte(MSG_ENTITY, self.angles_y*(256/360)); + WriteCoord(MSG_ENTITY, self.origin_x); + WriteCoord(MSG_ENTITY, self.origin_y); + WriteCoord(MSG_ENTITY, self.origin_z); + WriteShort(MSG_ENTITY, self.velocity_x*64); + WriteShort(MSG_ENTITY, self.velocity_y*64); + WriteShort(MSG_ENTITY, self.velocity_z*64); + WriteByte(MSG_ENTITY, 0); + + return TRUE; +}; + +/* +============================================================================== +SOLDIER CODE +============================================================================== +*/ + +void() army_fire; + +void() army_stand1 =[ $stand1, army_stand2 ] {ai_stand();}; +void() army_stand2 =[ $stand2, army_stand3 ] {ai_stand();}; +void() army_stand3 =[ $stand3, army_stand4 ] {ai_stand();}; +void() army_stand4 =[ $stand4, army_stand5 ] {ai_stand();}; +void() army_stand5 =[ $stand5, army_stand6 ] {ai_stand();}; +void() army_stand6 =[ $stand6, army_stand7 ] {ai_stand();}; +void() army_stand7 =[ $stand7, army_stand8 ] {ai_stand();}; +void() army_stand8 =[ $stand8, army_stand1 ] {ai_stand();}; + +void() army_walk1 =[ $prowl_1, army_walk2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "soldier/idle.wav", 1, ATTN_IDLE); +ai_walk(1);}; +void() army_walk2 =[ $prowl_2, army_walk3 ] {ai_walk(1);}; +void() army_walk3 =[ $prowl_3, army_walk4 ] {ai_walk(1);}; +void() army_walk4 =[ $prowl_4, army_walk5 ] {ai_walk(1);}; +void() army_walk5 =[ $prowl_5, army_walk6 ] {ai_walk(2);}; +void() army_walk6 =[ $prowl_6, army_walk7 ] {ai_walk(3);}; +void() army_walk7 =[ $prowl_7, army_walk8 ] {ai_walk(4);}; +void() army_walk8 =[ $prowl_8, army_walk9 ] {ai_walk(4);}; +void() army_walk9 =[ $prowl_9, army_walk10 ] {ai_walk(2);}; +void() army_walk10 =[ $prowl_10, army_walk11 ] {ai_walk(2);}; +void() army_walk11 =[ $prowl_11, army_walk12 ] {ai_walk(2);}; +void() army_walk12 =[ $prowl_12, army_walk13 ] {ai_walk(1);}; +void() army_walk13 =[ $prowl_13, army_walk14 ] {ai_walk(0);}; +void() army_walk14 =[ $prowl_14, army_walk15 ] {ai_walk(1);}; +void() army_walk15 =[ $prowl_15, army_walk16 ] {ai_walk(1);}; +void() army_walk16 =[ $prowl_16, army_walk17 ] {ai_walk(1);}; +void() army_walk17 =[ $prowl_17, army_walk18 ] {ai_walk(3);}; +void() army_walk18 =[ $prowl_18, army_walk19 ] {ai_walk(3);}; +void() army_walk19 =[ $prowl_19, army_walk20 ] {ai_walk(3);}; +void() army_walk20 =[ $prowl_20, army_walk21 ] {ai_walk(3);}; +void() army_walk21 =[ $prowl_21, army_walk22 ] {ai_walk(2);}; +void() army_walk22 =[ $prowl_22, army_walk23 ] {ai_walk(1);}; +void() army_walk23 =[ $prowl_23, army_walk24 ] {ai_walk(1);}; +void() army_walk24 =[ $prowl_24, army_walk1 ] {ai_walk(1);}; + +void() army_run1 =[ $run1, army_run2 ] { +if (random() < 0.2) + sound (self, CHAN_VOICE, "soldier/idle.wav", 1, ATTN_IDLE); +ai_run(11);}; +void() army_run2 =[ $run2, army_run3 ] {ai_run(15);}; +void() army_run3 =[ $run3, army_run4 ] {ai_run(10);}; +void() army_run4 =[ $run4, army_run5 ] {ai_run(10);}; +void() army_run5 =[ $run5, army_run6 ] {ai_run(8);}; +void() army_run6 =[ $run6, army_run7 ] {ai_run(15);}; +void() army_run7 =[ $run7, army_run8 ] {ai_run(10);}; +void() army_run8 =[ $run8, army_run1 ] {ai_run(8);}; + +void() army_atk1 =[ $shoot1, army_atk2 ] {ai_face();}; +void() army_atk2 =[ $shoot2, army_atk3 ] {ai_face();}; +void() army_atk3 =[ $shoot3, army_atk4 ] {ai_face();}; +void() army_atk4 =[ $shoot4, army_atk5 ] {ai_face();}; +void() army_atk5 =[ $shoot5, army_atk6 ] {ai_face();army_fire(); +self.effects = self.effects | EF_MUZZLEFLASH;}; +void() army_atk6 =[ $shoot6, army_atk7 ] {ai_face();}; +void() army_atk7 =[ $shoot7, army_atk8 ] {ai_face();SUB_CheckRefire (army_atk1);}; +void() army_atk8 =[ $shoot8, army_atk9 ] {ai_face();}; +void() army_atk9 =[ $shoot9, army_run1 ] {ai_face();}; + + +void() army_pain1 =[ $pain1, army_pain2 ] {}; +void() army_pain2 =[ $pain2, army_pain3 ] {}; +void() army_pain3 =[ $pain3, army_pain4 ] {}; +void() army_pain4 =[ $pain4, army_pain5 ] {}; +void() army_pain5 =[ $pain5, army_pain6 ] {}; +void() army_pain6 =[ $pain6, army_run1 ] {ai_pain(1);}; + +void() army_painb1 =[ $painb1, army_painb2 ] {}; +void() army_painb2 =[ $painb2, army_painb3 ] {ai_painforward(13);}; +void() army_painb3 =[ $painb3, army_painb4 ] {ai_painforward(9);}; +void() army_painb4 =[ $painb4, army_painb5 ] {}; +void() army_painb5 =[ $painb5, army_painb6 ] {}; +void() army_painb6 =[ $painb6, army_painb7 ] {}; +void() army_painb7 =[ $painb7, army_painb8 ] {}; +void() army_painb8 =[ $painb8, army_painb9 ] {}; +void() army_painb9 =[ $painb9, army_painb10] {}; +void() army_painb10=[ $painb10, army_painb11] {}; +void() army_painb11=[ $painb11, army_painb12] {}; +void() army_painb12=[ $painb12, army_painb13] {ai_pain(2);}; +void() army_painb13=[ $painb13, army_painb14] {}; +void() army_painb14=[ $painb14, army_run1 ] {}; + +void() army_painc1 =[ $painc1, army_painc2 ] {}; +void() army_painc2 =[ $painc2, army_painc3 ] {ai_pain(1);}; +void() army_painc3 =[ $painc3, army_painc4 ] {}; +void() army_painc4 =[ $painc4, army_painc5 ] {}; +void() army_painc5 =[ $painc5, army_painc6 ] {ai_painforward(1);}; +void() army_painc6 =[ $painc6, army_painc7 ] {ai_painforward(1);}; +void() army_painc7 =[ $painc7, army_painc8 ] {}; +void() army_painc8 =[ $painc8, army_painc9 ] {ai_pain(1);}; +void() army_painc9 =[ $painc9, army_painc10] {ai_painforward(4);}; +void() army_painc10=[ $painc10, army_painc11] {ai_painforward(3);}; +void() army_painc11=[ $painc11, army_painc12] {ai_painforward(6);}; +void() army_painc12=[ $painc12, army_painc13] {ai_painforward(8);}; +void() army_painc13=[ $painc13, army_run1] {}; + +void(entity attacker, float damage) army_pain = +{ + local float r; + + if (self.pain_finished > time) + return; + + r = random(); + + if (r < 0.2) + { + self.pain_finished = time + 0.6; + army_pain1 (); + sound (self, CHAN_VOICE, "soldier/pain1.wav", 1, ATTN_NORM); + } + else if (r < 0.6) + { + self.pain_finished = time + 1.1; + army_painb1 (); + sound (self, CHAN_VOICE, "soldier/pain2.wav", 1, ATTN_NORM); + } + else + { + self.pain_finished = time + 1.1; + army_painc1 (); + sound (self, CHAN_VOICE, "soldier/pain2.wav", 1, ATTN_NORM); + } +}; + + +void() army_fire = +{ + local vector dir; + local entity en; + + ai_face(); + + sound (self, CHAN_WEAPON, "soldier/sattck1.wav", 1, ATTN_NORM); + +// fire somewhat behind the player, so a dodging player is harder to hit + en = self.enemy; + + dir = en.origin - en.velocity*0.2; + dir = normalize (dir - self.origin); + + FireBullets (4, dir, '0.1 0.1 0'); +}; + + + +void() army_die1 =[ $death1, army_die2 ] {}; +void() army_die2 =[ $death2, army_die3 ] {}; +void() army_die3 =[ $death3, army_die4 ] +{self.solid = SOLID_NOT;self.ammo_shells = 5;DropBackpack();}; +void() army_die4 =[ $death4, army_die5 ] {}; +void() army_die5 =[ $death5, army_die6 ] {}; +void() army_die6 =[ $death6, army_die7 ] {}; +void() army_die7 =[ $death7, army_die8 ] {}; +void() army_die8 =[ $death8, army_die9 ] {}; +void() army_die9 =[ $death9, army_die10 ] {}; +void() army_die10 =[ $death10, army_die10 ] {}; + +void() army_cdie1 =[ $deathc1, army_cdie2 ] {}; +void() army_cdie2 =[ $deathc2, army_cdie3 ] {ai_back(5);}; +void() army_cdie3 =[ $deathc3, army_cdie4 ] +{self.solid = SOLID_NOT;self.ammo_shells = 5;DropBackpack();ai_back(4);}; +void() army_cdie4 =[ $deathc4, army_cdie5 ] {ai_back(13);}; +void() army_cdie5 =[ $deathc5, army_cdie6 ] {ai_back(3);}; +void() army_cdie6 =[ $deathc6, army_cdie7 ] {ai_back(4);}; +void() army_cdie7 =[ $deathc7, army_cdie8 ] {}; +void() army_cdie8 =[ $deathc8, army_cdie9 ] {}; +void() army_cdie9 =[ $deathc9, army_cdie10 ] {}; +void() army_cdie10 =[ $deathc10, army_cdie11 ] {}; +void() army_cdie11 =[ $deathc11, army_cdie11 ] {}; + + +void() army_die = +{ +// check for gib + if (self.health < -35) + { + ThrowCSQCGibs(GIB_SOLDIER); + return; + } + +// regular death + sound (self, CHAN_VOICE, "soldier/death1.wav", 1, ATTN_NORM); + if (random() < 0.5) + army_die1 (); + else + army_cdie1 (); +}; + + +/*QUAKED monster_army (1 0 0) (-16 -16 -24) (16 16 40) Ambush +*/ +void() monster_army = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/soldier.mdl"); + precache_model ("progs/h_guard.mdl"); + precache_model ("progs/gib1.mdl"); + precache_model ("progs/gib2.mdl"); + precache_model ("progs/gib3.mdl"); + + precache_sound ("soldier/death1.wav"); + precache_sound ("soldier/idle.wav"); + precache_sound ("soldier/pain1.wav"); + precache_sound ("soldier/pain2.wav"); + precache_sound ("soldier/sattck1.wav"); + precache_sound ("soldier/sight1.wav"); + + precache_sound ("player/udeath.wav"); // gib death + + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/soldier.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 30; + + self.th_stand = army_stand1; + self.th_walk = army_walk1; + self.th_run = army_run1; + self.th_missile = army_atk1; + self.th_pain = army_pain; + self.th_die = army_die; + + self.SendEntity = SendSoldier; + + walkmonster_start (); +}; diff --git a/quakec/csqctest/src/ss/subs.qc b/quakec/csqctest/src/ss/subs.qc new file mode 100644 index 000000000..1950ba829 --- /dev/null +++ b/quakec/csqctest/src/ss/subs.qc @@ -0,0 +1,316 @@ + + +void() SUB_Null = {}; + +void() SUB_Remove = {remove(self);}; + + +/* +QuakeEd only writes a single float for angles (bad idea), so up and down are +just constant angles. +*/ +void() SetMovedir = +{ + if (self.angles == '0 -1 0') + self.movedir = '0 0 1'; + else if (self.angles == '0 -2 0') + self.movedir = '0 0 -1'; + else + { + makevectors (self.angles); + self.movedir = v_forward; + } + + self.angles = '0 0 0'; +}; + +/* +================ +InitTrigger +================ +*/ +void() InitTrigger = +{ +// trigger angles are used for one-way touches. An angle of 0 is assumed +// to mean no restrictions, so use a yaw of 360 instead. + if (self.angles != '0 0 0') + SetMovedir (); + self.solid = SOLID_TRIGGER; + setmodel (self, self.model); // set size and link into world + self.movetype = MOVETYPE_NONE; + self.modelindex = 0; + self.model = ""; +}; + +/* +============= +SUB_CalcMove + +calculate self.velocity and self.nextthink to reach dest from +self.origin traveling at speed +=============== +*/ +void(entity ent, vector tdest, float tspeed, void() func) SUB_CalcMoveEnt = +{ +local entity stemp; + stemp = self; + self = ent; + + SUB_CalcMove (tdest, tspeed, func); + self = stemp; +}; + +void(vector tdest, float tspeed, void() func) SUB_CalcMove = +{ +local vector vdestdelta; +local float len, traveltime; + + if (!tspeed) + objerror("No speed is defined!"); + + self.think1 = func; + self.finaldest = tdest; + self.think = SUB_CalcMoveDone; + + if (tdest == self.origin) + { + self.velocity = '0 0 0'; + self.nextthink = self.ltime + 0.1; + return; + } + +// set destdelta to the vector needed to move + vdestdelta = tdest - self.origin; + +// calculate length of vector + len = vlen (vdestdelta); + +// divide by speed to get time to reach dest + traveltime = len / tspeed; + + if (traveltime < 0.1) + { + self.velocity = '0 0 0'; + self.nextthink = self.ltime + 0.1; + return; + } + +// set nextthink to trigger a think when dest is reached + self.nextthink = self.ltime + traveltime; + +// scale the destdelta vector by the time spent traveling to get velocity + self.velocity = vdestdelta * (1/traveltime); // qcc won't take vec/float +}; + +/* +============ +After moving, set origin to exact final destination +============ +*/ +void() SUB_CalcMoveDone = +{ + setorigin(self, self.finaldest); + self.velocity = '0 0 0'; + self.nextthink = -1; + if (self.think1) + self.think1(); +}; + + +/* +============= +SUB_CalcAngleMove + +calculate self.avelocity and self.nextthink to reach destangle from +self.angles rotating + +The calling function should make sure self.think is valid +=============== +*/ +void(entity ent, vector destangle, float tspeed, void() func) SUB_CalcAngleMoveEnt = +{ +local entity stemp; + stemp = self; + self = ent; + SUB_CalcAngleMove (destangle, tspeed, func); + self = stemp; +}; + +void(vector destangle, float tspeed, void() func) SUB_CalcAngleMove = +{ +local vector destdelta; +local float len, traveltime; + + if (!tspeed) + objerror("No speed is defined!"); + +// set destdelta to the vector needed to move + destdelta = destangle - self.angles; + +// calculate length of vector + len = vlen (destdelta); + +// divide by speed to get time to reach dest + traveltime = len / tspeed; + +// set nextthink to trigger a think when dest is reached + self.nextthink = self.ltime + traveltime; + +// scale the destdelta vector by the time spent traveling to get velocity + self.avelocity = destdelta * (1 / traveltime); + + self.think1 = func; + self.finalangle = destangle; + self.think = SUB_CalcAngleMoveDone; +}; + +/* +============ +After rotating, set angle to exact final angle +============ +*/ +void() SUB_CalcAngleMoveDone = +{ + self.angles = self.finalangle; + self.avelocity = '0 0 0'; + self.nextthink = -1; + if (self.think1) + self.think1(); +}; + + +//============================================================================= + +void() DelayThink = +{ + activator = self.enemy; + SUB_UseTargets (); + remove(self); +}; + +/* +============================== +SUB_UseTargets + +the global "activator" should be set to the entity that initiated the firing. + +If self.delay is set, a DelayedUse entity will be created that will actually +do the SUB_UseTargets after that many seconds have passed. + +Centerprints any self.message to the activator. + +Removes all entities with a targetname that match self.killtarget, +and removes them, so some events can remove other triggers. + +Search for (string)targetname in all entities that +match (string)self.target and call their .use function + +============================== +*/ +void() SUB_UseTargets = +{ + local entity t, stemp, otemp, act; + +// +// check for a delay +// + if (self.delay) + { + // create a temp object to fire at a later time + t = spawn(); + t.classname = "DelayedUse"; + t.nextthink = time + self.delay; + t.think = DelayThink; + t.enemy = activator; + t.message = self.message; + t.killtarget = self.killtarget; + t.target = self.target; + return; + } + + +// +// print the message +// + if (activator.classname == "player" && self.message != "") + { + centerprint (activator, self.message); + if (!self.noise) + sound (activator, CHAN_VOICE, "misc/talk.wav", 1, ATTN_NORM); + } + +// +// kill the killtagets +// + if (self.killtarget != "") + { + t = world; + do + { + t = find (t, targetname, self.killtarget); + if (!t) + return; + remove (t); + } while ( 1 ); + } + +// +// fire targets +// + if (self.target != "") + { + act = activator; + t = world; + do + { + t = find (t, targetname, self.target); + if (!t) + { + return; + } + stemp = self; + otemp = other; + self = t; + other = stemp; + if (self.use != SUB_Null) + { + if (self.use) + self.use (); + } + self = stemp; + other = otemp; + activator = act; + } while ( 1 ); + } + + +}; + + +/* + +in nightmare mode, all attack_finished times become 0 +some monsters refire twice automatically + +*/ + +void(float normal) SUB_AttackFinished = +{ + self.cnt = 0; // refire count for nightmare + if (skill != 3) + self.attack_finished = time + normal; +}; + +float (entity targ) visible; + +void (void() thinkst) SUB_CheckRefire = +{ + if (skill != 3) + return; + if (self.cnt == 1) + return; + if (!visible (self.enemy)) + return; + self.cnt = 1; + self.think = thinkst; +}; diff --git a/quakec/csqctest/src/ss/tarbaby.qc b/quakec/csqctest/src/ss/tarbaby.qc new file mode 100644 index 000000000..8742afcbb --- /dev/null +++ b/quakec/csqctest/src/ss/tarbaby.qc @@ -0,0 +1,222 @@ +/* +============================================================================== + +BLOB + +============================================================================== +*/ + +$cd id1/models/tarbaby +$origin 0 0 24 +$base base + +$skin skin + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 walk10 +$frame walk11 walk12 walk13 walk14 walk15 walk16 walk17 walk18 walk19 +$frame walk20 walk21 walk22 walk23 walk24 walk25 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 run9 run10 run11 run12 run13 +$frame run14 run15 run16 run17 run18 run19 run20 run21 run22 run23 +$frame run24 run25 + +$frame jump1 jump2 jump3 jump4 jump5 jump6 + +$frame fly1 fly2 fly3 fly4 + +$frame exp + +void() tbaby_stand1 =[ $walk1, tbaby_stand1 ] {ai_stand();}; + +void() tbaby_hang1 =[ $walk1, tbaby_hang1 ] {ai_stand();}; + +void() tbaby_walk1 =[ $walk1, tbaby_walk2 ] {ai_turn();}; +void() tbaby_walk2 =[ $walk2, tbaby_walk3 ] {ai_turn();}; +void() tbaby_walk3 =[ $walk3, tbaby_walk4 ] {ai_turn();}; +void() tbaby_walk4 =[ $walk4, tbaby_walk5 ] {ai_turn();}; +void() tbaby_walk5 =[ $walk5, tbaby_walk6 ] {ai_turn();}; +void() tbaby_walk6 =[ $walk6, tbaby_walk7 ] {ai_turn();}; +void() tbaby_walk7 =[ $walk7, tbaby_walk8 ] {ai_turn();}; +void() tbaby_walk8 =[ $walk8, tbaby_walk9 ] {ai_turn();}; +void() tbaby_walk9 =[ $walk9, tbaby_walk10 ] {ai_turn();}; +void() tbaby_walk10 =[ $walk10, tbaby_walk11 ] {ai_turn();}; +void() tbaby_walk11 =[ $walk11, tbaby_walk12 ] {ai_walk(2);}; +void() tbaby_walk12 =[ $walk12, tbaby_walk13 ] {ai_walk(2);}; +void() tbaby_walk13 =[ $walk13, tbaby_walk14 ] {ai_walk(2);}; +void() tbaby_walk14 =[ $walk14, tbaby_walk15 ] {ai_walk(2);}; +void() tbaby_walk15 =[ $walk15, tbaby_walk16 ] {ai_walk(2);}; +void() tbaby_walk16 =[ $walk16, tbaby_walk17 ] {ai_walk(2);}; +void() tbaby_walk17 =[ $walk17, tbaby_walk18 ] {ai_walk(2);}; +void() tbaby_walk18 =[ $walk18, tbaby_walk19 ] {ai_walk(2);}; +void() tbaby_walk19 =[ $walk19, tbaby_walk20 ] {ai_walk(2);}; +void() tbaby_walk20 =[ $walk20, tbaby_walk21 ] {ai_walk(2);}; +void() tbaby_walk21 =[ $walk21, tbaby_walk22 ] {ai_walk(2);}; +void() tbaby_walk22 =[ $walk22, tbaby_walk23 ] {ai_walk(2);}; +void() tbaby_walk23 =[ $walk23, tbaby_walk24 ] {ai_walk(2);}; +void() tbaby_walk24 =[ $walk24, tbaby_walk25 ] {ai_walk(2);}; +void() tbaby_walk25 =[ $walk25, tbaby_walk1 ] {ai_walk(2);}; + +void() tbaby_run1 =[ $run1, tbaby_run2 ] {ai_face();}; +void() tbaby_run2 =[ $run2, tbaby_run3 ] {ai_face();}; +void() tbaby_run3 =[ $run3, tbaby_run4 ] {ai_face();}; +void() tbaby_run4 =[ $run4, tbaby_run5 ] {ai_face();}; +void() tbaby_run5 =[ $run5, tbaby_run6 ] {ai_face();}; +void() tbaby_run6 =[ $run6, tbaby_run7 ] {ai_face();}; +void() tbaby_run7 =[ $run7, tbaby_run8 ] {ai_face();}; +void() tbaby_run8 =[ $run8, tbaby_run9 ] {ai_face();}; +void() tbaby_run9 =[ $run9, tbaby_run10 ] {ai_face();}; +void() tbaby_run10 =[ $run10, tbaby_run11 ] {ai_face();}; +void() tbaby_run11 =[ $run11, tbaby_run12 ] {ai_run(2);}; +void() tbaby_run12 =[ $run12, tbaby_run13 ] {ai_run(2);}; +void() tbaby_run13 =[ $run13, tbaby_run14 ] {ai_run(2);}; +void() tbaby_run14 =[ $run14, tbaby_run15 ] {ai_run(2);}; +void() tbaby_run15 =[ $run15, tbaby_run16 ] {ai_run(2);}; +void() tbaby_run16 =[ $run16, tbaby_run17 ] {ai_run(2);}; +void() tbaby_run17 =[ $run17, tbaby_run18 ] {ai_run(2);}; +void() tbaby_run18 =[ $run18, tbaby_run19 ] {ai_run(2);}; +void() tbaby_run19 =[ $run19, tbaby_run20 ] {ai_run(2);}; +void() tbaby_run20 =[ $run20, tbaby_run21 ] {ai_run(2);}; +void() tbaby_run21 =[ $run21, tbaby_run22 ] {ai_run(2);}; +void() tbaby_run22 =[ $run22, tbaby_run23 ] {ai_run(2);}; +void() tbaby_run23 =[ $run23, tbaby_run24 ] {ai_run(2);}; +void() tbaby_run24 =[ $run24, tbaby_run25 ] {ai_run(2);}; +void() tbaby_run25 =[ $run25, tbaby_run1 ] {ai_run(2);}; + + +//============================================================================ + + +void() tbaby_jump1; + +void() Tar_JumpTouch = +{ + local float ldmg; + + if (other.takedamage && other.classname != self.classname) + { + if ( vlen(self.velocity) > 400 ) + { + ldmg = 10 + 10*random(); + T_Damage (other, self, self, ldmg); + sound (self, CHAN_WEAPON, "blob/hit1.wav", 1, ATTN_NORM); + } + } + else + sound (self, CHAN_WEAPON, "blob/land1.wav", 1, ATTN_NORM); + + + if (!checkbottom(self)) + { + if (self.flags & FL_ONGROUND) + { // jump randomly to not get hung up +//dprint ("popjump\n"); + self.touch = SUB_Null; + self.think = tbaby_run1; + self.movetype = MOVETYPE_STEP; + self.nextthink = time + 0.1; + +// self.velocity_x = (random() - 0.5) * 600; +// self.velocity_y = (random() - 0.5) * 600; +// self.velocity_z = 200; +// self.flags = self.flags - FL_ONGROUND; + } + return; // not on ground yet + } + + self.touch = SUB_Null; + self.think = tbaby_jump1; + self.nextthink = time + 0.1; +}; + +void() tbaby_jump5; + +void() tbaby_fly1 =[ $fly1, tbaby_fly2 ] {}; +void() tbaby_fly2 =[ $fly2, tbaby_fly3 ] {}; +void() tbaby_fly3 =[ $fly3, tbaby_fly4 ] {}; +void() tbaby_fly4 =[ $fly4, tbaby_fly1 ] { +self.cnt = self.cnt + 1; +if (self.cnt == 4) +{ +//dprint ("spawn hop\n"); +tbaby_jump5 (); +} +}; + +void() tbaby_jump1 =[ $jump1, tbaby_jump2 ] {ai_face();}; +void() tbaby_jump2 =[ $jump2, tbaby_jump3 ] {ai_face();}; +void() tbaby_jump3 =[ $jump3, tbaby_jump4 ] {ai_face();}; +void() tbaby_jump4 =[ $jump4, tbaby_jump5 ] {ai_face();}; +void() tbaby_jump5 =[ $jump5, tbaby_jump6 ] +{ + self.movetype = MOVETYPE_BOUNCE; + self.touch = Tar_JumpTouch; + makevectors (self.angles); + self.origin_z = self.origin_z + 1; + self.velocity = v_forward * 600 + '0 0 200'; + self.velocity_z = self.velocity_z + random()*150; + if (self.flags & FL_ONGROUND) + self.flags = self.flags - FL_ONGROUND; + self.cnt = 0; +}; +void() tbaby_jump6 =[ $jump6,tbaby_fly1 ] {}; + + + +//============================================================================= + +void() tbaby_die1 =[ $exp, tbaby_die2 ] { +self.takedamage = DAMAGE_NO; +}; +void() tbaby_die2 =[ $exp, tbaby_run1 ] +{ + T_RadiusDamage (self, self, 120, world); + + sound (self, CHAN_VOICE, "blob/death1.wav", 1, ATTN_NORM); + self.origin = self.origin - 8*normalize(self.velocity); + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_TAREXPLOSION); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + + BecomeExplosion (); +}; + +//============================================================================= + + +/*QUAKED monster_tarbaby (1 0 0) (-16 -16 -24) (16 16 24) Ambush +*/ +void() monster_tarbaby = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model2 ("progs/tarbaby.mdl"); + + precache_sound2 ("blob/death1.wav"); + precache_sound2 ("blob/hit1.wav"); + precache_sound2 ("blob/land1.wav"); + precache_sound2 ("blob/sight1.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/tarbaby.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 80; + + self.th_stand = tbaby_stand1; + self.th_walk = tbaby_walk1; + self.th_run = tbaby_run1; + self.th_missile = tbaby_jump1; + self.th_melee = tbaby_jump1; + self.th_die = tbaby_die1; + + walkmonster_start (); +}; + diff --git a/quakec/csqctest/src/ss/triggers.qc b/quakec/csqctest/src/ss/triggers.qc new file mode 100644 index 000000000..1c49c9a4f --- /dev/null +++ b/quakec/csqctest/src/ss/triggers.qc @@ -0,0 +1,688 @@ + +entity s; + + +void() trigger_reactivate = +{ + self.solid = SOLID_TRIGGER; +}; + +//============================================================================= + +float SPAWNFLAG_NOMESSAGE = 1; +float SPAWNFLAG_NOTOUCH = 1; + +// the wait time has passed, so set back up for another activation +void() multi_wait = +{ + if (self.max_health) + { + self.health = self.max_health; + self.takedamage = DAMAGE_YES; + self.solid = SOLID_BBOX; + } +}; + + +// the trigger was just touched/killed/used +// self.enemy should be set to the activator so it can be held through a delay +// so wait for the delay time before firing +void() multi_trigger = +{ + if (self.nextthink > time) + { + return; // allready been triggered + } + + if (self.classname == "trigger_secret") + { + if (self.enemy.classname != "player") + return; + found_secrets = found_secrets + 1; + WriteByte (MSG_ALL, SVC_FOUNDSECRET); + } + + if (self.noise!="") + sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM); + +// don't trigger again until reset + self.takedamage = DAMAGE_NO; + + activator = self.enemy; + + SUB_UseTargets(); + + if (self.wait > 0) + { + self.think = multi_wait; + self.nextthink = time + self.wait; + } + else + { // we can't just remove (self) here, because this is a touch function + // called wheil C code is looping through area links... + self.touch = SUB_Null; + self.nextthink = time + 0.1; + self.think = SUB_Remove; + } +}; + +void() multi_killed = +{ + self.enemy = damage_attacker; + multi_trigger(); +}; + +void() multi_use = +{ + self.enemy = activator; + multi_trigger(); +}; + +void() multi_touch = +{ + if (other.classname != "player") + return; + +// if the trigger has an angles field, check player's facing direction + if (self.movedir != '0 0 0') + { + makevectors (other.angles); + if (v_forward * self.movedir < 0) + return; // not facing the right way + } + + self.enemy = other; + multi_trigger (); +}; + +/*QUAKED trigger_multiple (.5 .5 .5) ? notouch +Variable sized repeatable trigger. Must be targeted at one or more entities. If "health" is set, the trigger must be killed to activate each time. +If "delay" is set, the trigger waits some time after activating before firing. +"wait" : Seconds between triggerings. (.2 default) +If notouch is set, the trigger is only fired by other entities, not by touching. +NOTOUCH has been obsoleted by trigger_relay! +sounds +1) secret +2) beep beep +3) large switch +4) +set "message" to text string +*/ +void() trigger_multiple = +{ + if (self.sounds == 1) + { + precache_sound ("misc/secret.wav"); + self.noise = "misc/secret.wav"; + } + else if (self.sounds == 2) + { + precache_sound ("misc/talk.wav"); + self.noise = "misc/talk.wav"; + } + else if (self.sounds == 3) + { + precache_sound ("misc/trigger1.wav"); + self.noise = "misc/trigger1.wav"; + } + + if (!self.wait) + self.wait = 0.2; + self.use = multi_use; + + InitTrigger (); + + if (self.health) + { + if (self.spawnflags & SPAWNFLAG_NOTOUCH) + objerror ("health and notouch don't make sense\n"); + self.max_health = self.health; + self.th_die = multi_killed; + self.takedamage = DAMAGE_YES; + self.solid = SOLID_BBOX; + setorigin (self, self.origin); // make sure it links into the world + } + else + { + if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) ) + { + self.touch = multi_touch; + } + } +}; + + +/*QUAKED trigger_once (.5 .5 .5) ? notouch +Variable sized trigger. Triggers once, then removes itself. You must set the key "target" to the name of another object in the level that has a matching +"targetname". If "health" is set, the trigger must be killed to activate. +If notouch is set, the trigger is only fired by other entities, not by touching. +if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired. +if "angle" is set, the trigger will only fire when someone is facing the direction of the angle. Use "360" for an angle of 0. +sounds +1) secret +2) beep beep +3) large switch +4) +set "message" to text string +*/ +void() trigger_once = +{ + self.wait = -1; + trigger_multiple(); +}; + +//============================================================================= + +/*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8) +This fixed size trigger cannot be touched, it can only be fired by other events. It can contain killtargets, targets, delays, and messages. +*/ +void() trigger_relay = +{ + self.use = SUB_UseTargets; +}; + + +//============================================================================= + +/*QUAKED trigger_secret (.5 .5 .5) ? +secret counter trigger +sounds +1) secret +2) beep beep +3) +4) +set "message" to text string +*/ +void() trigger_secret = +{ + total_secrets = total_secrets + 1; + self.wait = -1; + if (!self.message) + self.message = "You found a secret area!"; + if (!self.sounds) + self.sounds = 1; + + if (self.sounds == 1) + { + precache_sound ("misc/secret.wav"); + self.noise = "misc/secret.wav"; + } + else if (self.sounds == 2) + { + precache_sound ("misc/talk.wav"); + self.noise = "misc/talk.wav"; + } + + trigger_multiple (); +}; + +//============================================================================= + + +void() counter_use = +{ + self.count = self.count - 1; + if (self.count < 0) + return; + + if (self.count != 0) + { + if (activator.classname == "player" + && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0) + { + if (self.count >= 4) + centerprint (activator, "There are more to go..."); + else if (self.count == 3) + centerprint (activator, "Only 3 more to go..."); + else if (self.count == 2) + centerprint (activator, "Only 2 more to go..."); + else + centerprint (activator, "Only 1 more to go..."); + } + return; + } + + if (activator.classname == "player" + && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0) + centerprint(activator, "Sequence completed!"); + self.enemy = activator; + multi_trigger (); +}; + +/*QUAKED trigger_counter (.5 .5 .5) ? nomessage +Acts as an intermediary for an action that takes multiple inputs. + +If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished. + +After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself. +*/ +void() trigger_counter = +{ + self.wait = -1; + if (!self.count) + self.count = 2; + + self.use = counter_use; +}; + + +/* +============================================================================== + +TELEPORT TRIGGERS + +============================================================================== +*/ + +float PLAYER_ONLY = 1; +float SILENT = 2; + +void() play_teleport = +{ + local float v; + local string tmpstr; + + v = random() * 5; + if (v < 1) + tmpstr = "misc/r_tele1.wav"; + else if (v < 2) + tmpstr = "misc/r_tele2.wav"; + else if (v < 3) + tmpstr = "misc/r_tele3.wav"; + else if (v < 4) + tmpstr = "misc/r_tele4.wav"; + else + tmpstr = "misc/r_tele5.wav"; + + sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM); + remove (self); +}; + +void(vector org) spawn_tfog = +{ + s = spawn (); + s.origin = org; + s.nextthink = time + 0.2; + s.think = play_teleport; + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_TELEPORT); + WriteCoord (MSG_BROADCAST, org_x); + WriteCoord (MSG_BROADCAST, org_y); + WriteCoord (MSG_BROADCAST, org_z); +}; + + +void() tdeath_touch = +{ + if (other == self.owner) + return; + +// frag anyone who teleports in on top of an invincible player + if (other.classname == "player") + { + if (other.invincible_finished > time) + self.classname = "teledeath2"; + if (self.owner.classname != "player") + { // other monsters explode themselves + T_Damage (self.owner, self, self, 50000); + return; + } + + } + + if (other.health) + { + T_Damage (other, self, self, 50000); + } +}; + + +void(vector org, entity death_owner) spawn_tdeath = +{ +local entity death; + + death = spawn(); + death.classname = "teledeath"; + death.movetype = MOVETYPE_NONE; + death.solid = SOLID_TRIGGER; + death.angles = '0 0 0'; + setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1'); + setorigin (death, org); + death.touch = tdeath_touch; + death.nextthink = time + 0.2; + death.think = SUB_Remove; + death.owner = death_owner; + + force_retouch = 2; // make sure even still objects get hit +}; + +void() teleport_touch = +{ +local entity t; +local vector org; + + if (self.targetname!="") + { + if (self.nextthink < time) + { + return; // not fired yet + } + } + + if (self.spawnflags & PLAYER_ONLY) + { + if (other.classname != "player") + return; + } + +// only teleport living creatures + if (other.health <= 0 || other.solid != SOLID_SLIDEBOX) + return; + + SUB_UseTargets (); + +// put a tfog where the player was + spawn_tfog (other.origin); + + t = find (world, targetname, self.target); + if (!t) + objerror ("couldn't find target"); + +// spawn a tfog flash in front of the destination + makevectors (t.mangle); + org = t.origin + 32 * v_forward; + + spawn_tfog (org); + spawn_tdeath(t.origin, other); + +// move the player and lock him down for a little while + if (!other.health) + { + other.origin = t.origin; + other.velocity = (v_forward * other.velocity_x) + (v_forward * other.velocity_y); + return; + } + + setorigin (other, t.origin); + other.angles = t.mangle; + if (other.classname == "player") + { + other.fixangle = 1; // turn this way immediately + other.teleport_time = time + 0.7; + if (other.flags & FL_ONGROUND) + other.flags = other.flags - FL_ONGROUND; + other.velocity = v_forward * 300; + } + other.flags = other.flags - other.flags & FL_ONGROUND; +}; + +/*QUAKED info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32) +This is the destination marker for a teleporter. It should have a "targetname" field with the same value as a teleporter's "target" field. +*/ +void() info_teleport_destination = +{ +// this does nothing, just serves as a target spot + self.mangle = self.angles; + self.angles = '0 0 0'; + self.model = ""; + self.origin = self.origin + '0 0 27'; + if (!self.targetname) + objerror ("no targetname"); +}; + +void() teleport_use = +{ + self.nextthink = time + 0.2; + force_retouch = 2; // make sure even still objects get hit + self.think = SUB_Null; +}; + +/*QUAKED trigger_teleport (.5 .5 .5) ? PLAYER_ONLY SILENT +Any object touching this will be transported to the corresponding info_teleport_destination entity. You must set the "target" field, and create an object with a "targetname" field that matches. + +If the trigger_teleport has a targetname, it will only teleport entities when it has been fired. +*/ +void() trigger_teleport = +{ + local vector o; + + InitTrigger (); + self.touch = teleport_touch; + // find the destination + if (!self.target) + objerror ("no target"); + self.use = teleport_use; + + if (!(self.spawnflags & SILENT)) + { + precache_sound ("ambience/hum1.wav"); + o = (self.mins + self.maxs)*0.5; + ambientsound (o, "ambience/hum1.wav",0.5 , ATTN_STATIC); + } +}; + +/* +============================================================================== + +trigger_setskill + +============================================================================== +*/ + +void() trigger_skill_touch = +{ + if (other.classname != "player") + return; + + cvar_set ("skill", self.message); +}; + +/*QUAKED trigger_setskill (.5 .5 .5) ? +sets skill level to the value of "message". +Only used on start map. +*/ +void() trigger_setskill = +{ + InitTrigger (); + self.touch = trigger_skill_touch; +}; + + +/* +============================================================================== + +ONLY REGISTERED TRIGGERS + +============================================================================== +*/ + +void() trigger_onlyregistered_touch = +{ + if (other.classname != "player") + return; + if (self.attack_finished > time) + return; + + self.attack_finished = time + 2; + if (cvar("registered")) + { + self.message = ""; + SUB_UseTargets (); + remove (self); + } + else + { + if (self.message != "") + { + centerprint (other, self.message); + sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM); + } + } +}; + +/*QUAKED trigger_onlyregistered (.5 .5 .5) ? +Only fires if playing the registered version, otherwise prints the message +*/ +void() trigger_onlyregistered = +{ + precache_sound ("misc/talk.wav"); + InitTrigger (); + self.touch = trigger_onlyregistered_touch; +}; + +//============================================================================ + +void() hurt_on = +{ + self.solid = SOLID_TRIGGER; + self.nextthink = -1; +}; + +void() hurt_touch = +{ + if (other.takedamage) + { + self.solid = SOLID_NOT; + T_Damage (other, self, self, self.dmg); + self.think = hurt_on; + self.nextthink = time + 1; + } + + return; +}; + +/*QUAKED trigger_hurt (.5 .5 .5) ? +Any object touching this will be hurt +set dmg to damage amount +defalt dmg = 5 +*/ +void() trigger_hurt = +{ + InitTrigger (); + self.touch = hurt_touch; + if (!self.dmg) + self.dmg = 5; +}; + +//============================================================================ + +float PUSH_ONCE = 1; + +//function provided by mercury (of oztf) +void () trigger_push_findtarget = +{ + local float flighttime; + local float dist; + local float grav; + local vector org; + + self.enemy = find (world, targetname, self.target); + if (!self.enemy) + { + dprint("trigger_push: target "); + dprint(self.target); + dprint(" not found\n"); + remove (self); + return; + } + org = (self.absmin + self.absmax) * 0.5; + grav = cvar ("sv_gravity"); + flighttime = sqrt ((self.enemy.origin_z - org_z) / (0.5 * grav)); + if (!flighttime) + { + dprint("trigger_push: target "); + dprint(self.target); + dprint(" too close\n"); + remove (self); + return; + } + self.movedir = self.enemy.origin - org; + self.movedir_z = 0; + dist = vlen (self.movedir); + self.movedir = normalize (self.movedir) * (dist / flighttime); + self.movedir_z = flighttime * grav; +}; + +void() trigger_push_touch = +{ + if (other.classname == "grenade") + other.velocity = self.movedir; + else if (other.health > 0) + { + other.velocity = self.movedir; + if (other.classname == "player") + { + if (other.fly_sound < time) + { + other.fly_sound = time + 1.5; + sound (other, CHAN_AUTO, "ambience/windfly.wav", 1, ATTN_NORM); + } + } + } + if (self.spawnflags & PUSH_ONCE) + remove(self); +}; + + +/*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE +Pushes the player +*/ +void() trigger_push = +{ + InitTrigger (); + precache_sound ("ambience/windfly.wav"); + self.touch = trigger_push_touch; + if (!self.speed) + self.speed = 1000; + + self.movedir = self.movedir * self.speed * 10; + + if (self.target) + { +// if (sqrt) + { + self.think = trigger_push_findtarget; + self.nextthink = time + 0.2; + } +// else +// remove(self); + } +}; + +//============================================================================ + +void() trigger_monsterjump_touch = +{ + if ( other.flags & (FL_MONSTER | FL_FLY | FL_SWIM) != FL_MONSTER ) + return; + +// set XY even if not on ground, so the jump will clear lips + other.velocity_x = self.movedir_x * self.speed; + other.velocity_y = self.movedir_y * self.speed; + + if ( !(other.flags & FL_ONGROUND) ) + return; + + other.flags = other.flags - FL_ONGROUND; + + other.velocity_z = self.height; +}; + +/*QUAKED trigger_monsterjump (.5 .5 .5) ? +Walking monsters that touch this will jump in the direction of the trigger's angle +"speed" default to 200, the speed thrown forward +"height" default to 200, the speed thrown upwards +*/ +void() trigger_monsterjump = +{ + if (!self.speed) + self.speed = 200; + if (!self.height) + self.height = 200; + if (self.angles == '0 0 0') + self.angles = '0 360 0'; + InitTrigger (); + self.touch = trigger_monsterjump_touch; +}; + diff --git a/quakec/csqctest/src/ss/weapons.qc b/quakec/csqctest/src/ss/weapons.qc new file mode 100644 index 000000000..120d864e1 --- /dev/null +++ b/quakec/csqctest/src/ss/weapons.qc @@ -0,0 +1,1348 @@ +/* +*/ +void (entity targ, entity inflictor, entity attacker, float damage) T_Damage; +void () player_run; +void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage; +void(vector org, vector vel, float damage) SpawnBlood; +void() SuperDamageSound; + + +// called by worldspawn +void() W_Precache = +{ + precache_sound ("weapons/r_exp3.wav"); // new rocket explosion + precache_sound ("weapons/rocket1i.wav"); // spike gun + precache_sound ("weapons/sgun1.wav"); + precache_sound ("weapons/guncock.wav"); // player shotgun + precache_sound ("weapons/ric1.wav"); // ricochet (used in c code) + precache_sound ("weapons/ric2.wav"); // ricochet (used in c code) + precache_sound ("weapons/ric3.wav"); // ricochet (used in c code) + precache_sound ("weapons/spike2.wav"); // super spikes + precache_sound ("weapons/tink1.wav"); // spikes tink (used in c code) + precache_sound ("weapons/grenade.wav"); // grenade launcher + precache_sound ("weapons/bounce.wav"); // grenade bounce + precache_sound ("weapons/shotgn2.wav"); // super shotgun +}; + +float() crandom = +{ + return 2*(random() - 0.5); +}; + +/* +================ +W_FireAxe +================ +*/ +void() W_FireAxe = +{ + local vector source; + local vector org; + + makevectors (self.v_angle); + source = self.origin + '0 0 16'; + traceline (source, source + v_forward*64, FALSE, self); + if (trace_fraction == 1.0) + return; + + org = trace_endpos - v_forward*4; + + if (trace_ent.takedamage) + { + trace_ent.axhitme = 1; + SpawnBlood (org, '0 0 0', 20); + T_Damage (trace_ent, self, self, 20); + } + else + { // hit wall + sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM); + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_GUNSHOT); + WriteCoord (MSG_BROADCAST, org_x); + WriteCoord (MSG_BROADCAST, org_y); + WriteCoord (MSG_BROADCAST, org_z); + } +}; + + +//============================================================================ + + +vector() wall_velocity = +{ + local vector vel; + + vel = normalize (self.velocity); + vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5)); + vel = vel + 2*trace_plane_normal; + vel = vel * 200; + + return vel; +}; + + +/* +================ +SpawnMeatSpray +================ +*/ +void(vector org, vector vel) SpawnMeatSpray = +{ + local entity missile; + + missile = spawn (); + missile.owner = self; + missile.movetype = MOVETYPE_BOUNCE; + missile.solid = SOLID_NOT; + + makevectors (self.angles); + + missile.velocity = vel; + missile.velocity_z = missile.velocity_z + 250 + 50*random(); + + missile.avelocity = '3000 1000 2000'; + +// set missile duration + missile.nextthink = time + 1; + missile.think = SUB_Remove; + + setmodel (missile, "progs/zom_gib.mdl"); + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, org); +}; + +/* +================ +SpawnBlood +================ +*/ +void(vector org, vector vel, float damage) SpawnBlood = +{ + particle (org, vel*0.1, 73, damage*2); +}; + +/* +================ +spawn_touchblood +================ +*/ +void(float damage) spawn_touchblood = +{ + local vector vel; + + vel = wall_velocity () * 0.2; + SpawnBlood (self.origin + vel*0.01, vel, damage); +}; + + +/* +================ +SpawnChunk +================ +*/ +/*void(vector org, vector vel) SpawnChunk = +{ + particle (org, vel*0.02, 0, 10); +};*/ + +/* +============================================================================== + +MULTI-DAMAGE + +Collects multiple small damages into a single damage + +============================================================================== +*/ + +entity multi_ent; +float multi_damage; + +void() ClearMultiDamage = +{ + multi_ent = world; + multi_damage = 0; +}; + +void() ApplyMultiDamage = +{ + if (!multi_ent) + return; + T_Damage (multi_ent, self, self, multi_damage); +}; + +void(entity hit, float damage) AddMultiDamage = +{ + if (!hit) + return; + + if (hit != multi_ent) + { + ApplyMultiDamage (); + multi_damage = damage; + multi_ent = hit; + } + else + multi_damage = multi_damage + damage; +}; + +/* +============================================================================== + +BULLETS + +============================================================================== +*/ + +/* +================ +TraceAttack +================ +*/ +void(float damage, vector dir) TraceAttack = +{ + local vector vel, org; + + vel = normalize(dir + v_up*crandom() + v_right*crandom()); + vel = vel + 2*trace_plane_normal; + vel = vel * 200; + + org = trace_endpos - dir*4; + + if (trace_ent.takedamage) + { + SpawnBlood (org, vel*0.2, damage); + AddMultiDamage (trace_ent, damage); + } + else + { + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_GUNSHOT); + WriteCoord (MSG_BROADCAST, org_x); + WriteCoord (MSG_BROADCAST, org_y); + WriteCoord (MSG_BROADCAST, org_z); + } +}; + +/* +================ +FireBullets + +Used by shotgun, super shotgun, and enemy soldier firing +Go to the trouble of combining multiple pellets into a single damage call. +================ +*/ +void(float shotcount, vector dir, vector spread) FireBullets = +{ + local vector direction; + local vector src; + + makevectors(self.v_angle); + + src = self.origin + v_forward*10; + src_z = self.absmin_z + self.size_z * 0.7; + + ClearMultiDamage (); + while (shotcount > 0) + { + direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up; + + traceline (src, src + direction*2048, FALSE, self); + if (trace_fraction != 1.0) + TraceAttack (4, direction); + + shotcount = shotcount - 1; + } + ApplyMultiDamage (); +}; + +/* +================ +W_FireShotgun +================ +*/ +void() W_FireShotgun = +{ + local vector dir; + + sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM); + + self.punchangle_x = -2; + + self.currentammo = self.ammo_shells = self.ammo_shells - 1; + dir = aim (self, 100000); + FireBullets (6, dir, '0.04 0.04 0'); +}; + + +/* +================ +W_FireSuperShotgun +================ +*/ +void() W_FireSuperShotgun = +{ + local vector dir; + + if (self.currentammo == 1) + { + W_FireShotgun (); + return; + } + + sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM); + + self.punchangle_x = -4; + + self.currentammo = self.ammo_shells = self.ammo_shells - 2; + dir = aim (self, 100000); + FireBullets (14, dir, '0.14 0.08 0'); +}; + + +/* +============================================================================== + +ROCKETS + +============================================================================== +*/ + +.vector source; +.float starttime; + +float(entity toplayer) SendNail = +{ + vector v; + v = self.source + self.velocity*(time-self.starttime); + WriteByte(MSG_ENTITY, CLASS_NAIL); + WriteCoord(MSG_ENTITY, v_x); + WriteCoord(MSG_ENTITY, v_y); + WriteCoord(MSG_ENTITY, v_z); + WriteByte(MSG_ENTITY, self.modelindex); //note: some engines support >256 modelindexes. so long as it's precached in worldspawn, it'll not be an issue. + WriteShort(MSG_ENTITY, vlen(self.velocity)); + WriteShort(MSG_ENTITY, self.angles_x*65535/360); //we might get better precision if we were to writecoord some point ahead that it should pass through, but this is smaller and accurate enough. + WriteShort(MSG_ENTITY, self.angles_y*65535/360); + + return TRUE; +}; + +float(entity toplayer) SendRocket = +{ + vector v; + v = self.source + self.velocity*(time-self.starttime); + WriteByte(MSG_ENTITY, CLASS_ROCKET); + WriteCoord(MSG_ENTITY, v_x); + WriteCoord(MSG_ENTITY, v_y); + WriteCoord(MSG_ENTITY, v_z); + WriteShort(MSG_ENTITY, self.angles_x*65535/360); //we might get better precision if we were to writecoord some point ahead that it should pass through, but this is smaller and accurate enough. + WriteShort(MSG_ENTITY, self.angles_y*65535/360); + + return TRUE; +}; + + +float(entity toplayer) SendExplosion = +{ + vector v; + v = self.origin; + WriteByte(MSG_ENTITY, CLASS_EXPLOSION); + WriteCoord(MSG_ENTITY, v_x); + WriteCoord(MSG_ENTITY, v_y); + WriteCoord(MSG_ENTITY, v_z); + + return TRUE; +}; + +void() s_explode1 = [0, s_explode2] {}; +void() s_explode2 = [1, s_explode3] {}; +void() s_explode3 = [2, s_explode4] {}; +void() s_explode4 = [3, s_explode5] {}; +void() s_explode5 = [4, s_explode6] {}; +void() s_explode6 = [5, SUB_Remove] {}; + +void() BecomeExplosion = +{ + self.movetype = MOVETYPE_NONE; + self.velocity = '0 0 0'; + self.touch = SUB_Null; + self.solid = SOLID_NOT; + + self.dimension_seen = 2; + dimension_send = 2; + te_explosion(self.origin); + sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM); + self.dimension_seen = 3; + dimension_send = 3; + + setmodel (self, "progs/s_explod.spr"); + s_explode1 (); + +//set up the fields required for transmitting the event. + self.source = self.origin; + self.SendEntity = SendExplosion; + self.starttime = time; + self.Version+=1; +}; + +void() T_MissileTouch = +{ + local float damg; + + if (other == self.owner) + return; // don't explode on owner + + if (pointcontents(self.origin) == CONTENT_SKY) + { + remove(self); + return; + } + + damg = 100 + random()*20; + + if (other.health) + { + if (other.classname == "monster_shambler") + damg = damg * 0.5; // mostly immune + T_Damage (other, self, self.owner, damg ); + } + + // don't do radius damage to the other, because all the damage + // was done in the impact + T_RadiusDamage (self, self.owner, 120, other); + +// sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM); + self.origin = self.origin - 8*normalize(self.velocity); + + BecomeExplosion (); +}; + +/* +================ +W_FireRocket +================ +*/ +void() W_FireRocket = +{ + local entity missile; + + self.currentammo = self.ammo_rockets = self.ammo_rockets - 1; + + sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM); + + self.punchangle_x = -2; + + missile = spawn (); + missile.owner = self; + missile.movetype = MOVETYPE_FLYMISSILE; + missile.solid = SOLID_BBOX; + missile.classname = "missile"; + +// set missile speed + + makevectors (self.v_angle); + missile.velocity = aim(self, 1000); + missile.velocity = missile.velocity * 1000; + missile.angles = vectoangles(missile.velocity); + + missile.touch = T_MissileTouch; + +// set missile duration + missile.nextthink = time + 5; + missile.think = SUB_Remove; + + setmodel (missile, "progs/missile.mdl"); + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, self.origin + v_forward*8 + '0 0 16'); + + missile.source = missile.origin; + missile.SendEntity = SendRocket; + missile.starttime = time; + missile.Version+=1; +}; + +/* +=============================================================================== + +LIGHTNING + +=============================================================================== +*/ + +/* +================= +LightningDamage +================= +*/ +void(vector p1, vector p2, entity from, float damage) LightningDamage = +{ + local entity e1, e2; + local vector f; + + f = p2 - p1; + normalize (f); + f_x = 0 - f_y; + f_y = f_x; + f_z = 0; + f = f*16; + + e1 = e2 = world; + + traceline (p1, p2, FALSE, self); + if (trace_ent.takedamage) + { + particle (trace_endpos, '0 0 100', 225, damage*4); + T_Damage (trace_ent, from, from, damage); + if (self.classname == "player") + { + if (other.classname == "player") + trace_ent.velocity_z = trace_ent.velocity_z + 400; + } + } + e1 = trace_ent; + + traceline (p1 + f, p2 + f, FALSE, self); + if (trace_ent != e1 && trace_ent.takedamage) + { + particle (trace_endpos, '0 0 100', 225, damage*4); + T_Damage (trace_ent, from, from, damage); + } + e2 = trace_ent; + + traceline (p1 - f, p2 - f, FALSE, self); + if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage) + { + particle (trace_endpos, '0 0 100', 225, damage*4); + T_Damage (trace_ent, from, from, damage); + } +}; + + +void() W_FireLightning = +{ + local vector org; + local float cells; + + if (self.ammo_cells < 1) + { + self.weapon = W_BestWeapon (); + W_SetCurrentAmmo (); + return; + } + +// explode if under water + if (self.waterlevel > 1) + { + cells = self.ammo_cells; + self.ammo_cells = 0; + W_SetCurrentAmmo (); + T_RadiusDamage (self, self, 35*cells, world); + return; + } + + if (self.t_width < time) + { + sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM); + self.t_width = time + 0.6; + } + self.punchangle_x = -2; + + self.currentammo = self.ammo_cells = self.ammo_cells - 1; + + org = self.origin + '0 0 16'; + + traceline (org, org + v_forward*600, TRUE, self); + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_LIGHTNING2); + WriteEntity (MSG_BROADCAST, self); + WriteCoord (MSG_BROADCAST, org_x); + WriteCoord (MSG_BROADCAST, org_y); + WriteCoord (MSG_BROADCAST, org_z); + WriteCoord (MSG_BROADCAST, trace_endpos_x); + WriteCoord (MSG_BROADCAST, trace_endpos_y); + WriteCoord (MSG_BROADCAST, trace_endpos_z); + + LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30); +}; + + +//============================================================================= + + +void() GrenadeExplode = +{ + T_RadiusDamage (self, self.owner, 120, world); + + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_EXPLOSION); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + + BecomeExplosion (); +}; + +void() GrenadeTouch = +{ + if (other == self.owner) + return; // don't explode on owner + if (other.takedamage == DAMAGE_AIM) + { + GrenadeExplode(); + return; + } + sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM); // bounce sound + if (self.velocity == '0 0 0') + self.avelocity = '0 0 0'; +}; + +/* +================ +W_FireGrenade +================ +*/ +void() W_FireGrenade = +{ + local entity missile; + + self.currentammo = self.ammo_rockets = self.ammo_rockets - 1; + + sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM); + + self.punchangle_x = -2; + + missile = spawn (); + missile.owner = self; + missile.movetype = MOVETYPE_BOUNCE; + missile.solid = SOLID_BBOX; + missile.classname = "grenade"; + +// set missile speed + + makevectors (self.v_angle); + + if (self.v_angle_x) + missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10; + else + { + missile.velocity = aim(self, 10000); + missile.velocity = missile.velocity * 600; + missile.velocity_z = 200; + } + + missile.avelocity = '300 300 300'; + + missile.angles = vectoangles(missile.velocity); + + missile.touch = GrenadeTouch; + +// set missile duration + missile.nextthink = time + 2.5; + missile.think = GrenadeExplode; + + setmodel (missile, "progs/grenade.mdl"); + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, self.origin); +}; + + +//============================================================================= + +void() spike_touch; +void() superspike_touch; + + +/* +=============== +launch_spike + +Used for both the player and the ogre +=============== +*/ +void(vector org, vector dir) launch_spike = +{ + newmis = spawn (); + newmis.owner = self; + newmis.movetype = MOVETYPE_FLYMISSILE; + newmis.solid = SOLID_BBOX; + + newmis.angles = vectoangles(dir); + + newmis.touch = spike_touch; + newmis.classname = "spike"; + newmis.think = SUB_Remove; + newmis.nextthink = time + 6; + setmodel (newmis, "progs/spike.mdl"); + setsize (newmis, VEC_ORIGIN, VEC_ORIGIN); + setorigin (newmis, org); + + newmis.velocity = dir * 1000; + + newmis.SendEntity = SendNail; + newmis.Version++; + newmis.source = newmis.origin; + newmis.starttime = time; +}; + +void() W_FireSuperSpikes = +{ + local vector dir; + + sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM); + self.attack_finished = time + 0.2; + self.currentammo = self.ammo_nails = self.ammo_nails - 2; + dir = aim (self, 1000); + launch_spike (self.origin + '0 0 16', dir); + newmis.touch = superspike_touch; + setmodel (newmis, "progs/s_spike.mdl"); + setsize (newmis, VEC_ORIGIN, VEC_ORIGIN); + self.punchangle_x = -2; +}; + +void(float ox) W_FireSpikes = +{ + local vector dir; + + makevectors (self.v_angle); + + if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN) + { + W_FireSuperSpikes (); + return; + } + + if (self.ammo_nails < 1) + { + self.weapon = W_BestWeapon (); + W_SetCurrentAmmo (); + return; + } + + sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM); + self.attack_finished = time + 0.2; + self.currentammo = self.ammo_nails = self.ammo_nails - 1; + dir = aim (self, 1000); + launch_spike (self.origin + '0 0 16' + v_right*ox, dir); + + self.punchangle_x = -2; +}; + + + +void() spike_touch = +{ + if (other == self.owner) + return; + + if (other.solid == SOLID_TRIGGER) + return; // trigger field, do nothing + + if (pointcontents(self.origin) == CONTENT_SKY) + { + remove(self); + return; + } + +// hit something that bleeds + if (other.takedamage) + { + spawn_touchblood (9); + T_Damage (other, self, self.owner, 9); + } + else + { + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + + if (self.classname == "wizspike") + WriteByte (MSG_BROADCAST, TE_WIZSPIKE); + else if (self.classname == "knightspike") + WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE); + else + WriteByte (MSG_BROADCAST, TE_SPIKE); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + } + + remove(self); + +}; + +void() superspike_touch = +{ + if (other == self.owner) + return; + + if (other.solid == SOLID_TRIGGER) + return; // trigger field, do nothing + + if (pointcontents(self.origin) == CONTENT_SKY) + { + remove(self); + return; + } + +// hit something that bleeds + if (other.takedamage) + { + spawn_touchblood (18); + T_Damage (other, self, self.owner, 18); + } + else + { + WriteByte (MSG_BROADCAST, SVC_TEMPENTITY); + WriteByte (MSG_BROADCAST, TE_SUPERSPIKE); + WriteCoord (MSG_BROADCAST, self.origin_x); + WriteCoord (MSG_BROADCAST, self.origin_y); + WriteCoord (MSG_BROADCAST, self.origin_z); + } + + remove(self); + +}; + + +/* +=============================================================================== + +PLAYER WEAPON USE + +=============================================================================== +*/ + +void() W_SetCurrentAmmo = +{ + player_run (); // get out of any weapon firing states + + self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) ); + + if (self.weapon == IT_AXE) + { + self.currentammo = 0; + self.weaponmodel = "progs/v_axe.mdl"; + self.weaponframe = 0; + } + else if (self.weapon == IT_SHOTGUN) + { + self.currentammo = self.ammo_shells; + self.weaponmodel = "progs/v_shot.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_SHELLS; + } + else if (self.weapon == IT_SUPER_SHOTGUN) + { + self.currentammo = self.ammo_shells; + self.weaponmodel = "progs/v_shot2.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_SHELLS; + } + else if (self.weapon == IT_NAILGUN) + { + self.currentammo = self.ammo_nails; + self.weaponmodel = "progs/v_nail.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_NAILS; + } + else if (self.weapon == IT_SUPER_NAILGUN) + { + self.currentammo = self.ammo_nails; + self.weaponmodel = "progs/v_nail2.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_NAILS; + } + else if (self.weapon == IT_GRENADE_LAUNCHER) + { + self.currentammo = self.ammo_rockets; + self.weaponmodel = "progs/v_rock.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_ROCKETS; + } + else if (self.weapon == IT_ROCKET_LAUNCHER) + { + self.currentammo = self.ammo_rockets; + self.weaponmodel = "progs/v_rock2.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_ROCKETS; + } + else if (self.weapon == IT_LIGHTNING) + { + self.currentammo = self.ammo_cells; + self.weaponmodel = "progs/v_light.mdl"; + self.weaponframe = 0; + self.items = self.items | IT_CELLS; + } + else + { + self.currentammo = 0; + self.weaponmodel = ""; + self.weaponframe = 0; + } +}; + +float() W_BestWeapon = +{ + local float it; + + it = self.items; + + if (self.waterlevel <= 1 && self.ammo_cells >= 1 && (it & IT_LIGHTNING) ) + return IT_LIGHTNING; + if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) ) + return IT_SUPER_NAILGUN; + if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) ) + return IT_SUPER_SHOTGUN; + if(self.ammo_nails >= 1 && (it & IT_NAILGUN) ) + return IT_NAILGUN; + if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) ) + return IT_SHOTGUN; + return IT_AXE; +}; + +float() W_CheckNoAmmo = +{ + if (self.currentammo > 0) + return TRUE; + + if (self.weapon == IT_AXE) + return TRUE; + + self.weapon = W_BestWeapon (); + + W_SetCurrentAmmo (); + +// drop the weapon down + return FALSE; +}; + +/* +============ +W_Attack + +An attack impulse can be triggered now +============ +*/ +void() player_axe1; +void() player_axeb1; +void() player_axec1; +void() player_axed1; +void() player_shot1; +void() player_nail1; +void() player_light1; +void() player_rocket1; + +void() W_Attack = +{ + local float r; + + if (!W_CheckNoAmmo ()) + return; + + makevectors (self.v_angle); // calculate forward angle for velocity + self.show_hostile = time + 1; // wake monsters up + + if (self.weapon == IT_AXE) + { + sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM); + r = random(); + if (r < 0.25) + player_axe1 (); + else if (r<0.5) + player_axeb1 (); + else if (r<0.75) + player_axec1 (); + else + player_axed1 (); + self.attack_finished = time + 0.5; + } + else if (self.weapon == IT_SHOTGUN) + { + player_shot1 (); + W_FireShotgun (); + self.attack_finished = time + 0.5; + } + else if (self.weapon == IT_SUPER_SHOTGUN) + { + player_shot1 (); + W_FireSuperShotgun (); + self.attack_finished = time + 0.7; + } + else if (self.weapon == IT_NAILGUN) + { + player_nail1 (); + } + else if (self.weapon == IT_SUPER_NAILGUN) + { + player_nail1 (); + } + else if (self.weapon == IT_GRENADE_LAUNCHER) + { + player_rocket1(); + W_FireGrenade(); + self.attack_finished = time + 0.6; + } + else if (self.weapon == IT_ROCKET_LAUNCHER) + { + player_rocket1(); + W_FireRocket(); + self.attack_finished = time + 0.8; + } + else if (self.weapon == IT_LIGHTNING) + { + player_light1(); + self.attack_finished = time + 0.1; + sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM); + } +}; + +/* +============ +W_ChangeWeapon + +============ +*/ +void() W_ChangeWeapon = +{ + local float it, am, fl; + + it = self.items; + am = 0; + + if (self.impulse == 1) + { + fl = IT_AXE; + } + else if (self.impulse == 2) + { + fl = IT_SHOTGUN; + if (self.ammo_shells < 1) + am = 1; + } + else if (self.impulse == 3) + { + fl = IT_SUPER_SHOTGUN; + if (self.ammo_shells < 2) + am = 1; + } + else if (self.impulse == 4) + { + fl = IT_NAILGUN; + if (self.ammo_nails < 1) + am = 1; + } + else if (self.impulse == 5) + { + fl = IT_SUPER_NAILGUN; + if (self.ammo_nails < 2) + am = 1; + } + else if (self.impulse == 6) + { + fl = IT_GRENADE_LAUNCHER; + if (self.ammo_rockets < 1) + am = 1; + } + else if (self.impulse == 7) + { + fl = IT_ROCKET_LAUNCHER; + if (self.ammo_rockets < 1) + am = 1; + } + else if (self.impulse == 8) + { + fl = IT_LIGHTNING; + if (self.ammo_cells < 1) + am = 1; + } + + self.impulse = 0; + + if (!(self.items & fl)) + { // don't have the weapon or the ammo + sprint (self, "no weapon.\n"); + return; + } + + if (am) + { // don't have the ammo + sprint (self, "not enough ammo.\n"); + return; + } + +// +// set weapon, set ammo +// + self.weapon = fl; + W_SetCurrentAmmo (); +}; + +/* +============ +CheatCommand +============ +*/ +void() CheatCommand = +{ + if (deathmatch || coop) + return; + + self.ammo_rockets = 100; + self.ammo_nails = 200; + self.ammo_shells = 100; + self.items = self.items | + IT_AXE | + IT_SHOTGUN | + IT_SUPER_SHOTGUN | + IT_NAILGUN | + IT_SUPER_NAILGUN | + IT_GRENADE_LAUNCHER | + IT_ROCKET_LAUNCHER | + IT_KEY1 | IT_KEY2; + + self.ammo_cells = 200; + self.items = self.items | IT_LIGHTNING; + + self.weapon = IT_ROCKET_LAUNCHER; + self.impulse = 0; + W_SetCurrentAmmo (); +}; + +/* +============ +CycleWeaponCommand + +Go to the next weapon with ammo +============ +*/ +void() CycleWeaponCommand = +{ + local float it, am; + + it = self.items; + self.impulse = 0; + + while (1) + { + am = 0; + + if (self.weapon == IT_LIGHTNING) + { + self.weapon = IT_AXE; + } + else if (self.weapon == IT_AXE) + { + self.weapon = IT_SHOTGUN; + if (self.ammo_shells < 1) + am = 1; + } + else if (self.weapon == IT_SHOTGUN) + { + self.weapon = IT_SUPER_SHOTGUN; + if (self.ammo_shells < 2) + am = 1; + } + else if (self.weapon == IT_SUPER_SHOTGUN) + { + self.weapon = IT_NAILGUN; + if (self.ammo_nails < 1) + am = 1; + } + else if (self.weapon == IT_NAILGUN) + { + self.weapon = IT_SUPER_NAILGUN; + if (self.ammo_nails < 2) + am = 1; + } + else if (self.weapon == IT_SUPER_NAILGUN) + { + self.weapon = IT_GRENADE_LAUNCHER; + if (self.ammo_rockets < 1) + am = 1; + } + else if (self.weapon == IT_GRENADE_LAUNCHER) + { + self.weapon = IT_ROCKET_LAUNCHER; + if (self.ammo_rockets < 1) + am = 1; + } + else if (self.weapon == IT_ROCKET_LAUNCHER) + { + self.weapon = IT_LIGHTNING; + if (self.ammo_cells < 1) + am = 1; + } + + if ( (it & self.weapon) && am == 0) + { + W_SetCurrentAmmo (); + return; + } + } + +}; + +/* +============ +CycleWeaponReverseCommand + +Go to the prev weapon with ammo +============ +*/ +void() CycleWeaponReverseCommand = +{ + local float it, am; + + it = self.items; + self.impulse = 0; + + while (1) + { + am = 0; + + if (self.weapon == IT_LIGHTNING) + { + self.weapon = IT_ROCKET_LAUNCHER; + if (self.ammo_rockets < 1) + am = 1; + } + else if (self.weapon == IT_ROCKET_LAUNCHER) + { + self.weapon = IT_GRENADE_LAUNCHER; + if (self.ammo_rockets < 1) + am = 1; + } + else if (self.weapon == IT_GRENADE_LAUNCHER) + { + self.weapon = IT_SUPER_NAILGUN; + if (self.ammo_nails < 2) + am = 1; + } + else if (self.weapon == IT_SUPER_NAILGUN) + { + self.weapon = IT_NAILGUN; + if (self.ammo_nails < 1) + am = 1; + } + else if (self.weapon == IT_NAILGUN) + { + self.weapon = IT_SUPER_SHOTGUN; + if (self.ammo_shells < 2) + am = 1; + } + else if (self.weapon == IT_SUPER_SHOTGUN) + { + self.weapon = IT_SHOTGUN; + if (self.ammo_shells < 1) + am = 1; + } + else if (self.weapon == IT_SHOTGUN) + { + self.weapon = IT_AXE; + } + else if (self.weapon == IT_AXE) + { + self.weapon = IT_LIGHTNING; + if (self.ammo_cells < 1) + am = 1; + } + + if ( (it & self.weapon) && am == 0) + { + W_SetCurrentAmmo (); + return; + } + } + +}; + +/* +============ +ServerflagsCommand + +Just for development +============ +*/ +void() ServerflagsCommand = +{ + serverflags = serverflags * 2 + 1; +}; + +void() QuadCheat = +{ + if (deathmatch || coop) + return; + self.super_time = 1; + self.super_damage_finished = time + 30; + self.items = self.items | IT_QUAD; + dprint ("quad cheat\n"); +}; + +/* +============ +ImpulseCommands + +============ +*/ +void() ImpulseCommands = +{ + if (self.impulse >= 1 && self.impulse <= 8) + W_ChangeWeapon (); + + if (self.impulse == 9) + CheatCommand (); + if (self.impulse == 10) + CycleWeaponCommand (); + if (self.impulse == 11) + ServerflagsCommand (); + if (self.impulse == 12) + CycleWeaponReverseCommand (); + + if (self.impulse == 255) + QuadCheat (); + + self.impulse = 0; +}; + +/* +============ +W_WeaponFrame + +Called every frame so impulse events can be handled as well as possible +============ +*/ +void() W_WeaponFrame = +{ + if (time < self.attack_finished) + return; + + ImpulseCommands (); + +// check for attack + if (self.button0) + { + SuperDamageSound (); + W_Attack (); + } +}; + +/* +======== +SuperDamageSound + +Plays sound if needed +======== +*/ +void() SuperDamageSound = +{ + if (self.super_damage_finished > time) + { + if (self.super_sound < time) + { + self.super_sound = time + 1; + sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM); + } + } + return; +}; + + diff --git a/quakec/csqctest/src/ss/wizard.qc b/quakec/csqctest/src/ss/wizard.qc new file mode 100644 index 000000000..9418fea41 --- /dev/null +++ b/quakec/csqctest/src/ss/wizard.qc @@ -0,0 +1,407 @@ +/* +============================================================================== + +WIZARD + +============================================================================== +*/ + +$cd id1/models/a_wizard +$origin 0 0 24 +$base wizbase +$skin wizbase + +$frame hover1 hover2 hover3 hover4 hover5 hover6 hover7 hover8 +$frame hover9 hover10 hover11 hover12 hover13 hover14 hover15 + +$frame fly1 fly2 fly3 fly4 fly5 fly6 fly7 fly8 fly9 fly10 +$frame fly11 fly12 fly13 fly14 + +$frame magatt1 magatt2 magatt3 magatt4 magatt5 magatt6 magatt7 +$frame magatt8 magatt9 magatt10 magatt11 magatt12 magatt13 + +$frame pain1 pain2 pain3 pain4 + +$frame death1 death2 death3 death4 death5 death6 death7 death8 + +/* +============================================================================== + +WIZARD + +If the player moves behind cover before the missile is launched, launch it +at the last visible spot with no velocity leading, in hopes that the player +will duck back out and catch it. +============================================================================== +*/ + +/* +============= +LaunchMissile + +Sets the given entities velocity and angles so that it will hit self.enemy +if self.enemy maintains it's current velocity +0.1 is moderately accurate, 0.0 is totally accurate +============= +*/ +/* +void(entity missile, float mspeed, float accuracy) LaunchMissile = +{ + local vector vec, move; + local float fly; + + makevectors (self.angles); + +// set missile speed + vec = self.enemy.origin + self.enemy.mins + self.enemy.size * 0.7 - missile.origin; + +// calc aproximate time for missile to reach vec + fly = vlen (vec) / mspeed; + +// get the entities xy velocity + move = self.enemy.velocity; + move_z = 0; + +// project the target forward in time + vec = vec + move * fly; + + vec = normalize(vec); + vec = vec + accuracy*v_up*(random()- 0.5) + accuracy*v_right*(random()- 0.5); + + missile.velocity = vec * mspeed; + + missile.angles = '0 0 0'; + missile.angles_y = vectoyaw(missile.velocity); + +// set missile duration + missile.nextthink = time + 5; + missile.think = SUB_Remove; +}; +*/ + +void() wiz_run1; +void() wiz_side1; + +/* +================= +WizardCheckAttack +================= +*/ +float() WizardCheckAttack = +{ + local vector spot1, spot2; + local entity targ; + local float chance; + + if (time < self.attack_finished) + return FALSE; + if (!enemy_vis) + return FALSE; + + if (enemy_range == RANGE_FAR) + { + if (self.attack_state != AS_STRAIGHT) + { + self.attack_state = AS_STRAIGHT; + wiz_run1 (); + } + return FALSE; + } + + targ = self.enemy; + +// see if any entities are in the way of the shot + spot1 = self.origin + self.view_ofs; + spot2 = targ.origin + targ.view_ofs; + + traceline (spot1, spot2, FALSE, self); + + if (trace_ent != targ) + { // don't have a clear shot, so move to a side + if (self.attack_state != AS_STRAIGHT) + { + self.attack_state = AS_STRAIGHT; + wiz_run1 (); + } + return FALSE; + } + + if (enemy_range == RANGE_MELEE) + chance = 0.9; + else if (enemy_range == RANGE_NEAR) + chance = 0.6; + else if (enemy_range == RANGE_MID) + chance = 0.2; + else + chance = 0; + + if (random () < chance) + { + self.attack_state = AS_MISSILE; + return TRUE; + } + + if (enemy_range == RANGE_MID) + { + if (self.attack_state != AS_STRAIGHT) + { + self.attack_state = AS_STRAIGHT; + wiz_run1 (); + } + } + else + { + if (self.attack_state != AS_SLIDING) + { + self.attack_state = AS_SLIDING; + wiz_side1 (); + } + } + + return FALSE; +}; + +/* +================= +WizardAttackFinished +================= +*/ +void() WizardAttackFinished = +{ + if (enemy_range >= RANGE_MID || !enemy_vis) + { + self.attack_state = AS_STRAIGHT; + self.think = wiz_run1; + } + else + { + self.attack_state = AS_SLIDING; + self.think = wiz_side1; + } +}; + +/* +============================================================================== + +FAST ATTACKS + +============================================================================== +*/ + +void() Wiz_FastFire = +{ + local vector vec; + local vector dst; + + if (self.owner.health > 0) + { + self.owner.effects = self.owner.effects | EF_MUZZLEFLASH; + + makevectors (self.enemy.angles); + dst = self.enemy.origin - 13*self.movedir; + + vec = normalize(dst - self.origin); + sound (self, CHAN_WEAPON, "wizard/wattack.wav", 1, ATTN_NORM); + launch_spike (self.origin, vec); + newmis.velocity = vec*600; + newmis.owner = self.owner; + newmis.classname = "wizspike"; + setmodel (newmis, "progs/w_spike.mdl"); + setsize (newmis, VEC_ORIGIN, VEC_ORIGIN); + } + + remove (self); +}; + + +void() Wiz_StartFast = +{ + local entity missile; + + sound (self, CHAN_WEAPON, "wizard/wattack.wav", 1, ATTN_NORM); + self.v_angle = self.angles; + makevectors (self.angles); + + missile = spawn (); + missile.owner = self; + missile.nextthink = time + 0.6; + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, self.origin + '0 0 30' + v_forward*14 + v_right*14); + missile.enemy = self.enemy; + missile.nextthink = time + 0.8; + missile.think = Wiz_FastFire; + missile.movedir = v_right; + + missile = spawn (); + missile.owner = self; + missile.nextthink = time + 1; + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, self.origin + '0 0 30' + v_forward*14 + v_right* -14); + missile.enemy = self.enemy; + missile.nextthink = time + 0.3; + missile.think = Wiz_FastFire; + missile.movedir = VEC_ORIGIN - v_right; +}; + + + +void() Wiz_idlesound = +{ +local float wr; + wr = random() * 5; + + if (self.waitmin < time) + { + self.waitmin = time + 2; + if (wr > 4.5) + sound (self, CHAN_VOICE, "wizard/widle1.wav", 1, ATTN_IDLE); + if (wr < 1.5) + sound (self, CHAN_VOICE, "wizard/widle2.wav", 1, ATTN_IDLE); + } + return; +}; + +void() wiz_stand1 =[ $hover1, wiz_stand2 ] {ai_stand();}; +void() wiz_stand2 =[ $hover2, wiz_stand3 ] {ai_stand();}; +void() wiz_stand3 =[ $hover3, wiz_stand4 ] {ai_stand();}; +void() wiz_stand4 =[ $hover4, wiz_stand5 ] {ai_stand();}; +void() wiz_stand5 =[ $hover5, wiz_stand6 ] {ai_stand();}; +void() wiz_stand6 =[ $hover6, wiz_stand7 ] {ai_stand();}; +void() wiz_stand7 =[ $hover7, wiz_stand8 ] {ai_stand();}; +void() wiz_stand8 =[ $hover8, wiz_stand1 ] {ai_stand();}; + +void() wiz_walk1 =[ $hover1, wiz_walk2 ] {ai_walk(8); +Wiz_idlesound();}; +void() wiz_walk2 =[ $hover2, wiz_walk3 ] {ai_walk(8);}; +void() wiz_walk3 =[ $hover3, wiz_walk4 ] {ai_walk(8);}; +void() wiz_walk4 =[ $hover4, wiz_walk5 ] {ai_walk(8);}; +void() wiz_walk5 =[ $hover5, wiz_walk6 ] {ai_walk(8);}; +void() wiz_walk6 =[ $hover6, wiz_walk7 ] {ai_walk(8);}; +void() wiz_walk7 =[ $hover7, wiz_walk8 ] {ai_walk(8);}; +void() wiz_walk8 =[ $hover8, wiz_walk1 ] {ai_walk(8);}; + +void() wiz_side1 =[ $hover1, wiz_side2 ] {ai_run(8); +Wiz_idlesound();}; +void() wiz_side2 =[ $hover2, wiz_side3 ] {ai_run(8);}; +void() wiz_side3 =[ $hover3, wiz_side4 ] {ai_run(8);}; +void() wiz_side4 =[ $hover4, wiz_side5 ] {ai_run(8);}; +void() wiz_side5 =[ $hover5, wiz_side6 ] {ai_run(8);}; +void() wiz_side6 =[ $hover6, wiz_side7 ] {ai_run(8);}; +void() wiz_side7 =[ $hover7, wiz_side8 ] {ai_run(8);}; +void() wiz_side8 =[ $hover8, wiz_side1 ] {ai_run(8);}; + +void() wiz_run1 =[ $fly1, wiz_run2 ] {ai_run(16); +Wiz_idlesound(); +}; +void() wiz_run2 =[ $fly2, wiz_run3 ] {ai_run(16);}; +void() wiz_run3 =[ $fly3, wiz_run4 ] {ai_run(16);}; +void() wiz_run4 =[ $fly4, wiz_run5 ] {ai_run(16);}; +void() wiz_run5 =[ $fly5, wiz_run6 ] {ai_run(16);}; +void() wiz_run6 =[ $fly6, wiz_run7 ] {ai_run(16);}; +void() wiz_run7 =[ $fly7, wiz_run8 ] {ai_run(16);}; +void() wiz_run8 =[ $fly8, wiz_run9 ] {ai_run(16);}; +void() wiz_run9 =[ $fly9, wiz_run10 ] {ai_run(16);}; +void() wiz_run10 =[ $fly10, wiz_run11 ] {ai_run(16);}; +void() wiz_run11 =[ $fly11, wiz_run12 ] {ai_run(16);}; +void() wiz_run12 =[ $fly12, wiz_run13 ] {ai_run(16);}; +void() wiz_run13 =[ $fly13, wiz_run14 ] {ai_run(16);}; +void() wiz_run14 =[ $fly14, wiz_run1 ] {ai_run(16);}; + +void() wiz_fast1 =[ $magatt1, wiz_fast2 ] {ai_face();Wiz_StartFast();}; +void() wiz_fast2 =[ $magatt2, wiz_fast3 ] {ai_face();}; +void() wiz_fast3 =[ $magatt3, wiz_fast4 ] {ai_face();}; +void() wiz_fast4 =[ $magatt4, wiz_fast5 ] {ai_face();}; +void() wiz_fast5 =[ $magatt5, wiz_fast6 ] {ai_face();}; +void() wiz_fast6 =[ $magatt6, wiz_fast7 ] {ai_face();}; +void() wiz_fast7 =[ $magatt5, wiz_fast8 ] {ai_face();}; +void() wiz_fast8 =[ $magatt4, wiz_fast9 ] {ai_face();}; +void() wiz_fast9 =[ $magatt3, wiz_fast10 ] {ai_face();}; +void() wiz_fast10 =[ $magatt2, wiz_run1 ] {ai_face();SUB_AttackFinished(2);WizardAttackFinished ();}; + +void() wiz_pain1 =[ $pain1, wiz_pain2 ] {}; +void() wiz_pain2 =[ $pain2, wiz_pain3 ] {}; +void() wiz_pain3 =[ $pain3, wiz_pain4 ] {}; +void() wiz_pain4 =[ $pain4, wiz_run1 ] {}; + +void() wiz_death1 =[ $death1, wiz_death2 ] { + +self.velocity_x = -200 + 400*random(); +self.velocity_y = -200 + 400*random(); +self.velocity_z = 100 + 100*random(); +self.flags = self.flags - (self.flags & FL_ONGROUND); +sound (self, CHAN_VOICE, "wizard/wdeath.wav", 1, ATTN_NORM); +}; +void() wiz_death2 =[ $death2, wiz_death3 ] {}; +void() wiz_death3 =[ $death3, wiz_death4 ]{self.solid = SOLID_NOT;}; +void() wiz_death4 =[ $death4, wiz_death5 ] {}; +void() wiz_death5 =[ $death5, wiz_death6 ] {}; +void() wiz_death6 =[ $death6, wiz_death7 ] {}; +void() wiz_death7 =[ $death7, wiz_death8 ] {}; +void() wiz_death8 =[ $death8, wiz_death8 ] {}; + +void() wiz_die = +{ +// check for gib + if (self.health < -40) + { + ThrowCSQCGibs(GIB_WIZARD); + return; + } + + wiz_death1 (); +}; + + +void(entity attacker, float damage) Wiz_Pain = +{ + sound (self, CHAN_VOICE, "wizard/wpain.wav", 1, ATTN_NORM); + if (random()*70 > damage) + return; // didn't flinch + + wiz_pain1 (); +}; + + +void() Wiz_Missile = +{ + wiz_fast1(); +}; + +/*QUAKED monster_wizard (1 0 0) (-16 -16 -24) (16 16 40) Ambush +*/ +void() monster_wizard = +{ + if (deathmatch) + { + remove(self); + return; + } + precache_model ("progs/wizard.mdl"); + precache_model ("progs/h_wizard.mdl"); + precache_model ("progs/w_spike.mdl"); + + precache_sound ("wizard/hit.wav"); // used by c code + precache_sound ("wizard/wattack.wav"); + precache_sound ("wizard/wdeath.wav"); + precache_sound ("wizard/widle1.wav"); + precache_sound ("wizard/widle2.wav"); + precache_sound ("wizard/wpain.wav"); + precache_sound ("wizard/wsight.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/wizard.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 80; + + self.th_stand = wiz_stand1; + self.th_walk = wiz_walk1; + self.th_run = wiz_run1; + self.th_missile = Wiz_Missile; + self.th_pain = Wiz_Pain; + self.th_die = wiz_die; + + flymonster_start (); +}; diff --git a/quakec/csqctest/src/ss/world.qc b/quakec/csqctest/src/ss/world.qc new file mode 100644 index 000000000..efd6b25b5 --- /dev/null +++ b/quakec/csqctest/src/ss/world.qc @@ -0,0 +1,392 @@ +float infokeyworks; +void() InitBodyQue; + +void() main = +{ + dprint ("main function\n"); + +// these are just commands the the prog compiler to copy these files + + precache_file ("progs.dat"); + precache_file ("gfx.wad"); + precache_file ("quake.rc"); + precache_file ("default.cfg"); + + precache_file ("end1.bin"); + precache_file2 ("end2.bin"); + + precache_file ("demo1.dem"); + precache_file ("demo2.dem"); + precache_file ("demo3.dem"); + +// +// these are all of the lumps from the cached.ls files +// + precache_file ("gfx/palette.lmp"); + precache_file ("gfx/colormap.lmp"); + + precache_file2 ("gfx/pop.lmp"); + + precache_file ("gfx/complete.lmp"); + precache_file ("gfx/inter.lmp"); + + precache_file ("gfx/ranking.lmp"); + precache_file ("gfx/vidmodes.lmp"); + precache_file ("gfx/finale.lmp"); + precache_file ("gfx/conback.lmp"); + precache_file ("gfx/qplaque.lmp"); + + precache_file ("gfx/menudot1.lmp"); + precache_file ("gfx/menudot2.lmp"); + precache_file ("gfx/menudot3.lmp"); + precache_file ("gfx/menudot4.lmp"); + precache_file ("gfx/menudot5.lmp"); + precache_file ("gfx/menudot6.lmp"); + + precache_file ("gfx/menuplyr.lmp"); + precache_file ("gfx/bigbox.lmp"); + precache_file ("gfx/dim_modm.lmp"); + precache_file ("gfx/dim_drct.lmp"); + precache_file ("gfx/dim_ipx.lmp"); + precache_file ("gfx/dim_tcp.lmp"); + precache_file ("gfx/dim_mult.lmp"); + precache_file ("gfx/mainmenu.lmp"); + + precache_file ("gfx/box_tl.lmp"); + precache_file ("gfx/box_tm.lmp"); + precache_file ("gfx/box_tr.lmp"); + + precache_file ("gfx/box_ml.lmp"); + precache_file ("gfx/box_mm.lmp"); + precache_file ("gfx/box_mm2.lmp"); + precache_file ("gfx/box_mr.lmp"); + + precache_file ("gfx/box_bl.lmp"); + precache_file ("gfx/box_bm.lmp"); + precache_file ("gfx/box_br.lmp"); + + precache_file ("gfx/sp_menu.lmp"); + precache_file ("gfx/ttl_sgl.lmp"); + precache_file ("gfx/ttl_main.lmp"); + precache_file ("gfx/ttl_cstm.lmp"); + + precache_file ("gfx/mp_menu.lmp"); + + precache_file ("gfx/netmen1.lmp"); + precache_file ("gfx/netmen2.lmp"); + precache_file ("gfx/netmen3.lmp"); + precache_file ("gfx/netmen4.lmp"); + precache_file ("gfx/netmen5.lmp"); + + precache_file ("gfx/sell.lmp"); + + precache_file ("gfx/help0.lmp"); + precache_file ("gfx/help1.lmp"); + precache_file ("gfx/help2.lmp"); + precache_file ("gfx/help3.lmp"); + precache_file ("gfx/help4.lmp"); + precache_file ("gfx/help5.lmp"); + + precache_file ("gfx/pause.lmp"); + precache_file ("gfx/loading.lmp"); + + precache_file ("gfx/p_option.lmp"); + precache_file ("gfx/p_load.lmp"); + precache_file ("gfx/p_save.lmp"); + precache_file ("gfx/p_multi.lmp"); + +// sounds loaded by C code + precache_sound ("misc/menu1.wav"); + precache_sound ("misc/menu2.wav"); + precache_sound ("misc/menu3.wav"); + + precache_sound ("ambience/water1.wav"); + precache_sound ("ambience/wind2.wav"); + +// shareware + precache_file ("maps/start.bsp"); + + precache_file ("maps/e1m1.bsp"); + precache_file ("maps/e1m2.bsp"); + precache_file ("maps/e1m3.bsp"); + precache_file ("maps/e1m4.bsp"); + precache_file ("maps/e1m5.bsp"); + precache_file ("maps/e1m6.bsp"); + precache_file ("maps/e1m7.bsp"); + precache_file ("maps/e1m8.bsp"); + +// registered + precache_file2 ("gfx/pop.lmp"); + + precache_file2 ("maps/e2m1.bsp"); + precache_file2 ("maps/e2m2.bsp"); + precache_file2 ("maps/e2m3.bsp"); + precache_file2 ("maps/e2m4.bsp"); + precache_file2 ("maps/e2m5.bsp"); + precache_file2 ("maps/e2m6.bsp"); + precache_file2 ("maps/e2m7.bsp"); + + precache_file2 ("maps/e3m1.bsp"); + precache_file2 ("maps/e3m2.bsp"); + precache_file2 ("maps/e3m3.bsp"); + precache_file2 ("maps/e3m4.bsp"); + precache_file2 ("maps/e3m5.bsp"); + precache_file2 ("maps/e3m6.bsp"); + precache_file2 ("maps/e3m7.bsp"); + + precache_file2 ("maps/e4m1.bsp"); + precache_file2 ("maps/e4m2.bsp"); + precache_file2 ("maps/e4m3.bsp"); + precache_file2 ("maps/e4m4.bsp"); + precache_file2 ("maps/e4m5.bsp"); + precache_file2 ("maps/e4m6.bsp"); + precache_file2 ("maps/e4m7.bsp"); + precache_file2 ("maps/e4m8.bsp"); + + precache_file2 ("maps/end.bsp"); + + precache_file2 ("maps/dm1.bsp"); + precache_file2 ("maps/dm2.bsp"); + precache_file2 ("maps/dm3.bsp"); + precache_file2 ("maps/dm4.bsp"); + precache_file2 ("maps/dm5.bsp"); + precache_file2 ("maps/dm6.bsp"); +}; + + +entity lastspawn; + +//======================= +/*QUAKED worldspawn (0 0 0) ? +Only used for the world entity. +Set message to the level name. +Set sounds to the cd track to play. + +World Types: +0: medieval +1: metal +2: base +*/ +//======================= +void() worldspawn = +{ + lastspawn = world; + InitBodyQue(); + +// custom map attributes + if (self.model == "maps/e1m8.bsp") + cvar_set ("sv_gravity", "100"); + else + cvar_set ("sv_gravity", "800"); + +// the area based ambient sounds MUST be the first precache_sounds + +// player precaches + W_Precache (); // get weapon precaches + +// sounds used from C physics code + precache_sound ("demon/dland2.wav"); // landing thud + precache_sound ("misc/h2ohit1.wav"); // landing splash + +// setup precaches allways needed + precache_sound ("items/itembk2.wav"); // item respawn sound + precache_sound ("player/plyrjmp8.wav"); // player jump + precache_sound ("player/land.wav"); // player landing + precache_sound ("player/land2.wav"); // player hurt landing + precache_sound ("player/drown1.wav"); // drowning pain + precache_sound ("player/drown2.wav"); // drowning pain + precache_sound ("player/gasp1.wav"); // gasping for air + precache_sound ("player/gasp2.wav"); // taking breath + precache_sound ("player/h2odeath.wav"); // drowning death + + precache_sound ("misc/talk.wav"); // talk + precache_sound ("player/teledth1.wav"); // telefrag + precache_sound ("misc/r_tele1.wav"); // teleport sounds + precache_sound ("misc/r_tele2.wav"); + precache_sound ("misc/r_tele3.wav"); + precache_sound ("misc/r_tele4.wav"); + precache_sound ("misc/r_tele5.wav"); + precache_sound ("weapons/lock4.wav"); // ammo pick up + precache_sound ("weapons/pkup.wav"); // weapon up + precache_sound ("items/armor1.wav"); // armor up + precache_sound ("weapons/lhit.wav"); //lightning + precache_sound ("weapons/lstart.wav"); //lightning start + precache_sound ("items/damage3.wav"); + + precache_sound ("misc/power.wav"); //lightning for boss + +// player gib sounds + precache_sound ("player/gib.wav"); // player gib sound + precache_sound ("player/udeath.wav"); // player gib sound + precache_sound ("player/tornoff2.wav"); // gib sound + +// player pain sounds + + precache_sound ("player/pain1.wav"); + precache_sound ("player/pain2.wav"); + precache_sound ("player/pain3.wav"); + precache_sound ("player/pain4.wav"); + precache_sound ("player/pain5.wav"); + precache_sound ("player/pain6.wav"); + +// player death sounds + precache_sound ("player/death1.wav"); + precache_sound ("player/death2.wav"); + precache_sound ("player/death3.wav"); + precache_sound ("player/death4.wav"); + precache_sound ("player/death5.wav"); + +// ax sounds + precache_sound ("weapons/ax1.wav"); // ax swoosh + precache_sound ("player/axhit1.wav"); // ax hit meat + precache_sound ("player/axhit2.wav"); // ax hit world + + precache_sound ("player/h2ojump.wav"); // player jumping into water + precache_sound ("player/slimbrn2.wav"); // player enter slime + precache_sound ("player/inh2o.wav"); // player enter water + precache_sound ("player/inlava.wav"); // player enter lava + precache_sound ("misc/outwater.wav"); // leaving water sound + + precache_sound ("player/lburn1.wav"); // lava burn + precache_sound ("player/lburn2.wav"); // lava burn + + precache_sound ("misc/water1.wav"); // swimming + precache_sound ("misc/water2.wav"); // swimming + + precache_model ("progs/player.mdl"); + precache_model ("progs/eyes.mdl"); + precache_model ("progs/h_player.mdl"); + precache_model ("progs/gib1.mdl"); + precache_model ("progs/gib2.mdl"); + precache_model ("progs/gib3.mdl"); + + precache_model ("progs/s_bubble.spr"); // drowning bubbles + precache_model ("progs/s_explod.spr"); // sprite explosion + + precache_model ("progs/v_axe.mdl"); + precache_model ("progs/v_shot.mdl"); + precache_model ("progs/v_nail.mdl"); + precache_model ("progs/v_rock.mdl"); + precache_model ("progs/v_shot2.mdl"); + precache_model ("progs/v_nail2.mdl"); + precache_model ("progs/v_rock2.mdl"); + + precache_model ("progs/bolt.mdl"); // for lightning gun + precache_model ("progs/bolt2.mdl"); // for lightning gun + precache_model ("progs/bolt3.mdl"); // for boss shock + precache_model ("progs/lavaball.mdl"); // for testing + + precache_model ("progs/missile.mdl"); + precache_model ("progs/grenade.mdl"); + precache_model ("progs/spike.mdl"); + precache_model ("progs/s_spike.mdl"); + + precache_model ("progs/backpack.mdl"); + + precache_model ("progs/zom_gib.mdl"); + + precache_model ("progs/v_light.mdl"); + + +// +// Setup light animation tables. 'a' is total darkness, 'z' is maxbright. +// + + // 0 normal + lightstyle(0, "m"); + + // 1 FLICKER (first variety) + lightstyle(1, "mmnmmommommnonmmonqnmmo"); + + // 2 SLOW STRONG PULSE + lightstyle(2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba"); + + // 3 CANDLE (first variety) + lightstyle(3, "mmmmmaaaaammmmmaaaaaabcdefgabcdefg"); + + // 4 FAST STROBE + lightstyle(4, "mamamamamama"); + + // 5 GENTLE PULSE 1 + lightstyle(5,"jklmnopqrstuvwxyzyxwvutsrqponmlkj"); + + // 6 FLICKER (second variety) + lightstyle(6, "nmonqnmomnmomomno"); + + // 7 CANDLE (second variety) + lightstyle(7, "mmmaaaabcdefgmmmmaaaammmaamm"); + + // 8 CANDLE (third variety) + lightstyle(8, "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa"); + + // 9 SLOW STROBE (fourth variety) + lightstyle(9, "aaaaaaaazzzzzzzz"); + + // 10 FLUORESCENT FLICKER + lightstyle(10, "mmamammmmammamamaaamammma"); + + // 11 SLOW PULSE NOT FADE TO BLACK + lightstyle(11, "abcdefghijklmnopqrrqponmlkjihgfedcba"); + + // styles 32-62 are assigned by the light program for switchable lights + + // 63 testing + lightstyle(63, "a"); + + infokeyworks = checkextension("QW_ENGINE"); +#ifdef WORKINDP + serverusingcsqc = TRUE; +#else + serverusingcsqc = checkextension("EXT_CSQC"); +#endif +}; + +void() StartFrame = +{ + teamplay = cvar("teamplay"); + skill = cvar("skill"); + framecount = framecount + 1; +}; + + + +float(entity ent) BodyqueCSQC = +{ + return FALSE; +}; + +entity bodyque_head; + +void() InitBodyQue = +{ + bodyque_head = spawn(); + bodyque_head.classname = "bodyque"; + bodyque_head.owner = spawn(); + bodyque_head.owner.classname = "bodyque"; + bodyque_head.owner.owner = spawn(); + bodyque_head.owner.owner.classname = "bodyque"; + bodyque_head.owner.owner.owner = spawn(); + bodyque_head.owner.owner.owner.classname = "bodyque"; + bodyque_head.owner.owner.owner.owner = bodyque_head; +}; + + +// make a body que entry for the given ent so the ent can be +// respawned elsewhere +void(entity ent) CopyToBodyQue = +{ + bodyque_head.angles = ent.angles; + bodyque_head.model = ent.model; + bodyque_head.modelindex = ent.modelindex; + bodyque_head.frame = ent.frame; + bodyque_head.colormap = ent.colormap; + bodyque_head.movetype = ent.movetype; + bodyque_head.velocity = ent.velocity; + bodyque_head.flags = 0; + bodyque_head.SendEntity = BodyqueCSQC; + setorigin (bodyque_head, ent.origin); + setsize (bodyque_head, ent.mins, ent.maxs); + bodyque_head = bodyque_head.owner; +}; + + diff --git a/quakec/csqctest/src/ss/zombie.qc b/quakec/csqctest/src/ss/zombie.qc new file mode 100644 index 000000000..fbe1c37a8 --- /dev/null +++ b/quakec/csqctest/src/ss/zombie.qc @@ -0,0 +1,511 @@ +/* +============================================================================== + +ZOMBIE + +============================================================================== +*/ +$cd id1/models/zombie + +$origin 0 0 24 + +$base base +$skin skin + +$frame stand1 stand2 stand3 stand4 stand5 stand6 stand7 stand8 +$frame stand9 stand10 stand11 stand12 stand13 stand14 stand15 + +$frame walk1 walk2 walk3 walk4 walk5 walk6 walk7 walk8 walk9 walk10 walk11 +$frame walk12 walk13 walk14 walk15 walk16 walk17 walk18 walk19 + +$frame run1 run2 run3 run4 run5 run6 run7 run8 run9 run10 run11 run12 +$frame run13 run14 run15 run16 run17 run18 + +$frame atta1 atta2 atta3 atta4 atta5 atta6 atta7 atta8 atta9 atta10 atta11 +$frame atta12 atta13 + +$frame attb1 attb2 attb3 attb4 attb5 attb6 attb7 attb8 attb9 attb10 attb11 +$frame attb12 attb13 attb14 + +$frame attc1 attc2 attc3 attc4 attc5 attc6 attc7 attc8 attc9 attc10 attc11 +$frame attc12 + +$frame paina1 paina2 paina3 paina4 paina5 paina6 paina7 paina8 paina9 paina10 +$frame paina11 paina12 + +$frame painb1 painb2 painb3 painb4 painb5 painb6 painb7 painb8 painb9 painb10 +$frame painb11 painb12 painb13 painb14 painb15 painb16 painb17 painb18 painb19 +$frame painb20 painb21 painb22 painb23 painb24 painb25 painb26 painb27 painb28 + +$frame painc1 painc2 painc3 painc4 painc5 painc6 painc7 painc8 painc9 painc10 +$frame painc11 painc12 painc13 painc14 painc15 painc16 painc17 painc18 + +$frame paind1 paind2 paind3 paind4 paind5 paind6 paind7 paind8 paind9 paind10 +$frame paind11 paind12 paind13 + +$frame paine1 paine2 paine3 paine4 paine5 paine6 paine7 paine8 paine9 paine10 +$frame paine11 paine12 paine13 paine14 paine15 paine16 paine17 paine18 paine19 +$frame paine20 paine21 paine22 paine23 paine24 paine25 paine26 paine27 paine28 +$frame paine29 paine30 + +$frame cruc_1 cruc_2 cruc_3 cruc_4 cruc_5 cruc_6 + +float SPAWN_CRUCIFIED = 1; + +//============================================================================= + +.float inpain; + +void() zombie_stand1 =[ $stand1, zombie_stand2 ] {ai_stand();}; +void() zombie_stand2 =[ $stand2, zombie_stand3 ] {ai_stand();}; +void() zombie_stand3 =[ $stand3, zombie_stand4 ] {ai_stand();}; +void() zombie_stand4 =[ $stand4, zombie_stand5 ] {ai_stand();}; +void() zombie_stand5 =[ $stand5, zombie_stand6 ] {ai_stand();}; +void() zombie_stand6 =[ $stand6, zombie_stand7 ] {ai_stand();}; +void() zombie_stand7 =[ $stand7, zombie_stand8 ] {ai_stand();}; +void() zombie_stand8 =[ $stand8, zombie_stand9 ] {ai_stand();}; +void() zombie_stand9 =[ $stand9, zombie_stand10 ] {ai_stand();}; +void() zombie_stand10 =[ $stand10, zombie_stand11 ] {ai_stand();}; +void() zombie_stand11 =[ $stand11, zombie_stand12 ] {ai_stand();}; +void() zombie_stand12 =[ $stand12, zombie_stand13 ] {ai_stand();}; +void() zombie_stand13 =[ $stand13, zombie_stand14 ] {ai_stand();}; +void() zombie_stand14 =[ $stand14, zombie_stand15 ] {ai_stand();}; +void() zombie_stand15 =[ $stand15, zombie_stand1 ] {ai_stand();}; + +void() zombie_cruc1 = [ $cruc_1, zombie_cruc2 ] { +if (random() < 0.1) + sound (self, CHAN_VOICE, "zombie/idle_w2.wav", 1, ATTN_STATIC);}; +void() zombie_cruc2 = [ $cruc_2, zombie_cruc3 ] {self.nextthink = time + 0.1 + random()*0.1;}; +void() zombie_cruc3 = [ $cruc_3, zombie_cruc4 ] {self.nextthink = time + 0.1 + random()*0.1;}; +void() zombie_cruc4 = [ $cruc_4, zombie_cruc5 ] {self.nextthink = time + 0.1 + random()*0.1;}; +void() zombie_cruc5 = [ $cruc_5, zombie_cruc6 ] {self.nextthink = time + 0.1 + random()*0.1;}; +void() zombie_cruc6 = [ $cruc_6, zombie_cruc1 ] {self.nextthink = time + 0.1 + random()*0.1;}; + +void() zombie_walk1 =[ $walk1, zombie_walk2 ] {ai_walk(0);}; +void() zombie_walk2 =[ $walk2, zombie_walk3 ] {ai_walk(2);}; +void() zombie_walk3 =[ $walk3, zombie_walk4 ] {ai_walk(3);}; +void() zombie_walk4 =[ $walk4, zombie_walk5 ] {ai_walk(2);}; +void() zombie_walk5 =[ $walk5, zombie_walk6 ] {ai_walk(1);}; +void() zombie_walk6 =[ $walk6, zombie_walk7 ] {ai_walk(0);}; +void() zombie_walk7 =[ $walk7, zombie_walk8 ] {ai_walk(0);}; +void() zombie_walk8 =[ $walk8, zombie_walk9 ] {ai_walk(0);}; +void() zombie_walk9 =[ $walk9, zombie_walk10 ] {ai_walk(0);}; +void() zombie_walk10 =[ $walk10, zombie_walk11 ] {ai_walk(0);}; +void() zombie_walk11 =[ $walk11, zombie_walk12 ] {ai_walk(2);}; +void() zombie_walk12 =[ $walk12, zombie_walk13 ] {ai_walk(2);}; +void() zombie_walk13 =[ $walk13, zombie_walk14 ] {ai_walk(1);}; +void() zombie_walk14 =[ $walk14, zombie_walk15 ] {ai_walk(0);}; +void() zombie_walk15 =[ $walk15, zombie_walk16 ] {ai_walk(0);}; +void() zombie_walk16 =[ $walk16, zombie_walk17 ] {ai_walk(0);}; +void() zombie_walk17 =[ $walk17, zombie_walk18 ] {ai_walk(0);}; +void() zombie_walk18 =[ $walk18, zombie_walk19 ] {ai_walk(0);}; +void() zombie_walk19 =[ $walk19, zombie_walk1 ] { +ai_walk(0); +if (random() < 0.2) + sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_IDLE);}; + +void() zombie_run1 =[ $run1, zombie_run2 ] {ai_run(1);self.inpain = 0;}; +void() zombie_run2 =[ $run2, zombie_run3 ] {ai_run(1);}; +void() zombie_run3 =[ $run3, zombie_run4 ] {ai_run(0);}; +void() zombie_run4 =[ $run4, zombie_run5 ] {ai_run(1);}; +void() zombie_run5 =[ $run5, zombie_run6 ] {ai_run(2);}; +void() zombie_run6 =[ $run6, zombie_run7 ] {ai_run(3);}; +void() zombie_run7 =[ $run7, zombie_run8 ] {ai_run(4);}; +void() zombie_run8 =[ $run8, zombie_run9 ] {ai_run(4);}; +void() zombie_run9 =[ $run9, zombie_run10 ] {ai_run(2);}; +void() zombie_run10 =[ $run10, zombie_run11 ] {ai_run(0);}; +void() zombie_run11 =[ $run11, zombie_run12 ] {ai_run(0);}; +void() zombie_run12 =[ $run12, zombie_run13 ] {ai_run(0);}; +void() zombie_run13 =[ $run13, zombie_run14 ] {ai_run(2);}; +void() zombie_run14 =[ $run14, zombie_run15 ] {ai_run(4);}; +void() zombie_run15 =[ $run15, zombie_run16 ] {ai_run(6);}; +void() zombie_run16 =[ $run16, zombie_run17 ] {ai_run(7);}; +void() zombie_run17 =[ $run17, zombie_run18 ] {ai_run(3);}; +void() zombie_run18 =[ $run18, zombie_run1 ] { +ai_run(8); +if (random() < 0.2) + sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_IDLE); +if (random() > 0.8) + sound (self, CHAN_VOICE, "zombie/z_idle1.wav", 1, ATTN_IDLE); +}; + +/* +============================================================================= + +ATTACKS + +============================================================================= +*/ + +void() ZombieGrenadeTouch = +{ + if (other == self.owner) + return; // don't explode on owner + if (other.takedamage) + { + T_Damage (other, self, self.owner, 10 ); + sound (self, CHAN_WEAPON, "zombie/z_hit.wav", 1, ATTN_NORM); + remove (self); + return; + } + sound (self, CHAN_WEAPON, "zombie/z_miss.wav", 1, ATTN_NORM); // bounce sound + self.velocity = '0 0 0'; + self.avelocity = '0 0 0'; + self.touch = SUB_Remove; +}; + +/* +================ +ZombieFireGrenade +================ +*/ +void(vector st) ZombieFireGrenade = +{ + local entity missile; + local vector org; + + sound (self, CHAN_WEAPON, "zombie/z_shot1.wav", 1, ATTN_NORM); + + missile = spawn (); + missile.owner = self; + missile.movetype = MOVETYPE_BOUNCE; + missile.solid = SOLID_BBOX; + +// calc org + org = self.origin + st_x * v_forward + st_y * v_right + (st_z - 24) * v_up; + +// set missile speed + + makevectors (self.angles); + + missile.velocity = normalize(self.enemy.origin - org); + missile.velocity = missile.velocity * 600; + missile.velocity_z = 200; + + missile.avelocity = '3000 1000 2000'; + + missile.touch = ZombieGrenadeTouch; + +// set missile duration + missile.nextthink = time + 2.5; + missile.think = SUB_Remove; + + setmodel (missile, "progs/zom_gib.mdl"); + setsize (missile, '0 0 0', '0 0 0'); + setorigin (missile, org); +}; + + +void() zombie_atta1 =[ $atta1, zombie_atta2 ] {ai_face();}; +void() zombie_atta2 =[ $atta2, zombie_atta3 ] {ai_face();}; +void() zombie_atta3 =[ $atta3, zombie_atta4 ] {ai_face();}; +void() zombie_atta4 =[ $atta4, zombie_atta5 ] {ai_face();}; +void() zombie_atta5 =[ $atta5, zombie_atta6 ] {ai_face();}; +void() zombie_atta6 =[ $atta6, zombie_atta7 ] {ai_face();}; +void() zombie_atta7 =[ $atta7, zombie_atta8 ] {ai_face();}; +void() zombie_atta8 =[ $atta8, zombie_atta9 ] {ai_face();}; +void() zombie_atta9 =[ $atta9, zombie_atta10 ] {ai_face();}; +void() zombie_atta10 =[ $atta10, zombie_atta11 ] {ai_face();}; +void() zombie_atta11 =[ $atta11, zombie_atta12 ] {ai_face();}; +void() zombie_atta12 =[ $atta12, zombie_atta13 ] {ai_face();}; +void() zombie_atta13 =[ $atta13, zombie_run1 ] {ai_face();ZombieFireGrenade('-10 -22 30');}; + +void() zombie_attb1 =[ $attb1, zombie_attb2 ] {ai_face();}; +void() zombie_attb2 =[ $attb2, zombie_attb3 ] {ai_face();}; +void() zombie_attb3 =[ $attb3, zombie_attb4 ] {ai_face();}; +void() zombie_attb4 =[ $attb4, zombie_attb5 ] {ai_face();}; +void() zombie_attb5 =[ $attb5, zombie_attb6 ] {ai_face();}; +void() zombie_attb6 =[ $attb6, zombie_attb7 ] {ai_face();}; +void() zombie_attb7 =[ $attb7, zombie_attb8 ] {ai_face();}; +void() zombie_attb8 =[ $attb8, zombie_attb9 ] {ai_face();}; +void() zombie_attb9 =[ $attb9, zombie_attb10 ] {ai_face();}; +void() zombie_attb10 =[ $attb10, zombie_attb11 ] {ai_face();}; +void() zombie_attb11 =[ $attb11, zombie_attb12 ] {ai_face();}; +void() zombie_attb12 =[ $attb12, zombie_attb13 ] {ai_face();}; +void() zombie_attb13 =[ $attb13, zombie_attb14 ] {ai_face();}; +void() zombie_attb14 =[ $attb13, zombie_run1 ] {ai_face();ZombieFireGrenade('-10 -24 29');}; + +void() zombie_attc1 =[ $attc1, zombie_attc2 ] {ai_face();}; +void() zombie_attc2 =[ $attc2, zombie_attc3 ] {ai_face();}; +void() zombie_attc3 =[ $attc3, zombie_attc4 ] {ai_face();}; +void() zombie_attc4 =[ $attc4, zombie_attc5 ] {ai_face();}; +void() zombie_attc5 =[ $attc5, zombie_attc6 ] {ai_face();}; +void() zombie_attc6 =[ $attc6, zombie_attc7 ] {ai_face();}; +void() zombie_attc7 =[ $attc7, zombie_attc8 ] {ai_face();}; +void() zombie_attc8 =[ $attc8, zombie_attc9 ] {ai_face();}; +void() zombie_attc9 =[ $attc9, zombie_attc10 ] {ai_face();}; +void() zombie_attc10 =[ $attc10, zombie_attc11 ] {ai_face();}; +void() zombie_attc11 =[ $attc11, zombie_attc12 ] {ai_face();}; +void() zombie_attc12 =[ $attc12, zombie_run1 ] {ai_face();ZombieFireGrenade('-12 -19 29');}; + +void() zombie_missile = +{ + local float r; + + r = random(); + + if (r < 0.3) + zombie_atta1 (); + else if (r < 0.6) + zombie_attb1 (); + else + zombie_attc1 (); +}; + + +/* +============================================================================= + +PAIN + +============================================================================= +*/ + +void() zombie_paina1 =[ $paina1, zombie_paina2 ] {sound (self, CHAN_VOICE, "zombie/z_pain.wav", 1, ATTN_NORM);}; +void() zombie_paina2 =[ $paina2, zombie_paina3 ] {ai_painforward(3);}; +void() zombie_paina3 =[ $paina3, zombie_paina4 ] {ai_painforward(1);}; +void() zombie_paina4 =[ $paina4, zombie_paina5 ] {ai_pain(1);}; +void() zombie_paina5 =[ $paina5, zombie_paina6 ] {ai_pain(3);}; +void() zombie_paina6 =[ $paina6, zombie_paina7 ] {ai_pain(1);}; +void() zombie_paina7 =[ $paina7, zombie_paina8 ] {}; +void() zombie_paina8 =[ $paina8, zombie_paina9 ] {}; +void() zombie_paina9 =[ $paina9, zombie_paina10 ] {}; +void() zombie_paina10 =[ $paina10, zombie_paina11 ] {}; +void() zombie_paina11 =[ $paina11, zombie_paina12 ] {}; +void() zombie_paina12 =[ $paina12, zombie_run1 ] {}; + +void() zombie_painb1 =[ $painb1, zombie_painb2 ] {sound (self, CHAN_VOICE, "zombie/z_pain1.wav", 1, ATTN_NORM);}; +void() zombie_painb2 =[ $painb2, zombie_painb3 ] {ai_pain(2);}; +void() zombie_painb3 =[ $painb3, zombie_painb4 ] {ai_pain(8);}; +void() zombie_painb4 =[ $painb4, zombie_painb5 ] {ai_pain(6);}; +void() zombie_painb5 =[ $painb5, zombie_painb6 ] {ai_pain(2);}; +void() zombie_painb6 =[ $painb6, zombie_painb7 ] {}; +void() zombie_painb7 =[ $painb7, zombie_painb8 ] {}; +void() zombie_painb8 =[ $painb8, zombie_painb9 ] {}; +void() zombie_painb9 =[ $painb9, zombie_painb10 ] {sound (self, CHAN_BODY, "zombie/z_fall.wav", 1, ATTN_NORM);}; +void() zombie_painb10 =[ $painb10, zombie_painb11 ] {}; +void() zombie_painb11 =[ $painb11, zombie_painb12 ] {}; +void() zombie_painb12 =[ $painb12, zombie_painb13 ] {}; +void() zombie_painb13 =[ $painb13, zombie_painb14 ] {}; +void() zombie_painb14 =[ $painb14, zombie_painb15 ] {}; +void() zombie_painb15 =[ $painb15, zombie_painb16 ] {}; +void() zombie_painb16 =[ $painb16, zombie_painb17 ] {}; +void() zombie_painb17 =[ $painb17, zombie_painb18 ] {}; +void() zombie_painb18 =[ $painb18, zombie_painb19 ] {}; +void() zombie_painb19 =[ $painb19, zombie_painb20 ] {}; +void() zombie_painb20 =[ $painb20, zombie_painb21 ] {}; +void() zombie_painb21 =[ $painb21, zombie_painb22 ] {}; +void() zombie_painb22 =[ $painb22, zombie_painb23 ] {}; +void() zombie_painb23 =[ $painb23, zombie_painb24 ] {}; +void() zombie_painb24 =[ $painb24, zombie_painb25 ] {}; +void() zombie_painb25 =[ $painb25, zombie_painb26 ] {ai_painforward(1);}; +void() zombie_painb26 =[ $painb26, zombie_painb27 ] {}; +void() zombie_painb27 =[ $painb27, zombie_painb28 ] {}; +void() zombie_painb28 =[ $painb28, zombie_run1 ] {}; + +void() zombie_painc1 =[ $painc1, zombie_painc2 ] {sound (self, CHAN_VOICE, "zombie/z_pain1.wav", 1, ATTN_NORM);}; +void() zombie_painc2 =[ $painc2, zombie_painc3 ] {}; +void() zombie_painc3 =[ $painc3, zombie_painc4 ] {ai_pain(3);}; +void() zombie_painc4 =[ $painc4, zombie_painc5 ] {ai_pain(1);}; +void() zombie_painc5 =[ $painc5, zombie_painc6 ] {}; +void() zombie_painc6 =[ $painc6, zombie_painc7 ] {}; +void() zombie_painc7 =[ $painc7, zombie_painc8 ] {}; +void() zombie_painc8 =[ $painc8, zombie_painc9 ] {}; +void() zombie_painc9 =[ $painc9, zombie_painc10 ] {}; +void() zombie_painc10 =[ $painc10, zombie_painc11 ] {}; +void() zombie_painc11 =[ $painc11, zombie_painc12 ] {ai_painforward(1);}; +void() zombie_painc12 =[ $painc12, zombie_painc13 ] {ai_painforward(1);}; +void() zombie_painc13 =[ $painc13, zombie_painc14 ] {}; +void() zombie_painc14 =[ $painc14, zombie_painc15 ] {}; +void() zombie_painc15 =[ $painc15, zombie_painc16 ] {}; +void() zombie_painc16 =[ $painc16, zombie_painc17 ] {}; +void() zombie_painc17 =[ $painc17, zombie_painc18 ] {}; +void() zombie_painc18 =[ $painc18, zombie_run1 ] {}; + +void() zombie_paind1 =[ $paind1, zombie_paind2 ] {sound (self, CHAN_VOICE, "zombie/z_pain.wav", 1, ATTN_NORM);}; +void() zombie_paind2 =[ $paind2, zombie_paind3 ] {}; +void() zombie_paind3 =[ $paind3, zombie_paind4 ] {}; +void() zombie_paind4 =[ $paind4, zombie_paind5 ] {}; +void() zombie_paind5 =[ $paind5, zombie_paind6 ] {}; +void() zombie_paind6 =[ $paind6, zombie_paind7 ] {}; +void() zombie_paind7 =[ $paind7, zombie_paind8 ] {}; +void() zombie_paind8 =[ $paind8, zombie_paind9 ] {}; +void() zombie_paind9 =[ $paind9, zombie_paind10 ] {ai_pain(1);}; +void() zombie_paind10 =[ $paind10, zombie_paind11 ] {}; +void() zombie_paind11 =[ $paind11, zombie_paind12 ] {}; +void() zombie_paind12 =[ $paind12, zombie_paind13 ] {}; +void() zombie_paind13 =[ $paind13, zombie_run1 ] {}; + +void() zombie_paine1 =[ $paine1, zombie_paine2 ] { +sound (self, CHAN_VOICE, "zombie/z_pain.wav", 1, ATTN_NORM); +self.health = 60; +}; +void() zombie_paine2 =[ $paine2, zombie_paine3 ] {ai_pain(8);}; +void() zombie_paine3 =[ $paine3, zombie_paine4 ] {ai_pain(5);}; +void() zombie_paine4 =[ $paine4, zombie_paine5 ] {ai_pain(3);}; +void() zombie_paine5 =[ $paine5, zombie_paine6 ] {ai_pain(1);}; +void() zombie_paine6 =[ $paine6, zombie_paine7 ] {ai_pain(2);}; +void() zombie_paine7 =[ $paine7, zombie_paine8 ] {ai_pain(1);}; +void() zombie_paine8 =[ $paine8, zombie_paine9 ] {ai_pain(1);}; +void() zombie_paine9 =[ $paine9, zombie_paine10 ] {ai_pain(2);}; +void() zombie_paine10 =[ $paine10, zombie_paine11 ] { +sound (self, CHAN_BODY, "zombie/z_fall.wav", 1, ATTN_NORM); +self.solid = SOLID_NOT; +}; +void() zombie_paine11 =[ $paine11, zombie_paine12 ] {self.nextthink = self.nextthink + 5;self.health = 60;}; +void() zombie_paine12 =[ $paine12, zombie_paine13 ]{ +// see if ok to stand up +self.health = 60; +sound (self, CHAN_VOICE, "zombie/z_idle.wav", 1, ATTN_IDLE); +self.solid = SOLID_SLIDEBOX; +if (!walkmove (0, 0)) +{ + self.think = zombie_paine11; + self.solid = SOLID_NOT; + return; +} +}; +void() zombie_paine13 =[ $paine13, zombie_paine14 ] {}; +void() zombie_paine14 =[ $paine14, zombie_paine15 ] {}; +void() zombie_paine15 =[ $paine15, zombie_paine16 ] {}; +void() zombie_paine16 =[ $paine16, zombie_paine17 ] {}; +void() zombie_paine17 =[ $paine17, zombie_paine18 ] {}; +void() zombie_paine18 =[ $paine18, zombie_paine19 ] {}; +void() zombie_paine19 =[ $paine19, zombie_paine20 ] {}; +void() zombie_paine20 =[ $paine20, zombie_paine21 ] {}; +void() zombie_paine21 =[ $paine21, zombie_paine22 ] {}; +void() zombie_paine22 =[ $paine22, zombie_paine23 ] {}; +void() zombie_paine23 =[ $paine23, zombie_paine24 ] {}; +void() zombie_paine24 =[ $paine24, zombie_paine25 ] {}; +void() zombie_paine25 =[ $paine25, zombie_paine26 ] {ai_painforward(5);}; +void() zombie_paine26 =[ $paine26, zombie_paine27 ] {ai_painforward(3);}; +void() zombie_paine27 =[ $paine27, zombie_paine28 ] {ai_painforward(1);}; +void() zombie_paine28 =[ $paine28, zombie_paine29 ] {ai_pain(1);}; +void() zombie_paine29 =[ $paine29, zombie_paine30 ] {}; +void() zombie_paine30 =[ $paine30, zombie_run1 ] {}; + +void() zombie_die = +{ + ThrowCSQCGibs(GIB_ZOMBIE); +}; + +/* +================= +zombie_pain + +Zombies can only be killed (gibbed) by doing 60 hit points of damage +in a single frame (rockets, grenades, quad shotgun, quad nailgun). + +A hit of 25 points or more (super shotgun, quad nailgun) will allways put it +down to the ground. + +A hit of from 10 to 40 points in one frame will cause it to go down if it +has been twice in two seconds, otherwise it goes into one of the four +fast pain frames. + +A hit of less than 10 points of damage (winged by a shotgun) will be ignored. + +FIXME: don't use pain_finished because of nightmare hack +================= +*/ +void(entity attacker, float take) zombie_pain = +{ + local float r; + + self.health = 60; // allways reset health + + if (take < 9) + return; // totally ignore + + if (self.inpain == 2) + return; // down on ground, so don't reset any counters + +// go down immediately if a big enough hit + if (take >= 25) + { + self.inpain = 2; + zombie_paine1 (); + return; + } + + if (self.inpain) + { +// if hit again in next gre seconds while not in pain frames, definately drop + self.pain_finished = time + 3; + return; // currently going through an animation, don't change + } + + if (self.pain_finished > time) + { +// hit again, so drop down + self.inpain = 2; + zombie_paine1 (); + return; + } + +// gp into one of the fast pain animations + self.inpain = 1; + + r = random(); + if (r < 0.25) + zombie_paina1 (); + else if (r < 0.5) + zombie_painb1 (); + else if (r < 0.75) + zombie_painc1 (); + else + zombie_paind1 (); +}; + +//============================================================================ + +/*QUAKED monster_zombie (1 0 0) (-16 -16 -24) (16 16 32) Crucified ambush + +If crucified, stick the bounding box 12 pixels back into a wall to look right. +*/ +void() monster_zombie = +{ + if (deathmatch) + { + remove(self); + return; + } + + precache_model ("progs/zombie.mdl"); + precache_model ("progs/h_zombie.mdl"); + precache_model ("progs/zom_gib.mdl"); + + precache_sound ("zombie/z_idle.wav"); + precache_sound ("zombie/z_idle1.wav"); + precache_sound ("zombie/z_shot1.wav"); + precache_sound ("zombie/z_gib.wav"); + precache_sound ("zombie/z_pain.wav"); + precache_sound ("zombie/z_pain1.wav"); + precache_sound ("zombie/z_fall.wav"); + precache_sound ("zombie/z_miss.wav"); + precache_sound ("zombie/z_hit.wav"); + precache_sound ("zombie/idle_w2.wav"); + + self.solid = SOLID_SLIDEBOX; + self.movetype = MOVETYPE_STEP; + + setmodel (self, "progs/zombie.mdl"); + + setsize (self, '-16 -16 -24', '16 16 40'); + self.health = 60; + + self.th_stand = zombie_stand1; + self.th_walk = zombie_walk1; + self.th_run = zombie_run1; + self.th_pain = zombie_pain; + self.th_die = zombie_die; + self.th_missile = zombie_missile; + + if (self.spawnflags & SPAWN_CRUCIFIED) + { + self.movetype = MOVETYPE_NONE; + zombie_cruc1 (); + } + else + walkmonster_start(); +}; diff --git a/quakec/csqctest/src/ssqc.src b/quakec/csqctest/src/ssqc.src new file mode 100644 index 000000000..1e350d8a6 --- /dev/null +++ b/quakec/csqctest/src/ssqc.src @@ -0,0 +1,51 @@ +../progs.dat + +optsssqc.qc +optsall.qc + +ss/defs.qc +ss/builtins.qc +common/combuiltins.qc +common/extensions.qc +common/econstants.qc +common/classes.qc + +common/pmove.qc + +ss/subs.qc +ss/fight.qc +ss/ai.qc +ss/combat.qc +ss/items.qc +ss/weapons.qc +ss/world.qc + +//common/phys.qc +//common/playerphysics.qc +//common/sv_user.qc + +ss/client.qc +ss/player.qc +ss/monsters.qc +ss/doors.qc +ss/buttons.qc +ss/triggers.qc +ss/plats.qc +ss/misc.qc + +ss/ogre.qc +ss/demon.qc +ss/shambler.qc +ss/knight.qc +ss/soldier.qc +ss/wizard.qc +ss/dog.qc +ss/zombie.qc +ss/boss.qc + +ss/tarbaby.qc // registered +ss/hknight.qc // registered +ss/fish.qc // registered +ss/shalrath.qc // registered +ss/enforcer.qc // registered +ss/oldone.qc // registered