Exemplo n.º 1
0
 /// <summary>
 /// 保存市政路灯扩展信息
 /// </summary>
 /// <param name="ProjectModel">工程模型</param>
 /// <param name="ItemModel">项目模型</param>
 /// <param name="Model">备用,可空</param>
 /// <returns></returns>
 public bool Add(T_Projects ProjectModel, T_Item ItemModel, object Model = null)
 {
     ProjectModel.shrq     = DateTime.Now.ToString("yyyy.MM.dd");
     RoadLampMDL.ProjectID = ProjectModel.ProjectNO;
     RoadLampMDL.ID        = Guid.NewGuid().ToString();
     return(new T_Project_RoadLamp_BLL().Add(ProjectModel, ItemModel, RoadLampMDL));
 }
Exemplo n.º 2
0
 /// <summary>
 /// 保存市政交通扩展信息
 /// </summary>
 /// <param name="ProjectModel">工程模型</param>
 /// <param name="ItemModel">项目模型</param>
 /// <param name="Model">备用,可空</param>
 /// <returns></returns>
 public bool Add(T_Projects ProjectModel, T_Item ItemModel, object Model = null)
 {
     ProjectModel.shrq    = System.DateTime.Now.ToString("yyyy.MM.dd");
     trafficMDL.ProjectID = ProjectModel.ProjectNO;
     trafficMDL.ID        = Guid.NewGuid().ToString();
     return(new T_Traffic_BLL().Add(ProjectModel, ItemModel, trafficMDL, detailList));
 }
Exemplo n.º 3
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            //获取检索名称
            string name = Requests.GetQueryString("name");
            E_Item data = new E_Item();

            data.Page           = new MLMGC.DataEntity.E_Page();
            data.Page.PageIndex = pageIndex;
            data.Page.PageSize  = pageSize;

            data.ItemName = name.Trim();
            txtName.Text  = name;

            DataTable dt = new T_Item().GetList(data);

            rpList.DataSource = dt;
            rpList.DataBind();

            //设置分页样式
            pageList1.PageSize              = pageSize;
            pageList1.CurrentPageIndex      = pageIndex;
            pageList1.RecordCount           = data.Page.TotalCount;
            pageList1.CustomInfoHTML        = string.Format("共有记录 <span class='red_font'>{0}</span> 条", pageList1.RecordCount);
            pageList1.TextAfterPageIndexBox = "&nbsp;页/" + pageList1.PageCount + "&nbsp;";
        }
Exemplo n.º 4
0
        public T_Item Find(String itemID)
        {
            String stmtId = "T_Item.Find";
            T_Item result = MyISqlMap.QueryForObject <T_Item>(stmtId, itemID);

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            MLMGC.COMP.EnumUtil.BindList <ItemStatus>(rbStatus);

            E_Item data = new T_Item().GetModel(new E_Item()
            {
                EnterpriseID = eid
            });

            if (data != null)
            {
                txtItemName.Text    = data.ItemName;
                txtItemIntro.Text   = data.ItemIntro;
                txtSignature.Text   = data.Signature;
                txtContent.Content  = data.ItemContent;
                imgPhoto.ImageUrl   = MLMGC.COMP.Config.GetEnterpriseItemPhotoUrl(data.Photo);
                hdUrl.Value         = MLMGC.COMP.Config.GetEnterpriseItemPhotoUrl(data.Photo);
                txtEstablished.Text = data.Established.ToShortDateString();
                //txtCityID.Text = data.CityID.ToString();
                rbStatus.SelectedValue = ((int)data.Status).ToString();
                region.RegionID        = data.CityID;

                //项目是否使用
                ltOpenFlag.Text     = data.OpenFlag.ToString();
                btnOpenFlag.Visible = data.OpenFlag == ItemOpenFlag.未开通;
            }

            loadMessage();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            //加载项目信息
            E_Item data = new T_Item().GetModel(new E_Item()
            {
                EnterpriseID = eid
            });

            if (data != null)
            {
                ltItemName.Text    = data.ItemName;
                ltItemIntro.Text   = data.ItemIntro;
                ltSignature.Text   = data.Signature;
                ltItemContent.Text = data.ItemContent;
                imgPhoto.ImageUrl  = MLMGC.COMP.Config.GetEnterpriseItemPhotoUrl(data.Photo);
                ltEstablished.Text = data.Established.ToShortDateString();
                //txtCityID.Text = data.CityID.ToString();
                region.RegionID = data.CityID;
            }

            //加载个人信息
            E_Personal pData = new T_Personal().GetModel(new E_Personal()
            {
                PersonalID = PersonalID, UserID = UserID
            });

            if (pData != null)
            {
                txtUserName.Text = pData.RealName;
                txtMobile.Text   = pData.Mobile;
                txtTel.Text      = pData.Tel;
                txtEmail.Text    = pData.Email;
                txtAddress.Text  = pData.Address;

                //判断个人是否已经加入了项目
                if (pData.ItemFlag == EnumItemFlag.已经加入项目)
                {
                    btnApply.Enabled = false;
                }
            }

            //判断个人是否已经申请过了该项目
            if (btnApply.Enabled)//若btnApply不可以用,说明他已经加入了项目,就不用再判断他是否申请过该项目了。
            {
                bool flag = new T_ItemApply().Exists(new E_ItemApply()
                {
                    ItemID = iid, UserID = UserID, ApplyType = EnumApplyType.申请加入
                });
                if (flag)
                {
                    btnApply.Text    = "申请已提交,正在申核。";
                    btnApply.Enabled = false;
                }
            }

            loadMessage();
        }
Exemplo n.º 7
0
 public Item(T_Item item)
 {
     item_name      = item.item_name;
     item_type      = item.item_type;
     item_quality   = item.item_quality;
     bonus          = item.bonus;
     value          = item.value;
     required_level = item.required_level;
 }
Exemplo n.º 8
0
        public override void Generate(T_Item currentItem, String dmID)
        {
            dict = GetActionsAsDictionary(currentItem.Action);

            //This generator modifies move events e.g. keys, so write changes to this one because we'll be
            //iterating over the original.
            Dictionary<T_Move, T_Reveal> newDict = new Dictionary<T_Move,T_Reveal>();


            foreach (T_Move key in dict.Keys)
            {
                T_Move move = key;
                T_Reveal reveal = dict[key];
                
                bool isPirate = (GetOwner(move, reveal) == "Pirate DM");
                bool ambiguity = !(currentItem.Parameters.Threat == T_Threat.Unambiguous); //Vessel's desired perceived ambiguity
                //If it's a merchant and resources are available, always make merchants UNambiguous (so IFF is likely to be on). Per Courtney -Lisa
                if (!isPirate && currentItem.Parameters.PlayerResources == T_ResourceAvailability.Available)
                    ambiguity = false;

                //Is it in a sea lane?  If it is being newly revealed, yes because it's already in an entry region 
                //and entry regions are the ends of sea lanes. Otherwise, check. 
                List<PolygonValue> seaLanes = ddd.GetAllSeaLanes();
                bool locationInSeaLane = false;
                if (reveal != null) locationInSeaLane = true;
                else
                {
                    LocationValue location = GetLocation(move, reveal);
                    foreach (PolygonValue seaLane in seaLanes)
                    {
                        if (Polygon2D.IsPointInside(new Polygon2D(seaLane), new Vec2D(location)))
                            locationInSeaLane = true;
                    }
                }
                bool onInterceptCourse = isPirate;  //all pirates are on intercept course, no merchant can be
                bool hasIFFon = false;
                if (reveal == null) //Object already exists in play
                {
                    String displayName = ddd.GetSeamateObject(move.ID).ObjectName; 
                    if (!displayName.StartsWith("unknown")) hasIFFon = true;
                }


                //Pick row from ambiguity table using existing constraints.
                bool[] selectedRow = PickRowFromAmbiguityTable(onInterceptCourse, hasIFFon, locationInSeaLane, ambiguity);


                reveal = SetIFF(selectedRow[0], isPirate, currentItem.Parameters.Threat, reveal); //alters reveal event
                move.Throttle = GetNewSpeed(selectedRow[1], move);
                move.Location.Item = GetNewDestination(selectedRow[2], onInterceptCourse).ToLocationValue();
                
                //Add modified move and reveal to new dictionary.
                newDict[move] = reveal;
            }
            currentItem.Action = GetActionsFromDictionary(newDict);
        }
Exemplo n.º 9
0
        public void Delete(T_Item obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            String stmtId = "T_Item.Delete";

            MyISqlMap.Delete(stmtId, obj);
        }
Exemplo n.º 10
0
 public ScriptGenerator()
 {
     //Make list of all items
     items = new T_Item[72];
     for (int i = 1; i < 73; i++)
     {
         T_Item item = makeItem(i);
         items.SetValue(item, i - 1);
     }
 }
Exemplo n.º 11
0
        public void Insert(T_Item obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            String stmtId = "T_Item.Insert";

            MyISqlMap.Insert(stmtId, obj);
        }
Exemplo n.º 12
0
 public Item(T_Item item, GameObject _model)
 {
     item_name      = item.item_name;
     item_type      = item.item_type;
     item_quality   = item.item_quality;
     bonus          = item.bonus;
     value          = item.value;
     required_level = item.required_level;
     model          = _model;
 }
Exemplo n.º 13
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            /*
             * EnumUtil.BindList<EnumApply>(rbStatus);
             *
             * int status = Requests.GetQueryInt("status", -1);
             * rbStatus.SelectedValue = status.ToString();
             */

            //根据EnterpriseID获取ItemID
            E_Item item = new T_Item().GetModel(new E_Item()
            {
                EnterpriseID = EnterpriceID
            });

            if (item == null)
            {
                Jscript.ShowMsg("未找到项目", this);
                return;
            }

            string      start = Requests.GetQueryString("start");
            string      end   = Requests.GetQueryString("end");
            E_ItemApply data  = new E_ItemApply();

            data.ApplyType = EnumApplyType.申请退出;
            data.Status    = EnumApply.全部;
            data.ItemID    = item.ItemID;
            data.Page      = new MLMGC.DataEntity.E_Page();

            if (!string.IsNullOrEmpty(start))
            {
                data.Page.StartDate = Convert.ToDateTime(start);
                txtStartDate.Text   = Convert.ToDateTime(start).ToString("yyyy-MM-dd");
            }
            if (!string.IsNullOrEmpty(end))
            {
                data.Page.EndDate = Convert.ToDateTime(end);
                txtEndDate.Text   = Convert.ToDateTime(end).ToString("yyyy-MM-dd");
            }

            data.Page.PageIndex = pageIndex;
            data.Page.PageSize  = pageSize;

            rpList.DataSource = new T_ItemApply().GetList(data);
            rpList.DataBind();

            //设置分页样式
            pageList1.PageSize              = pageSize;
            pageList1.CurrentPageIndex      = pageIndex;
            pageList1.RecordCount           = data.Page.TotalCount;
            pageList1.CustomInfoHTML        = string.Format("共有记录 <span class='red_font'>{0}</span> 条", pageList1.RecordCount);
            pageList1.TextAfterPageIndexBox = "&nbsp;页/" + pageList1.PageCount + "&nbsp;";
        }
Exemplo n.º 14
0
        /// <summary>
        /// Calculates an intercept course for "imminent threat" pirates
        /// </summary>
        /// <param name="currentItem"></param>
        /// <param name="dmID"></param>

        public override void Generate(T_Item currentItem, String dmID)
        {
            if (currentItem.Parameters.ThreatType == T_ThreatType.Nonimminent)
            {
                return;
            }

            Dictionary <T_Move, T_Reveal> dict = GetActionsAsDictionary(currentItem.Action);
            //This dictionary is a copy
            Dictionary <T_Move, T_Reveal> newDict = new Dictionary <T_Move, T_Reveal>(dict);

            //Find that pirate
            T_Move   move   = null;
            T_Reveal reveal = null;

            foreach (T_Move key in dict.Keys)
            {
                if (dict[key] == null)
                {
                    if (ddd.GetSeamateObject(key.ID).Owner == "Pirate DM")
                    {
                        move   = key;
                        reveal = dict[key];
                        newDict.Remove(key);
                        break;
                    }
                }
                else
                {
                    if (dict[key].Owner == "Pirate DM")
                    {
                        move   = key;
                        reveal = dict[key];
                        newDict.Remove(key);
                        break;
                    }
                }
            }
            if (move == null)
            {
                return;
            }



            move = SetToInterceptCourse(move, reveal, newDict);


            //Reset the pirate's move and reveal in dictionary.
            newDict[move] = reveal;

            //Translate dictionary back into action array.
            currentItem.Action = GetActionsFromDictionary(newDict);
        }
Exemplo n.º 15
0
        public void Delete(String cellID)
        {
            if (cellID == null)
            {
                throw new ArgumentNullException("obj");
            }
            String stmtId = "T_Item.Delete";
            T_Item obj    = new T_Item();

            obj.ItemID = cellID;
            MyISqlMap.Delete(stmtId, obj);
        }
Exemplo n.º 16
0
        public bool Update(T_Projects model_Projects, T_Item model_Item, T_Project_Brige model_Brige)
        {
            BLL.T_Projects_BLL proj_bll = new T_Projects_BLL();
            bool flag = proj_bll.Update(model_Projects, model_Item);

            if (flag)
            {
                this.Update(model_Brige);
                return(true);
            }
            return(false);
        }
Exemplo n.º 17
0
        public bool Add(T_Projects model_Projects, T_Item model_Item, T_Project_RoadLamp model_RoadLamp)
        {
            BLL.T_Projects_BLL proj_bll = new T_Projects_BLL();
            bool flag = proj_bll.Add(model_Projects, model_Item);

            if (flag)
            {
                this.Insert(model_RoadLamp);
                return(true);
            }
            return(false);
        }
Exemplo n.º 18
0
 public void BindItem()
 {
     IsPaired = true;
     if (T_Item.TempData != null)
     {
         T_Item.GetTempData();
     }
     if (T_Organization.TempData != null)
     {
         T_Organization.GetTempData();
     }
     //InitSignal();
 }
Exemplo n.º 19
0
        public bool Exists(String projectID)
        {
            String stmtId = "T_Item.Find";
            T_Item result = MyISqlMap.QueryForObject <T_Item>(stmtId, projectID);

            if (result == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Adds an item to the inventory.
 /// </summary>
 /// <param name="item">The item to add to the inventory.</param>
 /// <returns></returns>
 public static bool Add(T_Item item)
 {
     Debug.WriteLine("Adding a " + item.Name + " to the inventory.");
     if (inventory_items < inventory_items_max)
     {
         inventory.Add(item);
         inventory_items++;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Calculates an intercept course for "imminent threat" pirates
        /// </summary>
        /// <param name="currentItem"></param>
        /// <param name="dmID"></param>

        public override void Generate(T_Item currentItem, String dmID)
        {
            if (currentItem.Parameters.ThreatType == T_ThreatType.Nonimminent)
                return;

            Dictionary<T_Move, T_Reveal> dict = GetActionsAsDictionary(currentItem.Action);
            //This dictionary is a copy
            Dictionary<T_Move, T_Reveal> newDict = new Dictionary<T_Move,T_Reveal>(dict);

            //Find that pirate
            T_Move move = null;
            T_Reveal reveal = null;
            foreach (T_Move key in dict.Keys)
            {
                if (dict[key] == null)
                {
                    if (ddd.GetSeamateObject(key.ID).Owner == "Pirate DM")
                    {
                        move = key;
                        reveal = dict[key];
                        newDict.Remove(key);
                        break;
                    }
                }
                else
                {
                    if (dict[key].Owner == "Pirate DM")
                    {
                        move = key;
                        reveal = dict[key];
                        newDict.Remove(key);
                        break;
                    }
                }
            }
            if (move == null) return;



            move = SetToInterceptCourse(move, reveal, newDict);


            //Reset the pirate's move and reveal in dictionary.
            newDict[move] = reveal;

            //Translate dictionary back into action array.
            currentItem.Action = GetActionsFromDictionary(newDict);
        }
Exemplo n.º 22
0
        /// <summary>
        /// 后台管理员删除企业项目
        /// </summary>
        /// <remarks>tianzhenyun 2012-04-26</remarks>
        public void ItemDelete()
        {
            int eid;

            if (!int.TryParse(nv["eid"], out eid))
            {
                HttpContext.Current.Response.Write("0");
                return;
            }
            E_Item data = new E_Item();

            data.EnterpriseID = eid;
            bool flag = new T_Item().Delete(data);

            HttpContext.Current.Response.Write(flag ? "1" : "0");
        }
Exemplo n.º 23
0
        /// <summary>
        /// 点击确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //获取界面数据
            string name        = txtItemName.Text.Trim();
            string intro       = txtItemIntro.Text.Trim();
            string signature   = txtSignature.Text.Trim();
            string content     = txtContent.Content;
            string established = txtEstablished.Text.Trim();

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(content))
            {
                Jscript.ShowMsg("请认真填写以上内容!", this);
                return;
            }

            E_Item data = new E_Item();

            data.EnterpriseID = eid;
            data.ItemName     = name;
            data.ItemIntro    = intro;
            data.Signature    = signature;
            data.ItemContent  = content;
            data.SetStatus    = Convert.ToInt32(rbStatus.SelectedValue);
            data.Photo        = hdUrl.Value.Substring(hdUrl.Value.LastIndexOf("/") + 1);
            if (!string.IsNullOrEmpty(established))
            {
                data.Established = Convert.ToDateTime(txtEstablished.Text.Trim());
            }
            else
            {
                data.Established = DateTime.Now;
            }
            data.CityID = region.RegionID;
            bool flag = new T_Item().Update(data);

            //Jscript.ShowMsg(string.Format("保存{0}",flag?"成功":"失败"), this);
            if (flag)
            {
                //Jscript.ShowMsg("保存成功", this);
                databind();
                Jscript.AlertAndRedirect(this, "修改成功", "ItemList.aspx?page=" + Requests.GetQueryString("page"));
            }
            else
            {
                Jscript.ShowMsg("保存失败", this);
            }
        }
Exemplo n.º 24
0
        public bool Update(T_Projects model_Projects, T_Item model_Item, T_Traffic model_Traffic, IList <T_Traffic_Detail> detailMDL)
        {
            BLL.T_Projects_BLL proj_bll = new T_Projects_BLL();
            bool flag = proj_bll.Update(model_Projects, model_Item);

            if (flag)
            {
                BLL.T_Traffic_Detail_BLL detailBLL = new ERM.BLL.T_Traffic_Detail_BLL();
                for (int i = 0; i < detailMDL.Count; i++)
                {
                    detailBLL.Update(detailMDL[i]);
                }
                this.Update(model_Traffic);
                return(true);
            }
            return(false);
        }
Exemplo n.º 25
0
        /// <summary>
        /// 申核企业项目状态
        /// </summary>
        public void ItemStatus()
        {
            int eid;

            if (!int.TryParse(nv["eid"], out eid))
            {
                HttpContext.Current.Response.Write("0");
                return;
            }
            E_Item data = new E_Item();

            data.EnterpriseID = eid;
            //data.Status = MLMGC.DataEntity.Enterprise.ItemStatus.申核通过;
            bool flag = new T_Item().UpdateStatus(data);

            HttpContext.Current.Response.Write(flag ? "1" : "0");
        }
Exemplo n.º 26
0
        public bool Add(T_Projects model_Projects, T_Item model_Item, T_Traffic model_Traffic, IList <T_Traffic_Detail> detailMDL)
        {
            BLL.T_Projects_BLL proj_bll = new T_Projects_BLL();
            bool flag = proj_bll.Add(model_Projects, model_Item);

            if (flag)
            {
                this.Insert(model_Traffic);
                BLL.T_Traffic_Detail_BLL detailBLL = new ERM.BLL.T_Traffic_Detail_BLL();
                for (int i = 0; i < detailMDL.Count; i++)
                {
                    detailMDL[i].TrafficID = model_Traffic.ID.ToString();
                    detailBLL.Add(detailMDL[i]);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 27
0
        public T_Item makeItem(int id)
        {
            T_Item item = new T_Item();
            item.ID = id.ToString();
            item.Action = new object[0];
            item.Parameters = new Parameters();

            //Treat_type
            if (id < 41)
                item.Parameters.ThreatType = T_ThreatType.Nonimminent;
            else
                item.Parameters.ThreatType = T_ThreatType.Imminent;
            //Threat character
            if (id % 8 == 1 || id % 8 == 3 || id % 8 == 5 || id % 8 == 7)
                item.Parameters.Threat = T_Threat.Unambiguous;
            else
                item.Parameters.Threat = T_Threat.Ambiguous;
            //Crossing
            if (id % 8 < 5)
                item.Parameters.Crossing = false;
            else
                item.Parameters.Crossing = true;
            //GRoupings
            if (id % 8 < 3 || id % 8 == 5 || id % 8 == 6)
                item.Parameters.Groupings = T_Groupings.One;
            else
                item.Parameters.Groupings = T_Groupings.Two;
            //Resources
            if (id < 25 || (id > 40 && id < 57))
                item.Parameters.PlayerResources = T_ResourceAvailability.Available;
            else
                item.Parameters.PlayerResources = T_ResourceAvailability.Unavailable;
            //Partner resources
            if (id % 16 < 9)
                item.Parameters.TeammateResources = T_ResourceAvailability.Unavailable;
            else
                item.Parameters.TeammateResources = T_ResourceAvailability.Available;
            //Difficulty
            item.Parameters.TT_Difficulty = (double)id/72;
            item.Parameters.FF_Difficulty = (double)id / 72;

            return item;
        }
 private void btnSaver_Click(object sender, EventArgs e)
 {
     try
     {
         if (itemNo.Text == "")
         {
             using (DatabaseConnectionDataContext conn = new DatabaseConnectionDataContext())
             {
                 T_Item res = new T_Item();
                 res.itemNo = SerialGenerator.GenerateSerialNumber();
                 res.itemDescription = itemName.Text;
                 res.itemPrice = double.Parse(itemPrice.Text);
                 res.itemQuantityInStock = 0;
                 res.itemRecorderQuantity = int.Parse(itemMaxStock.Text);
                 res.itemRecorderLeadTime = itemTime.Value;
                 conn.T_Item.InsertOnSubmit(res);
                 conn.SubmitChanges();
                 MessageBox.Show(string.Format("信息添加成功!\n耗材编号:{0}\n耗材名称:{1}", res.itemNo, res.itemDescription), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             using (DatabaseConnectionDataContext conn = new DatabaseConnectionDataContext())
             {
                 var res = conn.T_Item.Where(o => o.itemNo == itemNo.Text).FirstOrDefault();
                 res.itemDescription = itemName.Text;
                 res.itemPrice = double.Parse(itemPrice.Text);
                 res.itemRecorderLeadTime = itemTime.Value;
                 conn.SubmitChanges();
                 MessageBox.Show(string.Format("信息修改成功!\n耗材编号:{0}\n耗材名称:{1}", res.itemNo, res.itemDescription), "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch(Exception ee)
     {
         MessageBox.Show(ee.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     finally
     {
         ItemKindManagement_Load(null, null);
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            //判断该人员是否已经加入了项目
            if (EnterpriseID != 0)
            {
                E_Item item = new T_Item().GetModel(new E_Item()
                {
                    EnterpriseID = EnterpriseID
                });
                if (item != null)
                {
                    itemid          = item.ItemID;
                    lblStatus.Text  = string.Format("您已经加入了<a href=\"iteminfo.aspx?eid={0}&iid={1}&backurl={3}\" >[{2}]</a>,不能在申请其它项目了!", EnterpriseID, item.ItemID, item.ItemName, "itemlist.aspx");
                    btnJump.Visible = true;
                }
            }
            else
            {
                lblStatus.Text = "您还未加入项目,请申请项目!";
            }

            string name = Requests.GetQueryString("name");
            E_Item data = new E_Item();

            data.ItemName       = name.Trim();
            txtName.Text        = name;
            data.Page           = new MLMGC.DataEntity.E_Page();
            data.Page.PageIndex = pageIndex;
            data.Page.PageSize  = pageSize;

            DataTable dt = new T_Item().PersonGetList(data);

            rpList.DataSource = dt;
            rpList.DataBind();

            //设置分页样式
            pageList1.PageSize              = pageSize;
            pageList1.CurrentPageIndex      = pageIndex;
            pageList1.RecordCount           = data.Page.TotalCount;
            pageList1.CustomInfoHTML        = string.Format("共有记录 <span class='red_font'>{0}</span> 条", pageList1.RecordCount);
            pageList1.TextAfterPageIndexBox = "&nbsp;页/" + pageList1.PageCount + "&nbsp;";
        }
Exemplo n.º 30
0
        /// <summary>
        /// 点击使用按钮处理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnOpenFlag_Click(object sender, EventArgs e)
        {
            E_Item data = new E_Item();

            data.EnterpriseID = eid;
            data.ItemID       = iid;
            data.OpenFlag     = ItemOpenFlag.已开通;

            bool flag = new T_Item().UpdateOpenFlag(data);

            if (flag)
            {
                Jscript.ShowMsg("开通成功!", this);
                databind();
            }
            else
            {
                Jscript.ShowMsg("开通失败!", this);
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            E_Item data = new T_Item().GetModel(new E_Item()
            {
                EnterpriseID = EnterpriceID
            });

            if (data != null)
            {
                ltItemName.Text    = data.ItemName;
                ltItemIntro.Text   = data.ItemIntro;
                ltSignature.Text   = data.Signature;
                ltItemContent.Text = data.ItemContent;
                imgPhoto.ImageUrl  = MLMGC.COMP.Config.GetEnterpriseItemPhotoUrl(data.Photo);
                ltEstablished.Text = data.Established.ToShortDateString();
                region.RegionID    = data.CityID;
            }

            loadMessage();
        }
Exemplo n.º 32
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        protected void databind()
        {
            //绑定状态
            EnumUtil.BindList <ItemStatus>(rbStatus);

            E_Item data = new T_Item().GetModel(new E_Item()
            {
                EnterpriseID = EnterpriceID
            });

            if (data != null)
            {
                txtItemName.Text       = data.ItemName;
                txtItemIntro.Text      = data.ItemIntro;
                txtSignature.Text      = data.Signature;
                txtItemContent.Content = data.ItemContent;
                imgPhoto.ImageUrl      = MLMGC.COMP.Config.GetEnterpriseItemPhotoUrl(data.Photo);
                hdUrl.Value            = MLMGC.COMP.Config.GetEnterpriseItemPhotoUrl(data.Photo);
                txtEstablished.Text    = data.Established.ToShortDateString();
                //txtCityID.Text = data.CityID.ToString();
                rbStatus.SelectedValue = ((int)data.Status).ToString();
                region.RegionID        = data.CityID;
            }
        }
Exemplo n.º 33
0
        /// <summary>
        /// Calculates an intercept course for all pirates
        /// </summary>
        /// <param name="currentItem"></param>
        /// <param name="dmID"></param>

        public override void Generate(T_Item currentItem, String dmID)
        {

            Dictionary<T_Move, T_Reveal> dict = GetActionsAsDictionary(currentItem.Action);
            //Make new dictionaries; they will be copies containing either merchants or pirates 
            Dictionary<T_Move, T_Reveal> merchantsDict = new Dictionary<T_Move,T_Reveal>();
            Dictionary<T_Move, T_Reveal> piratesDict = new Dictionary<T_Move, T_Reveal>();

            //Copy pirates and merchants into dictionaries
            foreach (T_Move key in dict.Keys)
            {
                if (GetOwner(key, dict[key]) == "Pirate DM") piratesDict.Add(key, dict[key]);
                else merchantsDict.Add(key, dict[key]); 
            }

            if (piratesDict.Keys.Count == 0) return;

            //This dictionary of pirates is the one we'll use to save intercept courses.
            Dictionary<T_Move, T_Reveal> piratesWithInterceptCourse = new Dictionary<T_Move, T_Reveal>();

            //Set each pirate on the shortest intercept course to a newly revealed or existing merchant.
            foreach (T_Move pirateMove in piratesDict.Keys) {
                Vec2D pirateLocation = new Vec2D(GetLocation(pirateMove, piratesDict[pirateMove]));

                //=========Check newly revealed merchants created in this item to find closest ===========================//
                double timeToIntercept = 1000000000000000;
                Vec2D closestInterceptPoint = null;
                T_Move closestNewMerchant = null;

                foreach (T_Move merchantMove in merchantsDict.Keys)
                {
                    double merchantSpeed = merchantMove.Throttle * GetMaxSpeed(merchantMove);
                    Vec2D merchantStart = new Vec2D(GetLocation(merchantMove, merchantsDict[merchantMove]));
                    Vec2D merchantDestination = new Vec2D((LocationValue)merchantMove.Location.Item);
                    Vec2D interceptPoint = GetInterceptPoint(merchantStart, merchantDestination, merchantSpeed, pirateLocation, GetMaxSpeed(pirateMove));
                    double merchantTimeToIntercept = merchantStart.ScalerDistanceTo(interceptPoint) / merchantSpeed;
                    if (merchantTimeToIntercept < timeToIntercept)
                    {
                        closestNewMerchant = merchantMove;
                        closestInterceptPoint = interceptPoint;
                        timeToIntercept = merchantTimeToIntercept;
                    }
                }            

                //============Check merchants already revealed, see if one is closer ========================
                //TODO: make sure any merchants we will move in this round are not being compared
                DDDAdapter.SeamateObject closestRevealedMerchant = null;
             
                foreach (DDDAdapter.SeamateObject vessel in revealedSeaVessels)
                {
                    //Compare all the existing merchants' positions to see if they are closer.

                    //if (vessel.ID == closestNewMerchant.ID) continue;

                    if (vessel.Owner == "Merchant DM")
                    {
                        double merchantSpeed = vessel.Throttle * vessel.MaximumSpeed;
                        Vec2D merchantStart = new Vec2D(vessel.Location);
                        Vec2D merchantDestination = new Vec2D(vessel.DestinationLocation);
                        Vec2D interceptPoint = GetInterceptPoint(merchantStart, merchantDestination, merchantSpeed, pirateLocation, GetMaxSpeed(pirateMove));

                        double merchantTimeToIntercept = merchantStart.ScalerDistanceTo(interceptPoint) / merchantSpeed;
                        if (merchantTimeToIntercept < timeToIntercept)
                        {
                            closestNewMerchant = null;
                            closestRevealedMerchant = vessel;
                            closestInterceptPoint = interceptPoint;
                            timeToIntercept = merchantTimeToIntercept;
                        }
                    }
                    else continue; //ignore pirates or fleet ships
                }


                if (closestInterceptPoint == null)
                {
                    return;
                }
                //Make a new move for the pirate, containing the pirate's intercept course.
                T_Move moveWithInterceptCourse = new T_Move();
                moveWithInterceptCourse.ID = pirateMove.ID;
                moveWithInterceptCourse.Throttle = 1.0;
                moveWithInterceptCourse.Location = new T_Location();
                moveWithInterceptCourse.Location.Item = closestInterceptPoint.ToLocationValue();



                
                //Set the pirate and merchant's "Intent" relating to the intercept in their SimObjects
                if (closestNewMerchant != null)
                {
                    ddd.UpdateObjectAttribute(closestNewMerchant.ID, "Intent", "Being intercepted:" + pirateMove.ID + ":" + timeToIntercept, "AGENT");   //Merchant
                    ddd.UpdateObjectAttribute(pirateMove.ID, "Intent", "Intercepting:" + closestNewMerchant.ID + ":" + timeToIntercept, "AGENT");  //Pirate
                }
                else if (closestRevealedMerchant != null)
                {
                    ddd.UpdateObjectAttribute(closestRevealedMerchant.ID, "Intent", "Being intercepted:" + pirateMove.ID + ":" + timeToIntercept, "AGENT");   //Merchant
                    ddd.UpdateObjectAttribute(pirateMove.ID, "Intent", "Intercepting:" + closestRevealedMerchant.ID + ":" + timeToIntercept, "AGENT");  //Pirate
                }
                else
                    Console.Error.WriteLine("Fix intercept generator");
                 
             
                //Add the pirate's updated move and reveal to pirate dictionary.
                piratesWithInterceptCourse[moveWithInterceptCourse] = piratesDict[pirateMove];

            }

            //Add altered pirates back to merchants, and reset the action array.
            currentItem.Action = GetActionsFromDictionary(merchantsDict.Concat(piratesWithInterceptCourse).ToDictionary(kvp => kvp.Key, kvp => kvp.Value));

        }
Exemplo n.º 34
0
        //Threat generator -- generates or chooses ONE pirate or friendly vessel in DM domain
        //So either creates a RevealEvent or chooses existing vessel for MoveEvent
        public List<DDDAdapter.SeamateObject> GenerateWithTriedItems(T_Item currentItem, String dmID, List<DDDAdapter.SeamateObject> triedVessels)
        {
            //make a copy of the input which we'll modify and return at the end
            List<DDDAdapter.SeamateObject> returnTriedVessels = new List<DDDAdapter.SeamateObject>(triedVessels);

            String owner;
            bool isPirate;

            if (currentItem.Parameters.Threat == T_Threat.None)
            {
                isPirate = false;
                owner = "Merchant DM";
            }
            else
            {
                isPirate = true;
                owner = "Pirate DM";
            }


            PolygonValue domainPV = this.ddd.GetDecisionMakersAreaOfResponsibility(dmID);
            Polygon2D domain = new Polygon2D(domainPV);
            
            List<Object> actions = new List<object>();

            if (shouldAddNewVessel(revealedSeaVessels)) 
            {
                Console.WriteLine("ThreatGenerator: I'm trying to reuse a vessel because there are " + revealedSeaVessels.Count + " in play already and/or probability told me to.");
                List<DDDAdapter.SeamateObject> vessels = new List<DDDAdapter.SeamateObject>();
                //Find all vessels of the appropriate type (pirate or merchant) within the BAMS/Firescout's range.
                foreach (DDDAdapter.SeamateObject vessel in revealedSeaVessels) 
                {
                    if (vessel.Owner == owner && Polygon2D.IsPointInside(domain, new Vec2D(vessel.Location)))
                        vessels.Add(vessel);
                }
                Console.WriteLine("ThreatGenerator: Found " + vessels.Count + " to reuse");
                
                if (vessels.Count > 0)
                {
                    //manage the list of previously tried objects
                    if (triedVessels.Count == vessels.Count) returnTriedVessels = new List<DDDAdapter.SeamateObject>();
                    foreach (DDDAdapter.SeamateObject alreadyTried in returnTriedVessels) vessels.Remove(alreadyTried);

                    Shuffle(vessels);
                    DDDAdapter.SeamateObject vessel = null;
                    //see if any eligible vessels are stopped, if so, use one of them
                    foreach (DDDAdapter.SeamateObject possiblyStoppedVessel in vessels)
                    {
                        if (possiblyStoppedVessel.Throttle == 0) //yes, it is stopped
                        {
                            Console.WriteLine("ThreatGenerator: Picking a stopped vessel " + possiblyStoppedVessel.ID + " to reuse.");
                            vessel = possiblyStoppedVessel;
                            break;
                        }
                    }
                    //we didn't find any stopped vessels, so pick a random eligible one.
                    if (vessel == null)
                        vessel = vessels[random.Next(vessels.Count)];
                    returnTriedVessels.Add(vessel);
                    T_Move move = new T_Move();
                    move.ID = vessel.ID;
                    move.Location = new T_Location();

                    actions.Add(move);

                }
            }

            if (actions.Count() == 0) //we couldn't find a ship or need more vessels
            { //reveal a random new one

                Console.WriteLine("ThreatGenerator: I'm revealing a new vessel, either couldn't find a ship or need more vessels.");
                List<string> unrevealedObjectIDs = ddd.GetAllUnrevealedObjectIds(isPirate,true,null);
               
                T_Reveal reveal = new T_Reveal();
                reveal.ID = unrevealedObjectIDs[random.Next(unrevealedObjectIDs.Count())];
                reveal.Owner = owner;
                reveal.State = "FullyFunctional";
                reveal.Location = new T_Location();
                reveal.StartupParameters = new T_StartupParameters();
                reveal.StartupParameters.Items = new string[0];
            
                T_Move move = new T_Move();
                move.ID = reveal.ID;
                move.Location = new T_Location();
                Vec2D point;
                List<PolygonValue> entryRegions = ddd.GetAllEntryRegions();
                //TODO: Write a safe PointInsideMultipleDomains() function.  This could theoretically loop forever with a terrible scenario
                while (true)
                {
                    point = new Polygon2D(entryRegions[random.Next(entryRegions.Count)]).PointInside();
                    if (Polygon2D.IsPointInside(domain,point)) {
                        break;
                    }
                }
                reveal.Location.Item = point.ToLocationValue();
 
                actions.Add(reveal);
                actions.Add(move);
                Console.WriteLine("ThreatGenerator: Just revealed a pirate " + reveal.ID);
            }


            currentItem.Action = actions.ToArray();
            return returnTriedVessels;
            
        }
Exemplo n.º 35
0
        public bool SpecialGenerate(T_Item currentItem, String dmID)
        {

            Dictionary<T_Move,T_Reveal> dict = GetActionsAsDictionary(currentItem.Action);
            Dictionary<T_Move, T_Reveal> newDict = new Dictionary<T_Move,T_Reveal>();
            
            List<PolygonValue> seaLanes = ddd.GetAllSeaLanes();
            PolygonValue domain = this.ddd.GetDecisionMakersAreaOfResponsibility(dmID);


            foreach (T_Move key in dict.Keys)
            {
                T_Move move = key;
                T_Reveal reveal = dict[key];
                

                //Is this vessel a pirate?
                bool isPirate = false;
                if (reveal!=null) //there's a reveal event
                {
                    if (reveal.Owner == "Pirate DM")
                        isPirate = true;
                } 
                else if (ddd.GetSeamateObject(move.ID).Owner == "Pirate DM")
                    isPirate = true;


                //Vessel's desired perceived ambiguity
                bool ambiguity = true;
                if (currentItem.Parameters.Threat == T_Threat.Unambiguous)
                    ambiguity = false;
                //If it's a merchant and resources aren't unavailable, always make merchants UNambiguous (so IFF is likely to be on)
                if (!isPirate && currentItem.Parameters.PlayerResources == T_ResourceAvailability.Available)
                    ambiguity = false;


                //Is it in a sea lane?  If it is already in play check, Yes if it is being revealed in an entry region
                bool locationInSeaLane = false;
                LocationValue location;
                if (reveal == null) //already in play
                    location = ddd.GetSeamateObject(move.ID).Location;
                else
                    location = (LocationValue)reveal.Location.Item;

                foreach (PolygonValue seaLane in seaLanes)
                {
                    Polygon2D seaLane2D = new Polygon2D(seaLane);
                    if (Polygon2D.IsPointInside(seaLane2D, new Vec2D(location)))
                    {
                        locationInSeaLane = true;
                        break;
                    }
                }

                //Intercept course
               bool onInterceptCourse = false;
               if (currentItem.Parameters.ThreatType == T_ThreatType.Imminent && isPirate)
                    onInterceptCourse = true;

                //IFF
               bool hasIFFon = false;

                //Is its IFF already on?
                if (move == null) //Object already exists in play
                {
                    String displayName = ddd.GetSeamateObject(move.ID).ObjectName; 
                    if (!displayName.StartsWith("unknown")) //Object has IFF set on
                        hasIFFon = true;
                }


                //Pick row from ambiguity table using existing constraints.
                Shuffle(ambiguityTable);
                bool[] selectedRow = null;
                foreach (bool[] row in ambiguityTable)
                {
                    if ((!onInterceptCourse || row[2])          //if onInterceptCourse is true, only allow course to be "on"/true ... if onInterceptCourse is false, either value is OK
                         && (!hasIFFon || row[0])                //same as above for hasIFFon and IFF
                        && (!locationInSeaLane || row[3])       //same as above for inSeaLane and location
                        && ambiguity == row[4])                 // ambiguity must match

                        selectedRow = row;
                }
                if (selectedRow == null)
                {
                    return false;
                    //Console.WriteLine("Impossible scenario");
                    //selectedRow = ambiguityTable[random.Next(ambiguityTable.Length)];
                    //TODO: Wipe out actions, go back to Threat Generator and make a new object
                }
               // Console.WriteLine("AmbiguityGenerator: Making settings for an " + currentItem.Parameters.ThreatType.ToString() + " vessel.  IFF should be on?" + selectedRow[0]);

                //Create scenario described in ambiguity table

                //IFF =================================
                //If we're revealing a new vessel, we can set its IFF on if we need to.  Default is off so we don't 
                // have to do anything.  We can't change existing ships.
                if (reveal != null)
                {
                    if (selectedRow[0] && !isPirate)
                        SetIFF(isPirate, reveal);

                    //If it's a pirate, ignore what it says in the ambiguity table.  
                    //Unambiguous == IFF ON always.  Ambiguous = IFF OFF always
                    if (isPirate && currentItem.Parameters.Threat == T_Threat.Unambiguous)
                        SetIFF(isPirate, reveal);
                    
                }

                //SPEED ===============================   
                double maxSpeed = GetMaxSpeed(move);

                double newSpeed;
                if (selectedRow[1])  //speed 69-84 m/s
                    newSpeed = random.Next(69, Math.Max((int)maxSpeed,84));
                else
                {  //speed <69 or >84 m/s
                    if (maxSpeed > 84)
                        newSpeed = random.Next(84, (int)maxSpeed);
                    else
                        newSpeed = random.Next(20, 68);
                }
                move.Throttle = ((double)newSpeed / (double)maxSpeed);



                //COURSE =================================
                if (selectedRow[2])
                {
                    if (onInterceptCourse) // we will take care of this later
                    {
                        
                    }
                    else //if (locationInSeaLane)
                    {
                        //pick any entry region and send it there.
                        Polygon2D entryRegion2D = new Polygon2D(entryRegions[random.Next(entryRegions.Count)]);
                        Vec2D point = entryRegion2D.PointInside();
                        move.Location = new T_Location();
                        move.Location.Item = point.ToLocationValue();
                    }
                }
                else
                {
                    //just send it anywhere ... probably won't be in a sea lane
                    Vec2D point = new Polygon2D(domain).PointInside(); //TODO: this should be in whole scenario boundaries, not just DM domain
                    move.Location = new T_Location();
                    move.Location.Item = point.ToLocationValue();

                    //TODO:  Send it to the edge of the universe.  Just kidding ... to edge of sea region.
                    ddd.GetDecisionMakersAreaOfResponsibility("BAMS DM");
                    ddd.GetDecisionMakersAreaOfResponsibility("Firescout DM");

                }
                //Add modified move and reveal back to dictionary.
                newDict[move] = reveal;
            }
            currentItem.Action = GetActionsFromDictionary(newDict);
            return true;
        }
Exemplo n.º 36
0
        public override void Generate(T_Item currentItem, String dmID)
        {
            //Identify what's already in actions list.
            foreach (Object action in currentItem.Action)
            {
                if (action as T_Move != null)
                    primaryMove = (T_Move)action;
                if (action as T_Reveal != null)
                    primaryReveal = (T_Reveal)action;
            }
            LocationValue location = GetLocation(primaryMove, primaryReveal);
            bool isPirate = GetOwner(primaryMove, primaryReveal)=="Pirate DM";
            PolygonValue pirateEntryRegion = null;
            if (isPirate)
            {
                foreach (PolygonValue region in entryRegions)
                {
                    if (Polygon2D.IsPointInside(new Polygon2D(region), new Vec2D(location)))
                    {
                        pirateEntryRegion = region;
                        break;
                    }
                }
            }


            List<Object> list = currentItem.Action.ToList();

            List<string> unrevealedObjectIDs = ddd.GetAllUnrevealedObjectIds(false, true, null);
            if (primaryReveal != null)
                unrevealedObjectIDs.Remove(primaryReveal.ID);

           
            int minStimuli = 0;

            //If threat type is imminent, we need to guarantee there will be a merchant for the pirate to attack.
            if (currentItem.Parameters.ThreatType == T_ThreatType.Imminent)
                minStimuli = 1;


            int maxStimuli;
            //If resources need to be available, then two is maximum of stimulus events.
            if (T_ResourceAvailability.Available == currentItem.Parameters.PlayerResources)
                maxStimuli = 2;
            //If resources are unavailable, there must be at least 3 total stimulus events, and max can be higher.
            else
            {
                minStimuli = 3;
                maxStimuli = 5;
            }

            int numStimuliToGenerate = this.changingNumber(minStimuli, 60, minStimuli, maxStimuli); //probably minStimuli but could be up to maxStimuli


            //If our probability criteria says we should add vessels, try and populate reusable objects list 
            List<DDDAdapter.SeamateObject> reuseableObjects = new List<DDDAdapter.SeamateObject>();
            if (shouldAddNewVessel(revealedSeaVessels))
                reuseableObjects = findObjectsInPlay(location, pirateEntryRegion, currentItem.Parameters.Groupings, false);

            for (int i = 0; i < numStimuliToGenerate; i++)
            {

                T_Move move = new T_Move();

                //Try and recycle objects to create stimulus.
                if (reuseableObjects.Count != 0)
                {
                    Shuffle(reuseableObjects);
                    DDDAdapter.SeamateObject objectForReuse = null;
                    //see if any eligible vessels are stopped, if so, use one of them
                    foreach (DDDAdapter.SeamateObject possiblyStoppedVessel in reuseableObjects)
                    {
                        if (possiblyStoppedVessel.Throttle == 0) //yes, it is stopped
                        {
                            //Console.WriteLine("GRoupingGenerator: Picking a stopped vessel " + possiblyStoppedVessel.ID + " to reuse.");
                            objectForReuse = possiblyStoppedVessel;
                            break;
                        }
                    }
                    //randomly pick one of the suitable objects to create a stimulus
                    if (objectForReuse == null)
                        objectForReuse = reuseableObjects[random.Next(reuseableObjects.Count)];

                    move.ID = objectForReuse.ID;
                    reuseableObjects.Remove(objectForReuse);
                    //Console.WriteLine("GroupingGenerator: Moving existing merchant " + objectForReuse.ID);

                }
                else //Reveal and move new merchant.
                {
                    T_Reveal reveal = new T_Reveal();
                    reveal.Owner = "Merchant DM";
                    reveal.State = "FullyFunctional";
                    reveal.StartupParameters = new T_StartupParameters();
                    reveal.StartupParameters.Items = new string[0];
                    reveal.ID = unrevealedObjectIDs[random.Next(unrevealedObjectIDs.Count)]; //pick a random new object
                    unrevealedObjectIDs.Remove(reveal.ID); //take it out of the available list

                    //ADDED 11/10/11:  To make sure that the merchants don't end up in the same entry region as a newly created pirate, 
                    //if there's a new pirate, instead of iterating over all entry regions we'll remove the pirate's region from the list first.
                    if (pirateEntryRegion != null)
                        entryRegions.Remove(pirateEntryRegion);

                    Vec2D point = null;

                    //If two grouping, pick points in entry regions until one is > 100 away
                    if (currentItem.Parameters.Groupings == T_Groupings.Two)
                    {
                        while (true)
                        {
                            point = new Polygon2D(entryRegions[random.Next(entryRegions.Count)]).PointInside();
                            if (point.ScalerDistanceTo(new Vec2D(location)) > twoGroupingDistance)
                            {
                                break;
                            }
                        }
                    }
                    //If one grouping, see if any entry region is within 50km.  If so, pick a point in that entry region.  
                    //It's possible that no entry region may be within 50km.  In that case, pick a point in the closest one.

                    if (currentItem.Parameters.Groupings == T_Groupings.One)
                    {
                        double closestDistance = 100000000;
                        PolygonValue closestRegion = null;
                        Shuffle(entryRegions);

                        foreach (PolygonValue entryRegion in entryRegions)
                        {
                            Polygon2D entry2D = new Polygon2D(entryRegion);
                            double distance = Polygon2D.ScalarDistanceToPolygon(entry2D, new Vec2D(location));

                            if (distance < oneGroupingDistance)
                            {
                                point = entry2D.PointInside();
                                break;
                            }
                            else
                            {
                                if (distance < closestDistance)
                                {
                                    closestDistance = distance;
                                    closestRegion = entryRegion;
                                }
                            }
                        }
                        if (point == null)
                        {
                            //Console.WriteLine("GroupingGenerator: Unable to place vessel in an entry region AND <100km away.  Placing in closest entry region " + closestDistance + " away.");
                            point = new Polygon2D(closestRegion).PointInside();
                        }
                    }
                    reveal.Location = new T_Location();
                    reveal.Location.Item = point.ToLocationValue();
                    list.Add(reveal);

                    move.ID = reveal.ID;
                    //Console.WriteLine("GroupingGenerator: Revealing new merchant " + reveal.ID + " and moving it");
                }

                move.Location = new T_Location();
                list.Add(move);
            }               

            currentItem.Action = list.ToArray();
        }
Exemplo n.º 37
0
        //Pirate generator -- generates or chooses several pirates or friendly vessels in DM domain 
        //So either creates a RevealEvent or chooses existing vessel for MoveEvent
        
        public override void Generate(T_Item currentItem, String dmID)
        {
            if (currentItem.Parameters.Threat == T_Threat.None) return;


            actions = currentItem.Action.ToList();

            // Do some setup
            bool isPirate = !(currentItem.Parameters.Threat == T_Threat.None);
            if (isPirate) owner = "Pirate DM";
            else owner = "Merchant DM";

            PolygonValue domainPV = this.ddd.GetDecisionMakersAreaOfResponsibility(dmID);
            domain = new Polygon2D(domainPV);
            List<string> unrevealedObjectIDs = ddd.GetAllUnrevealedObjectIds(isPirate, true, null);


            //How many pirates should we generate?  These numbers may need tweaking
            int minPirates = Properties.Settings.Default.minPirates;
            int maxPirates = Properties.Settings.Default.maxPirates;
            int numPirates = random.Next(minPirates, maxPirates);


            //Are there any pirates we can reuse, already in play?
            List<DDDAdapter.SeamateObject> reusableVessels = revealedSeaVessels.FindAll(IsReusable);

            if (reusableVessels.Count > 0 && Properties.Settings.Default.reusePirates)
            {
                for (int i = 0; i < numPirates; i++)
                {
                    if (reusableVessels.Count > 0)
                    {
                        DDDAdapter.SeamateObject vessel = reusableVessels[0];
                        reusableVessels.Remove(vessel);
                        CreateEmptyMove(vessel);
                    }
                    else
                    {
                        Vec2D location = MakeLocationInEntryRegions(entryRegions);
                        string id = unrevealedObjectIDs[random.Next(unrevealedObjectIDs.Count())];
                        unrevealedObjectIDs.Remove(id);
                        CreateRevealAndEmptyMove(id, owner, location);
                    }
                }


                ////See if any existing pirates can be paired under "grouping" distance constraints
                //List<List<DDDAdapter.SeamateObject>> groupedPirates = GroupVessels(currentItem.Parameters.Groupings, numPirates, reusableVessels);
                //List<List<DDDAdapter.SeamateObject>> groupsOfNumPirateSize = groupedPirates.FindAll(delegate(List<DDDAdapter.SeamateObject> g) { return g.Count >= numPirates; });

                ////Any groups of numPirates?
                //if (groupsOfNumPirateSize.Count > 0)
                //{
                //    //if yes, make dummy move events for them and add to actions list.  done.
                //    foreach (DDDAdapter.SeamateObject pirate in groupsOfNumPirateSize.ElementAt(0))
                //        CreateEmptyMove(pirate);
                //}
                //else
                //{
                //    //Can any of these smaller groupings include an entry region too, so we can add new pirates? 
                //    groupedPirates.Sort(delegate(List<DDDAdapter.SeamateObject> g1, List<DDDAdapter.SeamateObject> g2) { return g1.Count.CompareTo(g2.Count); }); //sort by size, largest first
                //    foreach (List<DDDAdapter.SeamateObject> group in groupedPirates)
                //    {
                //        List<PolygonValue> matchingEntryRegions = GetMatchingEntryRegions(currentItem.Parameters.Groupings, group, entryRegions);
                //        if (matchingEntryRegions.Count > 0)
                //        {
                //            //if yes, then make dummy move events for the pirates in grouping, then
                //            foreach (DDDAdapter.SeamateObject pirate in groupsOfNumPirateSize.ElementAt(0))
                //                CreateEmptyMove(pirate);
                //            //Create as many remaining pirates as we need distributed randomly among suitable entry regions.
                //            List<Vec2D> locations = MakeLocationsInEntryRegions(numPirates - group.Count, matchingEntryRegions);
                //            foreach (Vec2D location in locations)
                //            {
                //                string id = unrevealedObjectIDs[random.Next(unrevealedObjectIDs.Count())];
                //                unrevealedObjectIDs.Remove(id);
                //                CreateRevealAndEmptyMove(id, owner, location);
                //            }
                //            break;
                //        }
                //    }

                //    //if no, we couldn't include an entry region (where new pirates would be created) with any existing pirates
                //    if (actions.Count == 0)
                //        //TODO: maybe should make smaller num of pirates if above min rather than making all new?
                //        MakeAllNewPirates(currentItem.Parameters.Groupings,numPirates,entryRegions,unrevealedObjectIDs);
                //}
            }
            //no reusable vessels, we have to create all new pirates 
            else
            {
                MakeAllNewPirates(currentItem.Parameters.Groupings,numPirates,entryRegions,unrevealedObjectIDs);
            }

            currentItem.Action = actions.ToArray();

        }
Exemplo n.º 38
0
        public T_Item makeItem(int id)
        {
            T_Item item = new T_Item();

            item.ID         = id.ToString();
            item.Action     = new object[0];
            item.Parameters = new Parameters();

            //Treat_type
            if (id < 41)
            {
                item.Parameters.ThreatType = T_ThreatType.Nonimminent;
            }
            else
            {
                item.Parameters.ThreatType = T_ThreatType.Imminent;
            }
            //Threat character
            if (id % 8 == 1 || id % 8 == 3 || id % 8 == 5 || id % 8 == 7)
            {
                item.Parameters.Threat = T_Threat.Unambiguous;
            }
            else
            {
                item.Parameters.Threat = T_Threat.Ambiguous;
            }
            //Crossing
            if (id % 8 < 5)
            {
                item.Parameters.Crossing = false;
            }
            else
            {
                item.Parameters.Crossing = true;
            }
            //GRoupings
            if (id % 8 < 3 || id % 8 == 5 || id % 8 == 6)
            {
                item.Parameters.Groupings = T_Groupings.One;
            }
            else
            {
                item.Parameters.Groupings = T_Groupings.Two;
            }
            //Resources
            if (id < 25 || (id > 40 && id < 57))
            {
                item.Parameters.PlayerResources = T_ResourceAvailability.Available;
            }
            else
            {
                item.Parameters.PlayerResources = T_ResourceAvailability.Unavailable;
            }
            //Partner resources
            if (id % 16 < 9)
            {
                item.Parameters.TeammateResources = T_ResourceAvailability.Unavailable;
            }
            else
            {
                item.Parameters.TeammateResources = T_ResourceAvailability.Available;
            }
            //Difficulty
            item.Parameters.TT_Difficulty = (double)id / 72;
            item.Parameters.FF_Difficulty = (double)id / 72;

            return(item);
        }
Exemplo n.º 39
0
        public override void Generate(T_Item currentItem, String dmID)
        {
            actions = currentItem.Action.ToList();
            dict = GetActionsAsDictionary(currentItem.Action);
            grouping = currentItem.Parameters.Groupings;


            List<string> unrevealedMerchantIDs = ddd.GetAllUnrevealedObjectIds(false, true, null); //Gets only merchants

           
            int minStimuli = 1;
            int maxStimuli;
            //If resources need to be available, then two is maximum of stimulus events.
            if (T_ResourceAvailability.Available == currentItem.Parameters.PlayerResources)
                maxStimuli = Properties.Settings.Default.resourceThreshold-1;
            //If resources are unavailable, there must be at least 3 total stimulus events, and max can be higher.
            else
            {
                minStimuli = Properties.Settings.Default.resourceThreshold;
                maxStimuli = Properties.Settings.Default.resourceThreshold*2-1;
            }

            int numPirates = dict.Keys.Count;
            int numMerchants = Math.Max(0, random.Next(minStimuli, maxStimuli) - numPirates);
            if (numMerchants == 0)
                return;


            //If our probability criteria says we should add vessels, let's see if we can reuse any existing vessels 
            List<DDDAdapter.SeamateObject> reuseableVessels = new List<DDDAdapter.SeamateObject>();
            List<DDDAdapter.SeamateObject> allExistingMerchants = revealedSeaVessels.FindAll(IsMerchant);
            if (shouldAddNewVessel(revealedSeaVessels))
                reuseableVessels = allExistingMerchants.FindAll(MatchesGroupingConstraints);

            for (int i = 0; i < numMerchants; i++)  //Do once for each merchant we need to create.
            {
                //Try and recycle objects to create stimulus.
                if (reuseableVessels.Count > 0)
                {
                    DDDAdapter.SeamateObject objectForReuse = null;
                    //Make sure we reuse any stopped objects first
                    List<DDDAdapter.SeamateObject> stoppedObjects = reuseableVessels.FindAll(IsStopped);
                    if (stoppedObjects.Count > 0) objectForReuse = stoppedObjects[random.Next(stoppedObjects.Count)];
                    else objectForReuse = reuseableVessels[random.Next(reuseableVessels.Count)];

                    CreateEmptyMove(objectForReuse);
                    reuseableVessels.Remove(objectForReuse);

                }
                else //Reveal and move new merchant starting at an appropriate point for grouping constraints.
                {
                    Vec2D location = null;
                    if (currentItem.Parameters.Groupings == T_Groupings.One) //Get point in closest entry region
                    {
                        location = GetPointInClosestEntryRegion(dict, entryRegions);
                    }
                    else if (currentItem.Parameters.Groupings == T_Groupings.Two) //Get point in any entry region
                    {
                        location = new Polygon2D(entryRegions[random.Next(entryRegions.Count)]).PointInside();
                    }

                    string id = unrevealedMerchantIDs[random.Next(unrevealedMerchantIDs.Count)];
                    CreateRevealAndEmptyMove(id, "Merchant DM", location);
                    unrevealedMerchantIDs.Remove(id); 
                }
         
            }               
            currentItem.Action = actions.ToArray();
        }
Exemplo n.º 40
0
        //Pirate generator -- generates or chooses several pirates or friendly vessels in DM domain
        //So either creates a RevealEvent or chooses existing vessel for MoveEvent

        public override void Generate(T_Item currentItem, String dmID)
        {
            if (currentItem.Parameters.Threat == T_Threat.None)
            {
                return;
            }


            actions = currentItem.Action.ToList();

            // Do some setup
            bool isPirate = !(currentItem.Parameters.Threat == T_Threat.None);

            if (isPirate)
            {
                owner = "Pirate DM";
            }
            else
            {
                owner = "Merchant DM";
            }

            PolygonValue domainPV = this.ddd.GetDecisionMakersAreaOfResponsibility(dmID);

            domain = new Polygon2D(domainPV);
            List <string> unrevealedObjectIDs = ddd.GetAllUnrevealedObjectIds(isPirate, true, null);


            //How many pirates should we generate?  These numbers may need tweaking
            int minPirates = Properties.Settings.Default.minPirates;
            int maxPirates = Properties.Settings.Default.maxPirates;
            int numPirates = random.Next(minPirates, maxPirates);


            //Are there any pirates we can reuse, already in play?
            List <DDDAdapter.SeamateObject> reusableVessels = revealedSeaVessels.FindAll(IsReusable);

            if (reusableVessels.Count > 0 && Properties.Settings.Default.reusePirates)
            {
                for (int i = 0; i < numPirates; i++)
                {
                    if (reusableVessels.Count > 0)
                    {
                        DDDAdapter.SeamateObject vessel = reusableVessels[0];
                        reusableVessels.Remove(vessel);
                        CreateEmptyMove(vessel);
                    }
                    else
                    {
                        Vec2D  location = MakeLocationInEntryRegions(entryRegions);
                        string id       = unrevealedObjectIDs[random.Next(unrevealedObjectIDs.Count())];
                        unrevealedObjectIDs.Remove(id);
                        CreateRevealAndEmptyMove(id, owner, location);
                    }
                }


                ////See if any existing pirates can be paired under "grouping" distance constraints
                //List<List<DDDAdapter.SeamateObject>> groupedPirates = GroupVessels(currentItem.Parameters.Groupings, numPirates, reusableVessels);
                //List<List<DDDAdapter.SeamateObject>> groupsOfNumPirateSize = groupedPirates.FindAll(delegate(List<DDDAdapter.SeamateObject> g) { return g.Count >= numPirates; });

                ////Any groups of numPirates?
                //if (groupsOfNumPirateSize.Count > 0)
                //{
                //    //if yes, make dummy move events for them and add to actions list.  done.
                //    foreach (DDDAdapter.SeamateObject pirate in groupsOfNumPirateSize.ElementAt(0))
                //        CreateEmptyMove(pirate);
                //}
                //else
                //{
                //    //Can any of these smaller groupings include an entry region too, so we can add new pirates?
                //    groupedPirates.Sort(delegate(List<DDDAdapter.SeamateObject> g1, List<DDDAdapter.SeamateObject> g2) { return g1.Count.CompareTo(g2.Count); }); //sort by size, largest first
                //    foreach (List<DDDAdapter.SeamateObject> group in groupedPirates)
                //    {
                //        List<PolygonValue> matchingEntryRegions = GetMatchingEntryRegions(currentItem.Parameters.Groupings, group, entryRegions);
                //        if (matchingEntryRegions.Count > 0)
                //        {
                //            //if yes, then make dummy move events for the pirates in grouping, then
                //            foreach (DDDAdapter.SeamateObject pirate in groupsOfNumPirateSize.ElementAt(0))
                //                CreateEmptyMove(pirate);
                //            //Create as many remaining pirates as we need distributed randomly among suitable entry regions.
                //            List<Vec2D> locations = MakeLocationsInEntryRegions(numPirates - group.Count, matchingEntryRegions);
                //            foreach (Vec2D location in locations)
                //            {
                //                string id = unrevealedObjectIDs[random.Next(unrevealedObjectIDs.Count())];
                //                unrevealedObjectIDs.Remove(id);
                //                CreateRevealAndEmptyMove(id, owner, location);
                //            }
                //            break;
                //        }
                //    }

                //    //if no, we couldn't include an entry region (where new pirates would be created) with any existing pirates
                //    if (actions.Count == 0)
                //        //TODO: maybe should make smaller num of pirates if above min rather than making all new?
                //        MakeAllNewPirates(currentItem.Parameters.Groupings,numPirates,entryRegions,unrevealedObjectIDs);
                //}
            }
            //no reusable vessels, we have to create all new pirates
            else
            {
                MakeAllNewPirates(currentItem.Parameters.Groupings, numPirates, entryRegions, unrevealedObjectIDs);
            }

            currentItem.Action = actions.ToArray();
        }
Exemplo n.º 41
0
        public void Generate(String outputFilename) {

            //minute, DM, vesselID,"stimuli,stimuli"

            //Example Data for 20 min seaside scenario 2
            //Right now I create this with "replace" in notepad.
            object[][] spreadsheet = 

new object[][] {
new object [] {1,"BAMS",2469,"Move, Reveal"}, new object [] {
1,"BAMS",7738,"Move, Reveal"}, new object [] {
1,"BAMS",2779,"Move, Reveal"}, new object [] {
1,"BAMS",1604,"Move, Reveal"}, new object [] {
1,"BAMS",2228,"Move, Reveal"}, new object [] {
1,"BAMS",6348,"Move, Reveal"}, new object [] {
1,"BAMS",2994,"Move, Reveal"}, new object [] {
1,"FireScout",7648,"Move, Reveal"}, new object [] {
1,"FireScout",1818,"Move, Reveal"}, new object [] {
1,"FireScout",4633,"Move, Reveal"}, new object [] {
1,"FireScout",5069,"Move, Reveal"}, new object [] {
1,"FireScout",3734,"Move, Reveal"}, new object [] {
1,"FireScout",2213,"Move, Reveal"}, new object [] {
1,"FireScout",4475,"Move, Reveal"}, new object [] {
1,"FireScout",4633,"Move, Reveal"}, new object [] {
2,"BAMS",8736,"Move, Reveal"}, new object [] {
2,"BAMS",1961,"Move, Reveal"}, new object [] {
2,"BAMS",5553,"Move, Reveal"}, new object [] {
2,"BAMS",5958,"Move, Reveal"}, new object [] {
2,"FireScout",8893,"Move, Reveal"}, new object [] {
3,"BAMS",2228,"Move"}, new object [] {
3,"FireScout",1848,"Move, Reveal"}, new object [] {
4,"BAMS",1135,"Reveal"}, new object [] {
4,"FireScout",3502,"Move, Reveal"}, new object [] {
5,"FireScout",7648,"Move"}, new object [] {
5,"FireScout",1818,"Move, Reveal"}, new object [] {
6,"BAMS",2377,"Move, Reveal"}, new object [] {
6,"FireScout",3593,"Move, Reveal"}, new object [] {
7,"BAMS",8948,"Move, Reveal"}, new object [] {
7,"BAMS",3106,"Move, Reveal"}, new object [] {
7,"FireScout",3593,"Move"}, new object [] {
7,"FireScout",6074,"Move, Reveal"}, new object [] {
7,"FireScout",6077,"Move, Reveal"}, new object [] {
7,"FireScout",9167,"Move, Reveal"}, new object [] {
7,"FireScout",4318,"Move, Reveal"}, new object [] {
7,"FireScout",7679,"Move, Reveal"}, new object [] {
8,"FireScout",7232,"Move, Reveal"}, new object [] {
9,"BAMS",7112,"Move, Reveal"}, new object [] {
10,"FireScout",3170,"Move, Reveal"}, new object [] {
11,"BAMS",4940,"Move, Reveal"}, new object [] {
11,"BAMS",5304,"Move, Reveal"}, new object [] {
11,"BAMS",5965,"Move, Reveal"}, new object [] {
11,"BAMS",8560,"Move, Reveal"}, new object [] {
11,"FireScout",1606,"Move, Reveal"}, new object [] {
11,"FireScout",7151,"Move, Reveal"}, new object [] {
13,"BAMS",1212,"Move, Reveal"}, new object [] {
13,"BAMS",9809,"Move, Reveal"}, new object [] {
13,"BAMS",4685,"Move, Reveal"}, new object [] {
13,"BAMS",1608,"Move, Reveal"}, new object [] {
13,"BAMS",3537,"Move, Reveal"}, new object [] {
13,"FireScout",4322,"Move, Reveal"}, new object [] {
13,"FireScout",4257,"Move, Reveal"}, new object [] {
13,"FireScout",3170,"Move, Reveal"}, new object [] {
14,"BAMS",1621,"Move, Reveal"}, new object [] {
14,"FireScout",7626,"Move, Reveal"}, new object [] {
15,"FireScout",6081,"Move, Reveal"}, new object [] {
15,"BAMS",3957,"Move, Reveal"}, new object [] {
15,"BAMS",9081,"Move, Reveal"}, new object [] {
15,"BAMS",1966,"Move, Reveal"}, new object [] {
15,"FireScout",8940,"Move, Reveal"}, new object [] {
15,"FireScout",6015,"Move, Reveal"}, new object [] {
18,"BAMS",9081,"Move"}, new object [] {
18,"BAMS",1604,"Move, Reveal"}, new object [] {
18,"BAMS",4306,"Move, Reveal"}, new object [] {
18,"FireScout",2471,"Move, Reveal"}, new object [] {
18,"FireScout",4758,"Move, Reveal"}, new object [] {
18,"FireScout",4257,"Move"}, new object [] {
19,"BAMS",2285,"Move, Reveal"}, new object [] {
19,"BAMS",9228,"Move, Reveal"}, new object [] {
19,"BAMS",6290,"Move, Reveal"}};


            List<ScheduledItem> allScheduledItems = new List<ScheduledItem>();
            List<T_Item>allItems = new List<T_Item>();
            foreach (object[] line in spreadsheet)
            {
                if (line.Length < 4)
                    continue;   //allows you to paste in and ignore empty lines (with no stimuli)
                int minute = (int)line[0];
                int time = minute *60;
                String dm_id = MakeDMID((String)line[1]);
                int obj_id = (int)line[2];
                String actions = (String)line[3];
                if (actions == null)
                    continue;
                ScheduledItem scheduledItem = null;
                T_Item item = null;
                //see if we've already made an "ScheduledItem" that this action belongs to
                foreach (ScheduledItem maybeScheduledItem in allScheduledItems)
                {
                    if (maybeScheduledItem.DM_ID == dm_id && maybeScheduledItem.Time == time)
                    {
                        scheduledItem = maybeScheduledItem;
                        //find corresponding abstract "Item"
                        foreach (T_Item maybeItem in allItems) {
                            if (maybeItem.ID == scheduledItem.ID) {
                                item = maybeItem;
                            }
                        }
                        break;
                    }
                }
                if (scheduledItem == null)
                    //make new "scheduledItem" and "item" (uid)
                {
                    //Dummy item that contains a UID and empty actions list
                    item = new T_Item();
                    uid = uid+1;
                    item.ID = uid.ToString();
                    item.Action = new object[0];
                    item.Parameters = new Parameters();
                    item.Parameters.ThreatType = T_ThreatType.Nonimminent;
                    item.Parameters.Threat = T_Threat.Unambiguous;
                    item.Parameters.Crossing = false;
                    item.Parameters.Groupings = T_Groupings.One;
                    item.Parameters.PlayerResources = T_ResourceAvailability.Available;
                    item.Parameters.TeammateResources = T_ResourceAvailability.Available;
                    item.Parameters.FF_Difficulty =1.0;
                    item.Parameters.TT_Difficulty = 1.0;
                    allItems.Add(item);

                    scheduledItem = new ScheduledItem();
                    scheduledItem.Time = time;
                    scheduledItem.DM_ID = dm_id;
                    scheduledItem.ID = uid.ToString();
                    allScheduledItems.Add(scheduledItem);
                }

                //OK.  We've verified that the scheduled item exists and we have the pointer to the item.
                //Add actions to item.Action:
                List<T_ScriptedItem> listToAddToAction = new List<T_ScriptedItem>();
                if (actions.Contains("Reveal"))
                {
                    T_ScriptedItem reveal = new T_ScriptedItem();
                    reveal.ID = obj_id.ToString();
                    reveal.ActionType = "Reveal";
                    listToAddToAction.Add(reveal);
                }
                if (actions.Contains("Move"))
                {
                    T_ScriptedItem move = new T_ScriptedItem();
                    move.ID = obj_id.ToString();
                    move.ActionType = "Move";
                    listToAddToAction.Add(move);
                }
                List<object> copyOfActions = item.Action.ToList();
                copyOfActions.AddRange(listToAddToAction);
                item.Action = copyOfActions.ToArray();
            }
            T_SeamateItems seamateItems = new T_SeamateItems();
            seamateItems.Timeline = allScheduledItems.ToArray();
            seamateItems.Items = allItems.ToArray();
            System.IO.File.WriteAllText(@"C:\Work\SEAMATE\"+outputFilename+".xml", seamateItems.Serialize()); 
        }
Exemplo n.º 42
0
 public override void Generate(T_Item currentItem, String dmID)
 {
     //currentItem.Parameters.Crossing //True, False
 }