void lab4_gnalb_driver(int cn, int ret, int lastact) { struct lab4_gnalb_driver_data *dat; struct msg *msg,*next; int co,cc,in; char *str; // get data dat=set_data(cn,DRD_LAB4_GNALB,sizeof(struct lab4_gnalb_driver_data)); if (!dat) return; // oops... // loop through our messages for (msg=ch[cn].msg; msg; msg=next) { next=msg->next; if (msg->type==NT_CREATE) { lab4_gnalb_driver_parse(cn,dat); lab4_gnalb_driver_init(cn,dat); } if (msg->type==NT_GIVE) { co=msg->dat1; if (!(in=ch[cn].citem)) { remove_message(cn,msg); continue; } // ??? i saw something like this at DBs source // destroy everything we get destroy_item(ch[cn].citem); ch[cn].citem=0; } if (msg->type==NT_TEXT) { co=msg->dat3; str=(char *)msg->dat2; tabunga(cn,co,str); if (co==cn) { remove_message(cn,msg); continue; } } if (msg->type==NT_SEEHIT && dat->type==2) { cc=msg->dat1; co=msg->dat2; if (!cc || !co) { remove_message(cn,msg); continue; } // is the victim our friend? then help if (co!=cn && ch[co].group==ch[cn].group) { if (!is_valid_enemy(cn,cc,-1)) { remove_message(cn,msg); continue; } if (char_dist(cn,cc)>10) { remove_message(cn,msg); continue; } fight_driver_add_enemy(cn,cc,1,1); remove_message(cn,msg); continue; } // is the attacker our friend? then help if (cc!=cn && ch[cc].group==ch[cn].group) { if (!is_valid_enemy(cn,co,-1)) { remove_message(cn,msg); continue; } if (char_dist(cn,co)>10) { remove_message(cn,msg); continue; } fight_driver_add_enemy(cn,co,0,1); remove_message(cn,msg); continue; } remove_message(cn,msg); continue; } standard_message_driver(cn,msg,dat->aggressive,dat->helper); remove_message(cn,msg); } // fighting fight_driver_update(cn); if (fight_driver_attack_visible(cn,0)) return; if (fight_driver_follow_invisible(cn)) return; // rest of standard action if (regenerate_driver(cn)) return; if (spell_self_driver(cn)) return; // gnalb guards patroling if (dat->type==1 && dat->path) { fight_driver_set_home(cn,ch[cn].x,ch[cn].y); if (swap_move_driver(cn,gnalb_path[dat->path].x,gnalb_path[dat->path].y,1)) return; if (map_dist(ch[cn].x,ch[cn].y,gnalb_path[dat->path].x,gnalb_path[dat->path].y)<4) { int p; do p=RANDOM(4); while(gnalb_path[dat->path].next[p]==0 || (gnalb_path[dat->path].next[1]!=0 && gnalb_path[dat->path].next[p]==dat->lastpath)); dat->lastpath=dat->path; dat->path=gnalb_path[dat->path].next[p]; } else do_idle(cn,TICKS/2); return; } // crazy gnalb talking if (dat->type==3) { switch (RANDOM(50)) { case 0: whisper(cn,"Me saw right in Fire."); break; case 1: whisper(cn,"Me not crazy. In me house me saw in fire."); break; case 2: whisper(cn,"Me will get it out."); break; case 3: whisper(cn,"Fire hot, but me not crazy."); break; case 4: whisper(cn,"Tell mage me saw in fire, me not crazy."); break; case 10: case 11: case 12: case 13: case 14: if (do_use(cn,DX_RIGHT,0)) return; } if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_RIGHT,ret,lastact)) return; // nothing left to do do_idle(cn,TICKS/2); return; } if (secure_move_driver(cn,ch[cn].tmpx,ch[cn].tmpy,DX_DOWN,ret,lastact)) return; // nothing left to do do_idle(cn,TICKS/2); }
void Engine::main_loop() { setup_curses(); map->update_visibility_from(player->get_pos()); render(); main_loop_done = false; while(!main_loop_done) { switch (state) { case NEUTRAL: if (detect_player_and_mob_turns()) break; if (detect_modal_messages()) break; tick(); break; case PLAYER_TURN: render(); if(handle_keypress(getch())) { state = NEUTRAL; player->turn_taken(); } map->update_visibility_from(player->get_pos()); break; case MOB_TURN: do_ai(); state = NEUTRAL; break; case VIEW_INVENTORY: render(); inventory_panel->render(player->get_inventory()->get_items()); doupdate(); getch(); state = NEUTRAL; break; case WIELD: do_wield(); state = NEUTRAL; player->turn_taken(); break; case USE: do_use(); state = NEUTRAL; player->turn_taken(); break; case FIRE: if (fire_weapon()) { player->turn_taken(); } state = NEUTRAL; break; case MODAL_MSG: render(); this->modal_message_panel->render(fired_cutscenes[0]); fired_cutscenes[0]->fired(); state = NEUTRAL; break; } if (player->is_dead()) { game_over_lost(); } } teardown_curses(); }