void* SelfDestructBehaveInit(void* bhdata,STRATEGYBLOCK* sbptr) { SELF_DESTRUCT_BEHAV_BLOCK* sd_bhv; SELF_DESTRUCT_TOOLS_TEMPLATE* sd_tt; GLOBALASSERT(sbptr); GLOBALASSERT(bhdata); sd_bhv=(SELF_DESTRUCT_BEHAV_BLOCK*)AllocateMem(sizeof(SELF_DESTRUCT_BEHAV_BLOCK)); if(!sd_bhv) { memoryInitialisationFailure = 1; return 0; } sd_bhv->bhvr_type=I_BehaviourSelfDestruct; sd_tt=(SELF_DESTRUCT_TOOLS_TEMPLATE*)bhdata; //copy stuff from tools template COPY_NAME(sbptr->SBname, sd_tt->nameID); sd_bhv->timer=sd_tt->timer; sd_bhv->active=FALSE; return (void*)sd_bhv; }
void* DeathVolumeBehaveInit(void* bhdata,STRATEGYBLOCK* sbptr) { DEATH_VOLUME_BEHAV_BLOCK* dv_bhv; DEATH_VOLUME_TOOLS_TEMPLATE* dv_tt; GLOBALASSERT(sbptr); GLOBALASSERT(bhdata); dv_bhv=(DEATH_VOLUME_BEHAV_BLOCK*)AllocateMem(sizeof(DEATH_VOLUME_BEHAV_BLOCK)); if(!dv_bhv) { memoryInitialisationFailure = 1; return 0; } dv_bhv->bhvr_type=I_BehaviourDeathVolume; dv_tt=(DEATH_VOLUME_TOOLS_TEMPLATE*)bhdata; //copy stuff from tools template COPY_NAME(sbptr->SBname, dv_tt->nameID); dv_bhv->volume_min=dv_tt->volume_min; dv_bhv->volume_max=dv_tt->volume_max; dv_bhv->damage_per_second=dv_tt->damage_per_second; dv_bhv->active=dv_tt->active; dv_bhv->collision_required=dv_tt->collision_required; return (void*)dv_bhv; }
void* PowerCableBehaveInit(void* bhdata,STRATEGYBLOCK* sbptr) { POWER_CABLE_BEHAV_BLOCK* pc_bhv; POWER_CABLE_TOOLS_TEMPLATE* pc_tt; GLOBALASSERT(sbptr); GLOBALASSERT(bhdata); pc_bhv=(POWER_CABLE_BEHAV_BLOCK*)AllocateMem(sizeof(POWER_CABLE_BEHAV_BLOCK)); if(!pc_bhv) { memoryInitialisationFailure = 1; return 0; } pc_bhv->bhvr_type=I_BehaviourPowerCable; pc_tt=(POWER_CABLE_TOOLS_TEMPLATE*)bhdata; //copy stuff from tools template COPY_NAME(sbptr->SBname, pc_tt->nameID); pc_bhv->position = pc_tt->position; pc_bhv->max_charge = pc_tt->max_charge; pc_bhv->current_charge = pc_tt->current_charge; pc_bhv->recharge_rate = pc_tt->recharge_rate; pc_bhv->position.vy+=10; //temporarily move cable down in case rounding errors have put cable just outside of module sbptr->containingModule=ModuleFromPosition(&(pc_bhv->position),0); pc_bhv->position.vy-=10; GLOBALASSERT(sbptr->containingModule); return (void*)pc_bhv; }
void* PlacedHierarchyBehaveInit(void* bhdata,STRATEGYBLOCK* sbptr) { PLACED_HIERARCHY_BEHAV_BLOCK* ph_bhv; PLACED_HIERARCHY_TOOLS_TEMPLATE* ph_tt; SECTION *root_section; SECTION_DATA* sound_section_data; GLOBALASSERT(sbptr); GLOBALASSERT(bhdata); ph_bhv=(PLACED_HIERARCHY_BEHAV_BLOCK*)AllocateMem(sizeof(PLACED_HIERARCHY_BEHAV_BLOCK)); if(!ph_bhv) { memoryInitialisationFailure = 1; return ((void *)NULL); } ph_bhv->bhvr_type=I_BehaviourPlacedHierarchy; ph_tt=(PLACED_HIERARCHY_TOOLS_TEMPLATE*)bhdata; sbptr->shapeIndex=0; COPY_NAME(sbptr->SBname, ph_tt->nameID); sbptr->DynPtr->Position = sbptr->DynPtr->PrevPosition = ph_tt->position; sbptr->DynPtr->OrientEuler = ph_tt->orientation; CreateEulerMatrix(&sbptr->DynPtr->OrientEuler, &sbptr->DynPtr->OrientMat); TransposeMatrixCH(&sbptr->DynPtr->OrientMat); ph_bhv->num_sequences=ph_tt->num_sequences; ph_bhv->sequences=ph_tt->sequences; ph_bhv->num_sounds=ph_tt->num_sounds; ph_bhv->sounds=ph_tt->sounds; ph_bhv->num_special_track_points=ph_tt->num_special_track_points; ph_bhv->special_track_points=ph_tt->special_track_points; root_section=GetNamedHierarchyFromLibrary(ph_tt->file_name,ph_tt->hier_name); GLOBALASSERT(root_section); Create_HModel(&ph_bhv->HModelController,root_section); ph_bhv->current_seq=ph_tt->first_sequence; InitHModelSequence(&ph_bhv->HModelController,ph_bhv->current_seq->sequence_no,ph_bhv->current_seq->sub_sequence_no,ph_bhv->current_seq->time); ph_bhv->HModelController.Playing=ph_tt->playing; ph_bhv->HModelController.Looped=ph_bhv->current_seq->loop; //find the hierarchy section that sound should be produced from sound_section_data=GetThisSectionData(ph_bhv->HModelController.section_data,"SoundSource"); if(!sound_section_data) { //if there isn't a SoundSource object , sound can come from the root section sound_section_data=ph_bhv->HModelController.section_data; } ph_bhv->sound_location=&sound_section_data->World_Offset; return ((void*)ph_bhv); }
void Board::edit_cb() { int oldp = pos; Board* nb = new Board(); #define COPY_NAME(a) strcpy(nb->a, a) COPY_NAME(whitename); COPY_NAME(whiterank); COPY_NAME(blackname); COPY_NAME(blackrank); nb->set_size(size); go(0); memcpy(nb->score, score, sizeof(score)); memcpy(nb->root_story.score, score, sizeof(score)); //nb->score = score; /* if (s) { while(s->step()) { nb->add_move(s->x, s->y); go(++pos); } nb->add_move(s->x, s->y); nb->go(32000); }*/ Story* ts = s; if (ts) { while (ts->past) ts = ts->past; ts = ts->step(); while (ts) { nb->add_move(ts->x, ts->y); ts = ts->step(); nb->go(32000); } } go(oldp); }
void SaveStrategy_PlacedHierarchy(STRATEGYBLOCK* sbPtr) { PLACED_HIERARCHY_BEHAV_BLOCK *ph_bhv; SAVE_BLOCK_STRATEGY_HEADER* header; char* buffer; unsigned int size; int i; ph_bhv = (PLACED_HIERARCHY_BEHAV_BLOCK*)sbPtr->SBdataptr; //determine memeory required size = sizeof(SAVE_BLOCK_STRATEGY_HEADER)+(2*sizeof(int))+(sizeof(int)*ph_bhv->num_sounds); header = (SAVE_BLOCK_STRATEGY_HEADER*) GetPointerForSaveBlock(size); buffer = (char*) header; buffer += sizeof(*header); //fill in the header header->type = SaveBlock_Strategy; header->size = size; header->bhvr_type = I_BehaviourPlacedHierarchy; COPY_NAME(header->SBname,sbPtr->SBname); { int sequence_index = ph_bhv->current_seq-ph_bhv->sequences; *(int*)buffer = sequence_index; buffer+=sizeof(int); } *(int*)buffer = ph_bhv->num_sounds; buffer+=sizeof(int); for(i=0;i<ph_bhv->num_sounds;i++) { int playing = ph_bhv->sounds[i].playing; *(int*)buffer = playing; buffer+=sizeof(int); } //save the hierarchy SaveHierarchy(&ph_bhv->HModelController); for(i=0;i<ph_bhv->num_sounds;i++) { Save_SoundState(&ph_bhv->sounds[i].activ_no); } }
void* LiftDoorBehaveInit(void* bhdata, STRATEGYBLOCK* sbptr) { LIFT_DOOR_BEHAV_BLOCK *doorbhv; LIFT_DOOR_TOOLS_TEMPLATE *doortt; MORPHCTRL* morphctrl; MORPHHEADER* morphheader; MORPHFRAME* morphframe; MODULE * my_mod; doorbhv = (LIFT_DOOR_BEHAV_BLOCK*)AllocateMem(sizeof(LIFT_DOOR_BEHAV_BLOCK)); if (!doorbhv) { memoryInitialisationFailure = 1; return ((void *)NULL); } doorbhv->bhvr_type = I_BehaviourLiftDoor; // from loaders doortt = (LIFT_DOOR_TOOLS_TEMPLATE*)bhdata; // Set up a new Morph Control morphctrl = (MORPHCTRL*)AllocateMem(sizeof(MORPHCTRL)); if (!morphctrl) { memoryInitialisationFailure = 1; return ((void *)NULL); } morphheader = (MORPHHEADER*)AllocateMem(sizeof(MORPHHEADER)); if (!morphheader) { memoryInitialisationFailure = 1; return ((void *)NULL); } morphframe = (MORPHFRAME*)AllocateMem(sizeof(MORPHFRAME)); if (!morphframe) { memoryInitialisationFailure = 1; return ((void *)NULL); } morphframe->mf_shape1 = doortt->shape_open; morphframe->mf_shape2 = doortt->shape_closed; morphheader->mph_numframes = 1; morphheader->mph_maxframes = ONE_FIXED; morphheader->mph_frames = morphframe; morphctrl->ObMorphCurrFrame = 0; morphctrl->ObMorphFlags = 0; morphctrl->ObMorphSpeed = 0; morphctrl->ObMorphHeader = morphheader; // Copy the name over COPY_NAME (sbptr->SBname, doortt->nameID); // Setup module ref { MREF mref=doortt->my_module; ConvertModuleNameToPointer (&mref, MainSceneArray[0]->sm_marray); my_mod = mref.mref_ptr; } GLOBALASSERT (my_mod); my_mod->m_sbptr = sbptr; sbptr->SBmoptr = my_mod; sbptr->SBmomptr = my_mod->m_mapptr; sbptr->SBflags.no_displayblock = 1; doorbhv->door_state = doortt->state; doorbhv->PDmctrl = morphctrl; doorbhv->door_closing_speed=doortt->door_closing_speed; doorbhv->door_opening_speed=doortt->door_opening_speed; // all lift doors have a closed starting state except the // one where the lift is - fill in other data sbptr->SBmorphctrl = doorbhv->PDmctrl; if(doorbhv->door_state == I_door_open) { sbptr->SBmorphctrl->ObMorphCurrFrame = 0; OpenDoor(sbptr->SBmorphctrl, DOOR_OPENFASTSPEED); } else { GLOBALASSERT(doorbhv->door_state == I_door_closed); sbptr->SBmorphctrl->ObMorphCurrFrame = 1; CloseDoor(sbptr->SBmorphctrl, DOOR_CLOSEFASTSPEED); } doorbhv->request_state = doorbhv->door_state; // copy data into relevant structures sbptr->SBmorphctrl = doorbhv->PDmctrl; if(sbptr->SBmoptr) { sbptr->SBmoptr->m_flags |= m_flag_open; } if(sbptr->SBmomptr) { sbptr->SBmomptr->MapMorphHeader = sbptr->SBmorphctrl->ObMorphHeader; } doorbhv->SoundHandle=SOUND_NOACTIVEINDEX; return((void*)doorbhv); }
void* LinkSwitchBehaveInit(void* bhdata, STRATEGYBLOCK* sbptr) { LINK_SWITCH_BEHAV_BLOCK *ls_bhv; LINK_SWITCH_TOOLS_TEMPLATE *ls_tt; int i; GLOBALASSERT(sbptr); ls_bhv = (LINK_SWITCH_BEHAV_BLOCK*)AllocateMem(sizeof(LINK_SWITCH_BEHAV_BLOCK)); if(!ls_bhv) { memoryInitialisationFailure = 1; return ((void *)NULL); } ls_bhv->bhvr_type = I_BehaviourLinkSwitch; // from loaders // 1 rest_state - on or off // 2 mode // 3 timer switch - time for reset // 4 security clerance to operate // 5 copy the target name ls_tt = (LINK_SWITCH_TOOLS_TEMPLATE*)bhdata; sbptr->shapeIndex = ls_tt->shape_num; COPY_NAME(sbptr->SBname, ls_tt->nameID); if (ls_tt->mode == I_lswitch_SELFDESTRUCT) { ls_bhv->ls_mode = I_lswitch_timer; ls_bhv->IS_SELF_DESTRUCT = Yes; } else { ls_bhv->ls_mode = ls_tt->mode; ls_bhv->IS_SELF_DESTRUCT = No; } ls_bhv->num_targets=ls_tt->num_targets; if(ls_bhv->num_targets) { ls_bhv->ls_targets = (LINK_SWITCH_TARGET*)AllocateMem(sizeof(LINK_SWITCH_TARGET) * ls_tt->num_targets); if (!ls_bhv->ls_targets) { memoryInitialisationFailure = 1; return ((void *)NULL); } } else { ls_bhv->ls_targets=0; } for (i=0; i<ls_tt->num_targets; i++) { ls_bhv->ls_targets[i]=ls_tt->targets[i]; ls_bhv->ls_targets[i].sbptr = 0; } ls_bhv->time_for_reset = ls_tt->time_for_reset; ls_bhv->security_clerance = ls_tt->security_clearance; ls_bhv->switch_flags=ls_tt->switch_flags; ls_bhv->trigger_volume_min=ls_tt->trigger_volume_min; ls_bhv->trigger_volume_max=ls_tt->trigger_volume_max; ls_bhv->switch_always_on = ls_tt->switch_always_on; ls_bhv->switch_off_message_same=ls_tt->switch_off_message_same; ls_bhv->switch_off_message_none=ls_tt->switch_off_message_none; if(sbptr->DynPtr) //there may be no shape { sbptr->DynPtr->Position = sbptr->DynPtr->PrevPosition = ls_tt->position; sbptr->DynPtr->OrientEuler = ls_tt->orientation; CreateEulerMatrix(&sbptr->DynPtr->OrientEuler, &sbptr->DynPtr->OrientMat); TransposeMatrixCH(&sbptr->DynPtr->OrientMat); } // set up the animation control if(sbptr->shapeIndex!=-1) { int item_num; TXACTRLBLK **pptxactrlblk; int shape_num = ls_tt->shape_num; SHAPEHEADER *shptr = GetShapeData(shape_num); SetupPolygonFlagAccessForShape(shptr); pptxactrlblk = &ls_bhv->ls_tac; for(item_num = 0; item_num < shptr->numitems; item_num ++) { POLYHEADER *poly = (POLYHEADER*)(shptr->items[item_num]); LOCALASSERT(poly); if((Request_PolyFlags((void *)poly)) & iflag_txanim) { TXACTRLBLK *pnew_txactrlblk; int num_seq = 0; pnew_txactrlblk = AllocateMem(sizeof(TXACTRLBLK)); if (pnew_txactrlblk) { pnew_txactrlblk->tac_flags = 0; pnew_txactrlblk->tac_item = item_num; pnew_txactrlblk->tac_sequence = ls_tt->rest_state; pnew_txactrlblk->tac_node = 0; pnew_txactrlblk->tac_txarray = GetTxAnimArrayZ(shape_num, item_num); pnew_txactrlblk->tac_txah_s = GetTxAnimHeaderFromShape(pnew_txactrlblk, shape_num); while(pnew_txactrlblk->tac_txarray[num_seq+1])num_seq++; // Assert does not work at this point so GLOBALASSERT(num_seq==2); /* set the flags in the animation header */ // we only ever have one frame of animation per sequence - // nb this can change talk to richard - one sequence with two frames // or mutliple sequences??? //Now two sequences with an arbitrary number of frames - Richard pnew_txactrlblk->tac_txah.txa_flags |= txa_flag_play; /* change the value held in pptxactrlblk which point to the previous structures "next" pointer*/ *pptxactrlblk = pnew_txactrlblk; pptxactrlblk = &pnew_txactrlblk->tac_next; } else { memoryInitialisationFailure = 1; } } } *pptxactrlblk=0; } else { //no shape - so there won't be any animation ls_bhv->ls_tac=0; } ls_bhv->ls_dtype = linkswitch_no_display; if (ls_bhv->ls_tac) { ls_bhv->ls_dtype = linkswitch_animate_me; } ls_bhv->ls_track=ls_tt->track; if (ls_bhv->ls_track) { ls_bhv->ls_track->sbptr=sbptr; if (ls_bhv->ls_dtype == linkswitch_animate_me) { ls_bhv->ls_dtype = linkswitch_animate_and_move_me; } else { ls_bhv->ls_dtype = linkswitch_move_me; } } // fill in the rest ourselves ls_bhv->request = 0; ls_bhv->state = ls_tt->rest_state; ls_bhv->timer = 0; ls_bhv->system_state = 0; ls_bhv->soundHandle = SOUND_NOACTIVEINDEX; ls_bhv->num_linked_switches=ls_tt->num_linked_switches; if(ls_tt->num_linked_switches) ls_bhv->lswitch_list=(LSWITCH_ITEM*)AllocateMem(sizeof(LSWITCH_ITEM)*ls_bhv->num_linked_switches); else ls_bhv->lswitch_list=0; for (i=0; i<ls_tt->num_linked_switches; i++) { COPY_NAME (ls_bhv->lswitch_list[i].bs_name, ls_tt->switchIDs[i].name); } if(ls_bhv->state) { ls_bhv->timer=ls_bhv->time_for_reset; if(ls_bhv->ls_track) { //set the track to the end position ls_bhv->ls_track->current_section=(ls_bhv->ls_track->num_sections-1); ls_bhv->ls_track->timer=ls_bhv->ls_track->sections[ls_bhv->ls_track->current_section].time_for_section; ls_bhv->ls_track->playing=1; Update_Track_Position(ls_bhv->ls_track); } } ls_bhv->TimeUntilNetSynchAllowed=0; return((void*)ls_bhv); }