/*
   CMSC 427 - Term Project Candidate
   ---------------------------------

   Beth Weinstein - bweinste@wam.umd.edu
   Ben Stewart - stewartb@wam.umd.edu
   Nawfel Tricha - Topaz@endorproductions.com

   Minimal OpenGL project using Microsoft Visual C++.
   This project is a premilinary candidate for the term 
   project required by CMSC 427.

   ABSTRACT:
      In this project, we will develop several fast 
      rendering and collision routines which would 
      require C/C++ speed and accuracy and then 
      implement a VisualJ++ interface.

   MODULE:
      Nawfel Engine module.
*/

#include "Global.h"

static skin_t r_floor_skin;

static edict_t *martian, *ninja, *zumlin, *frame;
edict_t  *ginny, *hatch;
#define NAWFEL_STZ_SHOW_SPECTRUM       1
#define NAWFEL_STZ_SHOW_MARTIAN        2
#define NAWFEL_STZ_SHOW_NINJA          8
#define NAWFEL_STZ_SHOW_ZUMLIN         7

/*
   Initialization of Nawfel engine:
*/
void NawfelInit()
{
   edict_t *temp;
   martian = MartianSpawn();
   ninja = NinjaSpawn();
   zumlin = ZumlinSpawn();
   ginny = GinnySpawn();
   frame = FrameSpawn();
   hatch = HatchSpawn();
   temp = ChairSpawn();
   VectorSet(temp->origin, -30, 0, -55);
   temp = ChairSpawn();
   VectorSet(temp->origin, -10, 0, -55);
   temp = ChairSpawn();
   VectorSet(temp->origin, -20, 0, -65);

   // First stanza takes 20 seconds (just for testing):
   eng.next_stanza = eng.time; 
}


/*
   Stanza change for Nawfel engine:
*/
void NawfelStanza(int stanza)
{
   switch (stanza)
      {
      // Show spectrum:
      case NAWFEL_STZ_SHOW_SPECTRUM:
         cam.target = frame;
         eng.next_stanza = eng.time + (1000 * 15); 
         break;
      // Show ninja:
      case NAWFEL_STZ_SHOW_NINJA:
         cam.target = ninja;
         r_mode |= RENDER_DSP_LIGHT;
         eng.next_stanza = eng.time + (1000 * 15); 
         break;
      // Show martian:
      case NAWFEL_STZ_SHOW_MARTIAN:
         cam.target = martian;
         eng.next_stanza = eng.time + (1000 * 15); 
         break;
      case NAWFEL_STZ_SHOW_ZUMLIN:
         if (!zumlin->next_think)
            zumlin->think(zumlin);
         cam.target = zumlin;
         ginny->state &= ~ENT_ST_VISIBLE;
         eng.next_stanza = eng.time + (1000 * 15); 
         break;
      default:
         r_mode &= ~RENDER_DSP_LIGHT;
		// BS: Take this out for now  
		/*
         cam.target = ninja;
         eng.stanza = 0;
		 */
      break;
      }
}

/*
   Main function, called from RenderFrame every frame:
*/
void NawfelMain(struct winampVisModule *this_mod)
{
   // Rainbow RGB:
   static float r = 666, r_skip = .07f,
                g = 0, g_skip = .03f,
                b = 0, b_skip = .04f;

   // NT: Initialization for static color runs (Rainbow):
   if (r==666)
      {
      r = (float) (rand() & 0xFF / 0xFF);
      g = (float) (rand() & 0xFF / 0xFF);
      b = (float) (rand() & 0xFF / 0xFF);
      }
    r += r_skip; g += g_skip; b += b_skip;
 
    // NT: Check limits for colors: Ping-Pong effect
    if (r > 1 || r < 0)
       r_skip = -r_skip, r += r_skip;
    if (g > 1 || g < 0)
       g_skip = -g_skip, g += g_skip;
    if (b > 1 || b < 0)
       b_skip = -b_skip, b += b_skip;

   // NT: Set rainbow to current edicts:
   VectorSet(cam.RGB_filter, r, g, b);

}

