SPRMAKE.CPP
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:4k
源码类别:

游戏

开发平台:

Visual C++

  1. #include "ray.h"
  2. #include "globals.h"
  3. #include "rayspr.h"
  4. #include "bspmove.h"
  5. #include "message.h"
  6. #include "blockmap.h"
  7. #include "timer.h"
  8. #include <stddef.h>
  9. pobject Create_Object(long x, long y, long z, angle_type angle,
  10.    short type, pobject owner, ULONG team)
  11. {
  12.       if (type >= Number_Of_OTs) {
  13.          return NULL;
  14.       }
  15.       pobject_node global_node, ss_node;
  16.       pobject cur_object;
  17.       // Create a global node for the object
  18.       global_node=(pobject_node)NewPtr(sizeof(object_node));
  19.       global_node->front=NULL;
  20.       global_node->back=NULL;
  21.       global_node->data=(pobject)NewPtr(sizeof(object));
  22.  
  23.       // Push it into the global node list
  24.       OL_Push_Node(global_node, g_object_list);
  25.       // Initialize given data
  26.       cur_object=global_node->data;
  27.       cur_object->x=x;
  28.       cur_object->y=y;
  29.       cur_object->z=z;
  30.       cur_object->angle=angle;
  31.       cur_object->cur_frame=0;
  32.       cur_object->type=Obj_Type_List+type;
  33.       // Set sector and ssector
  34.       cur_object->cur_ss=Get_Object_SSector(cur_object, bsp_start_node);
  35.       cur_object->cur_sec=Get_Sec_From_SSec(cur_object->cur_ss);
  36.  
  37.       // Save global node pointer in object
  38.       cur_object->global_node=global_node;
  39.       // Setup the sub sector node in object
  40.       cur_object->ss_node=(pobject_node)NewPtr(sizeof(object_node));
  41.       ss_node=cur_object->ss_node;
  42.       ss_node->front=NULL;
  43.       ss_node->back=NULL;
  44.       ss_node->data=cur_object;
  45.       // Push ssector node onto that ssector's list
  46.       OL_Push_Node(ss_node, cur_object->cur_ss->objects);
  47.       cur_object->cur_ss->num_objects++;
  48.       // Setup object for blockmap
  49.       cur_object->block_x=Block_X(cur_object->x);
  50.       cur_object->block_y=Block_Y(cur_object->y);
  51.       cur_object->block_node=(pobject_node)NewPtr(sizeof(object_node));
  52.       cur_object->block_node->front=NULL;
  53.       cur_object->block_node->back=NULL;
  54.       cur_object->block_node->data=cur_object;
  55.       OL_Push_Node(cur_object->block_node, 
  56.          *Get_Block_Obj_List(cur_object->block_x, cur_object->block_y));
  57.       // Clear message queues
  58.       cur_object->send_objects=NULL;
  59.       cur_object->receive_objects=NULL;
  60.  
  61.       // set owner
  62.       cur_object->owner=owner;
  63.       // set team
  64.       cur_object->team=team;
  65.       // initalize stats
  66.       cur_object->stats.current_speed=cur_object->type->stats.base_speed;
  67.       cur_object->stats.current_health=cur_object->type->stats.total_health;
  68.       // Set default extra data, for now
  69.       cur_object->extra_data=NULL;
  70.       (*cur_object->type->Load_Extra)(cur_object, BAD_LOAD_OFFSET);
  71.       if (updating) {
  72.          cur_object->type->Update(cur_object, Get_Update_Num());
  73.       }
  74.       return cur_object;
  75.  
  76. }
  77. void Kill_Object(pobject del_obj)
  78. {
  79.    Send_Auto_Message(del_obj, KILLED_MESSAGE, NULL);
  80.    pobject_node cur_node, next_node;
  81.    cur_node=del_obj->send_objects;
  82.    while (!OL_Empty_Node(cur_node)) {
  83.       next_node=OL_Next_Node(cur_node);
  84.       Release_Object_Messages(del_obj, cur_node->data);
  85.       cur_node=next_node;
  86.    }
  87.    cur_node=del_obj->receive_objects;
  88.    while (!OL_Empty_Node(cur_node)) {
  89.       next_node=OL_Next_Node(cur_node);
  90.       Release_Object_Messages(cur_node->data, del_obj);
  91.       cur_node=next_node;
  92.    }
  93.    // Clear nodes
  94.    OL_Delete_Node(del_obj->ss_node, del_obj->cur_ss->objects);
  95.    del_obj->cur_ss->num_objects--;
  96.    OL_Delete_Node(del_obj->global_node, g_object_list);
  97.    OL_Delete_Node(del_obj->block_node, 
  98.       *Get_Block_Obj_List(del_obj->block_x, del_obj->block_y));
  99.    DelPtr( del_obj->global_node);
  100.    DelPtr( del_obj->ss_node);
  101.    DelPtr( del_obj->block_node);
  102.    // Delete any extra the object might have
  103.    if (del_obj->extra_data!=NULL)
  104.      DelPtr( del_obj->extra_data);
  105.    // and delete the object
  106.    DelPtr( del_obj);
  107. }
  108. void Clear_Objects() {
  109.    pobject cur_obj;
  110.    while (g_object_list!=NULL) {
  111.       cur_obj=g_object_list->data;
  112.       Kill_Object(cur_obj);
  113.    }
  114. }