INT cd_gen(INT cmd, EQUIPMENT * pequipment) { INT status; switch (cmd) { case CMD_INIT: status = gen_init(pequipment); break; case CMD_START: status = gen_start(pequipment); break; case CMD_STOP: status = gen_stop(pequipment); break; case CMD_EXIT: status = gen_exit(pequipment); break; case CMD_IDLE: status = gen_idle(pequipment); break; default: cm_msg(MERROR, "Generic class driver", "Received unknown command %d", cmd); status = FE_ERR_DRIVER; break; } return status; }
//产生一个随机地图, rate决定地图的渲染率. 地图大小应在mcMap中设定 int gen_map(McMap * mcMap, double rate) { int i, j, retv = 0, count = 0; int prev = 0, trans = 0, next = 0; double sum; pLinkList pList; pQueuePoint pqp; pList = init_queue(); if (pList == NULL) return -1; srandom(time(NULL)); //随机选择一个渲染点 i = random() % (mcMap->row - 2) + 1; j = random() % (mcMap->col - 2) + 1; sum = mcMap->row * mcMap->col + 0.1; while (count / sum < rate) { //保证一定的渲染率 pqp = calloc(1, sizeof (QueuePoint)); if (pqp == NULL) { retv = -1; goto END; } pqp->i = i; pqp->j = j; insert_node(pList, pqp); //加入渲染队列 mcMap->map[i][j].exit |= NODE_QUEUED; while (!is_empty(pList)) { pqp = read_first(pList); //取队列首点 //产生该点的随机出口 gen_exit(mcMap, pqp->i, pqp->j, count / (rate * sum), &prev, &trans, &next); //产生该点的东东, ncp, box, boss... gen_item(mcMap, pqp->i, pqp->j); //加入该点的出口点 if (check_exit_node(pList, mcMap, pqp->i, pqp->j, 0) || check_exit_node(pList, mcMap, pqp->i, pqp->j, 1) || check_exit_node(pList, mcMap, pqp->i, pqp->j, 2) || check_exit_node(pList, mcMap, pqp->i, pqp->j, 3)) { retv = -1; goto END; } delete_node(pList, 0, 1); //从队列中删除该点 if ((++count) / sum > rate) //渲染率达到就跳出 goto END; } //end of while(...) random_select(mcMap, &i, &j); //如果一个点不够渲染率, 则再选择一个 } END: free_queue(pList, 1); //释放队列资源 return retv; }