179 lines
4.5 KiB
C
179 lines
4.5 KiB
C
#include "Centery.h"
|
|
#include "../../server_source/transactions.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int CenteryInit(void* self) {
|
|
entity* ent = self;
|
|
centery* cen = ent->data;
|
|
cen->direction = 0;
|
|
return 0;
|
|
}
|
|
|
|
int CenteryUpdate(int arg, void* self) {
|
|
entity* e = self;
|
|
world* w = e->world;
|
|
centery* cen = e->data;
|
|
vec2 moveTo = e->position;
|
|
int goodMove;
|
|
user_transaction pos_ut;
|
|
memset(&pos_ut, 0, sizeof(pos_ut));
|
|
printf("getting transaction\n");
|
|
|
|
//printf("Has Connection\n");
|
|
//printf("cli sock %d, entity sock ,\n", e->server->socket);
|
|
if(cen->cli->server.game_info.socket > 0) {
|
|
|
|
|
|
if(RecvUserTransaction(&pos_ut, e->server)) {
|
|
printf("Centery NG\n");
|
|
}else {
|
|
|
|
memcpy(&moveTo, pos_ut.userArg,sizeof(vec2));
|
|
printf("size of post_ut %d\n", pos_ut.argsize);
|
|
printf("move to %d,%d\n", moveTo.x,moveTo.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!EntityMove(e, &moveTo)) {
|
|
|
|
// st_move = (user_transaction){
|
|
// .userArg = &mv,
|
|
// .action = PlayerMove,
|
|
// .id = SERVER_T_USER_FLAG,
|
|
// .argsize = sizeof(mv),
|
|
//};
|
|
|
|
|
|
//w->wells[at(mv.x, mv.y, w)].cell = SetCell(6);
|
|
}
|
|
|
|
//do{
|
|
// goodMove = EntityMove(e,(vec2){e->position.x+ 0, e-> position.y + 1});
|
|
// if(goodMove == 1) {
|
|
// switch (cen->direction) {
|
|
// case 0:
|
|
// moveTo = (vec2){e->position.x+ 0, e-> position.y + 1};
|
|
// printf("moveing S\n");
|
|
// break;
|
|
// case 1:
|
|
// moveTo = (vec2){e->position.x+ 1, e-> position.y + 1};
|
|
// printf("moveing SE\n");
|
|
// break;
|
|
// case 2:
|
|
// moveTo = (vec2){e->position.x+ 1, e-> position.y + 0};
|
|
// printf("moveing E\n");
|
|
// break;
|
|
// case 3:
|
|
// moveTo = (vec2){e->position.x+ 1, e-> position.y + -1};
|
|
// printf("moveing NE\n");
|
|
// break;
|
|
// case 4:
|
|
// moveTo = (vec2){e->position.x+ 0, e-> position.y + -1};
|
|
// printf("moveing N\n");
|
|
// break;
|
|
// case 6:
|
|
// moveTo = (vec2){e->position.x+ -1, e->position.y+ -1};
|
|
// printf("moveing NW\n");
|
|
// break;
|
|
// case 7:
|
|
// moveTo = (vec2){e->position.x+ -1, e->position.y + 0};
|
|
// printf("moveing W\n");
|
|
// break;
|
|
// case 8:
|
|
// moveTo = (vec2){e->position.x+ -1, e->position.y + 1};
|
|
// printf("moveing SW\n");
|
|
// break;
|
|
// }
|
|
// goodMove = EntityMove(e,moveTo);
|
|
// if(cen->direction > 8) {
|
|
// cen->direction = 0;
|
|
// }else {
|
|
// cen->direction ++;
|
|
// }
|
|
//
|
|
// }
|
|
//}while(goodMove == 1);
|
|
|
|
|
|
|
|
//printf("name of entity %s\n",e->name);
|
|
return 0;
|
|
}
|
|
|
|
int CenteryFree(void* self) {
|
|
entity* ent = self;
|
|
centery* cen = ent->data;
|
|
free(cen);
|
|
free(ent);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
entity* CreateCentery(int tear, client* cli, world* w) {
|
|
entity* ent = (entity*)malloc(sizeof(entity));
|
|
centery* cen = (centery*)malloc(sizeof(centery));
|
|
|
|
*cen = (centery){
|
|
.weapon = 1,
|
|
.classification = 1,
|
|
.tear = 3,
|
|
.alert = 0,
|
|
.mode = 0,
|
|
|
|
.health = 30,
|
|
.ac = 3,
|
|
.str = 3,
|
|
.wis = 3,
|
|
.dex = 3,
|
|
.cli = cli,
|
|
};
|
|
|
|
*ent = (entity){
|
|
.id = CENTERY_ID,
|
|
.name = "Centery",
|
|
.description = "Your Basic Bad giy",
|
|
.tile = {
|
|
.simble = 'C',
|
|
.background = {0,0,0},
|
|
.forground = {0xff,0x10,0x10},
|
|
},
|
|
.position = (vec2){5,5},
|
|
.data = cen,
|
|
.world = w,
|
|
.callback = {
|
|
.init = CenteryInit,
|
|
.update = CenteryUpdate,
|
|
.free = CenteryFree,
|
|
},
|
|
|
|
.cleanup = 0,
|
|
};
|
|
|
|
return ent;
|
|
}
|
|
|
|
int ServerUpdate(void * ent) {
|
|
//entity* e = (entity*)ent;
|
|
//centery* cen = (centery*)e->userdata;
|
|
|
|
|
|
return 0;
|
|
}
|
|
int ClientUpdate(int action, void * centery) {
|
|
return 0;
|
|
}
|
|
|
|
|
|
int Init(void * ent){
|
|
return 0;
|
|
}
|
|
|
|
int Free(void* ent) {
|
|
return 0;
|
|
}
|